def get_time_percent(self): data = [] cpu_time_percent = cpu_ps.cpu_times_percent() data.append(namedtuple_to_dict(cpu_time_percent, self.prefix, dict({'index': 'cpu-total'}))) cpu_time_percent = cpu_ps.cpu_times(percpu=True) for (i, c) in enumerate(cpu_time_percent): data.append(namedtuple_to_dict(c, self.prefix, dict({'index': 'cpu-'+str(i)}))) return data
def get_frequency(self): data = [] cpu_freq = cpu_ps.cpu_freq() data.append(namedtuple_to_dict(cpu_freq, self.prefix, dict({'index': 'cpu-total'}))) cpu_freq = cpu_ps.cpu_freq(percpu=True) for (i, c) in enumerate(cpu_freq): data.append(namedtuple_to_dict(c, self.prefix, dict({'index': 'cpu-'+str(i)}))) return data
def get_io_counters(self): data = [] diskio_counters = disk_ps.disk_io_counters(perdisk=False) data.append( namedtuple_to_dict(diskio_counters, self.diskio_prefix, dict({'device': 'disk-total'}))) diskio_counters = disk_ps.disk_io_counters(perdisk=True) for (k, v) in diskio_counters.items(): data.append( namedtuple_to_dict(v, self.diskio_prefix, dict({'device': k}))) return data
def get_io_counters(self): data = [] io_counters = net_ps.net_io_counters() data.append( namedtuple_to_dict(io_counters, self.prefix, dict({'interface': 'total'}))) io_counters = net_ps.net_io_counters(pernic=True) for (k, i) in io_counters.items(): data.append( namedtuple_to_dict(i, self.prefix, dict({'interface': k}))) return data
def get_battery(self): data = [] battery = sensor_ps.sensors_battery() data.append( namedtuple_to_dict(battery, self.prefix, dict({'type': 'battery'}))) return data
def get_if_stats(self): data = [] if_stats = net_ps.net_if_stats() for (k, iss) in if_stats.items(): data.append( namedtuple_to_dict(iss, self.prefix, dict({'interface': k}))) return data
def get_usage(self, path_list): data = [] for p in path_list: disk_usage = disk_ps.disk_usage(p) data.append( namedtuple_to_dict(disk_usage, self.disk_prefix, dict({'mountpoint': p}))) return data
def get_if_addrs(self): data = [] if_addrs = net_ps.net_if_addrs() for (k, ia) in if_addrs.items(): for i in ia: data.append( namedtuple_to_dict(i, self.prefix, dict({'interface': k}))) return data
def get_fans(self): data = [] fans = sensor_ps.sensors_fans() for (k, fan) in fans.items(): for f in fan: data.append( namedtuple_to_dict(f, self.prefix, dict({ 'type': 'fan', 'item': k }))) return data
def get_temperatures(self): data = [] temperatures = sensor_ps.sensors_temperatures() for (k, temp) in temperatures.items(): for t in temp: data.append( namedtuple_to_dict( t, self.prefix, dict({ 'type': 'temperature', 'item': k }))) return data
def get_virtual_memory(self): vir_mem = mem_ps.virtual_memory() return namedtuple_to_dict(vir_mem, self.memPrefix)
def get_users(self): data = [] users = sys_ps.users() for u in users: data.append(namedtuple_to_dict(u, self.prefix, dict({'type': 'user'}))) return data
def get_state(self): cpu_stats = cpu_ps.cpu_stats() return namedtuple_to_dict(cpu_stats, self.prefix, dict({'index': 'cpu-total'}))
def get_connections(self): data = [] inter_conn = net_ps.net_connections() for ic in inter_conn: data.append(namedtuple_to_dict(ic, self.prefix)) return data
def get_swap_memory(self): swap_mem = mem_ps.swap_memory() return namedtuple_to_dict(swap_mem, self.swapPrefix)
def get_proc_info(self, proc): d = dict() try: d[self.prefix + 'pid'] = proc.pid except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'status'] = proc.status() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'name'] = proc.name() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'exe'] = proc.exe() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'cmdline'] = ' '.join(proc.cmdline()) except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'create_time'] = rfc3339.rfc3339( datetime.datetime.fromtimestamp(proc.create_time())) except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'ppid'] = namedtuple_to_dict(proc.parent()) except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'cmd'] = proc.cmd() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'nice'] = proc.nice() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'ionice'] = namedtuple_to_dict(proc.ionice()) except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'io_counter'] = namedtuple_to_dict( proc.io_counters()) except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'num_ctx_switches'] = namedtuple_to_dict( proc.num_ctx_switches()) except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'num_fds'] = proc.num_fds() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'num_handles'] = proc.num_handles() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'num_threads'] = proc.num_threads() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'threads'] = proc.threads() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'cpu_times'] = namedtuple_to_dict(proc.cpu_times()) except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'cpu_percent'] = proc.cpu_percent() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'cpu_num'] = proc.cpu_num() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'memory_info'] = namedtuple_to_dict( proc.memory_full_info()) except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'memory_percent'] = proc.memory_percent() except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'open_files'] = [ namedtuple_to_dict(tup) for tup in proc.open_files() ] except AttributeError: pass except proc_ps.AccessDenied: pass try: d[self.prefix + 'connections'] = [ namedtuple_to_dict(tup) for tup in proc.connections() ] except AttributeError: pass except proc_ps.AccessDenied: pass return d
def get_partitions(self): data = [] disk_part = disk_ps.disk_partitions() for d in disk_part: data.append(namedtuple_to_dict(d, self.disk_prefix)) return data