Ejemplo n.º 1
0
        with open(PF.proc_net_dev) as net_dev_file:
            for each_line in net_dev_file:
                each_line_strip = each_line.strip()
                if len(each_line_strip) > 0:
                    each_line_list = each_line_strip.split()
                    dev_name = each_line_list[0]
                    if re.match('.*:$', dev_name):
                        net_dev_name = dev_name[:-1]
                        received_bytes = each_line_list[1]
                        transmit_bytes = each_line_list[8]
                        net_dev_result[dev_name] = NetDevInfo(net_dev_name, received_bytes, transmit_bytes)
        return net_dev_result

    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

if __name__ == '__main__':
    nsi = NetStatInfo()
    MyCurses.display_base_info(nsi)
Ejemplo n.º 2
0
            except:
                failedReadCount += 1
        return currentProcList

    def get_result(self):
        current_proc_list = self.read_process_status()
        total_proc_num = len(current_proc_list)
        #result 保存了当前所有各个用户所有进程数总和
        #runningResult 保存了当前所有各个用户running的进程数总和
        result, running_result, allOwnerNum, runningOwnerNum, total_running_num = {}, {}, 0, 0, 0
        for eachProc in current_proc_list:
            procOwner, procId, procCmd, procStatus = eachProc.processOwner, eachProc.processId, \
                                                     eachProc.processCmdline, eachProc.processStatus
            if procOwner not in result.keys(): result[procOwner] = 0
            if procOwner not in running_result.keys(): running_result[procOwner] = 0
            if procOwner in result.keys(): result[procOwner] +=1 
            if procOwner in result.keys() and eachProc.processStatus == 'R': running_result[procOwner] +=1
            if eachProc.processStatus == 'R': total_running_num += 1
        present_str, keys_count = '', 0
        for i in result.keys():
            i_all_proc, i_running_proc = result[i], running_result[i]
            allOwnerPercent = '%s%s' % (round((float(i_all_proc))/total_proc_num, 4)*100, '%')
            runningOwnerPercent = '%s%s' % (round((float(i_running_proc))/total_running_num, 4)*100, '%')
            present_str = '|%s\t|Running:%s\t|Total:%s\t|Running percent:%s|Total percent:%s' % (i,i_running_proc, i_all_proc, runningOwnerPercent, allOwnerPercent)
            result[i] = present_str
        return result

if __name__ == '__main__':
    pi = ProcessInfo()
    MyCurses.display_base_info(pi)
Ejemplo n.º 3
0
from statics import MyCurses
from parent import Base


class Main(Base):
    def __init__(self):
        super(Main, self).__init__()

    def get_result(self):
        ci = CpuInfo().get_result()
        di = DiskInfo().get_result()
        pi = ProcessInfo().get_result()
        msi = MemStatInfo().get_result()
        nsi = NetStatInfo().get_result()
        total_result = OrderedDict(dict({"my_local_cpu_info": "================Local Cpu Info=============="}))
        total_result.update(ci)
        total_result.update(dict({"my_local_disk_info": "================Local Disk Info=============="}))
        total_result.update(di)
        total_result.update(dict({"my_memory_info": "================Local Memory Info=============="}))
        total_result.update(msi)
        total_result.update(dict({"my_network_info": "================Local Network Info=============="}))
        total_result.update(nsi)
        total_result.update(dict({"my_process_info": "================Local Process Info=============="}))
        total_result.update(pi)
        return total_result


if __name__ == "__main__":
    m = Main()
    MyCurses.display_base_info(m)