Ejemplo n.º 1
0
 def get_result(self, default_unit='KB'):
     net_usage = {}
     pre_net_stat = self.get_info()
     time.sleep(Statics.frequency)
     cur_net_stat = self.get_info()
     for i in pre_net_stat.keys():
         net_dev_name, delta_received_bytes, delta_transmit_bytes = cur_net_stat[i] - pre_net_stat[i]
         if delta_received_bytes != 0 and delta_transmit_bytes !=0:
             received_bytes_per = '%s%s%s' % (Statics.calc_diff(delta_received_bytes, default_unit=default_unit), default_unit, '/s')
             transmit_bytes_per = '%s%s%s' % (Statics.calc_diff(delta_transmit_bytes, default_unit=default_unit), default_unit, '/s')
             result_str = '%s| Received:%s| Transmit:%s' % (net_dev_name, received_bytes_per, transmit_bytes_per)
             net_usage[net_dev_name] = result_str
     return net_usage
Ejemplo n.º 2
0
 def disk_io_counter(self, defaultUnit='KB'):
     parti_size = Partitions.get_partition_size('GB')
     io_result_dict = OrderedDict()
     prev_disk_list = self.disk_stats()
     time.sleep(Statics.frequency)
     curr_disk_list = self.disk_stats()
     for key in prev_disk_list.keys():
         diff_r_completed, diff_r_merged, diff_r_sections, diff_time_spent_reading, diff_w_count, diff_w_merged, diff_w_sections, diff_time_spent_write, diff_cur_io_requests, diff_time_spent_doing_io, diff_weighted_time_spent_doing_io = curr_disk_list[key] - prev_disk_list[key]
         read_rate = "%s%s%s" % (Statics.calc_diff(diff_r_sections * Statics.io_sector_size, default_unit=defaultUnit), defaultUnit, '/s')
         write_rate = "%s%s%s" % (Statics.calc_diff(diff_w_sections * Statics.io_sector_size, default_unit=defaultUnit), defaultUnit, '/s')
         r_w_rate = '%s\t|total_size: %s\t|read_rate:%s\t|write_rate:%s' % (key, parti_size[key], read_rate, write_rate)
         io_result_dict[key] = r_w_rate
     return io_result_dict