def _sendLinuxMetrics(self): cpu_percents = {} for k, v in cpu_stat.cpu_percents().items(): cpu_percents['cpu_' + k] = v load_avg = cpu_stat.load_avg() assert(len(load_avg) == 3) file_desc = cpu_stat.file_desc() assert(len(file_desc) == 3) stats = cpu_percents.items() stats += zip(['load_1min', 'load_5min', 'load_15min'], load_avg) stats += {'procs_running': cpu_stat.procs_running(), 'procs_blocked': cpu_stat.procs_blocked()}.items() stats += zip(['filedesc_allocated', 'filedesc_allocated_free', 'filedesc_max'], file_desc) self.sendEvent('cpu', dict(stats)) for nic in ['wlan0', 'eth0', 'usb0']: rx, tx = net_stat.rx_tx_bytes(nic) self.sendEvent('net', {'nic': nic, 'rx_bytes': rx, 'tx_bytes': tx})
def main(): # cpu print 'procs running: %d' % cpu_stat.procs_running() cpu_pcts = cpu_stat.cpu_percents(sample_duration=1) print 'cpu utilization: %.2f%%' % (100 - cpu_pcts['idle']) # disk print 'disk busy: %s%%' % disk_stat.disk_busy('sda', sample_duration=1) r, w = disk_stat.disk_reads_writes('sda') print 'disk reads: %s' % r print 'disk writes: %s' % w # memory used, total = mem_stat.mem_stats() print 'mem used: %s' % used print 'mem total: %s' % total # network rx_bits, tx_bits = net_stat.rx_tx_bits('eth0') print 'net bits received: %s' % rx_bits print 'net bits sent: %s' % tx_bits
def read_cpu_procs(): return cpu_stat.procs_running()
def getMetrics(self): now = int(time.time()) * 1000 #JSON for GS Advanced Feed PUT API comp = {} comp['stream'] = [] comp['componentId'] = self._compId comp['time'] = [now] comp['defaults'] = {} comp['defaults']['name'] = self._compName #Assign a component template for auto registration comp['compTmplId'] = 'rPi' #cpu streams cpu_pcts = cpu_stat.cpu_percents(1) stream = {} stream['streamId'] = 'cpu_user' stream['data'] = [cpu_pcts['user']] comp['stream'].append(stream) stream = {} stream['streamId'] = 'cpu_nice' stream['data'] = [cpu_pcts['nice']] comp['stream'].append(stream) stream = {} stream['streamId'] = 'cpu_system' stream['data'] = [cpu_pcts['system']] comp['stream'].append(stream) stream = {} stream['streamId'] = 'cpu_idle' stream['data'] = [cpu_pcts['idle']] comp['stream'].append(stream) stream = {} stream['streamId'] = 'cpu_iowait' stream['data'] = [cpu_pcts['iowait']] comp['stream'].append(stream) load = cpu_stat.load_avg() stream = {} stream['streamId'] = 'cpu_avg1min' stream['data'] = [load[0]] comp['stream'].append(stream) stream = {} stream['streamId'] = 'cpu_avg5min' stream['data'] = [load[1]] comp['stream'].append(stream) stream = {} stream['streamId'] = 'cpu_avg15min' stream['data'] = [load[2]] comp['stream'].append(stream) #processes stream = {} stream['streamId'] = 'procs_running' stream['data'] = [cpu_stat.procs_running()] comp['stream'].append(stream) #memory mem = mem_stat.mem_stats() stream = {} stream['streamId'] = 'mem_active' stream['data'] = [mem[0]] comp['stream'].append(stream) stream = {} stream['streamId'] = 'mem_total' stream['data'] = [mem[1]] comp['stream'].append(stream) stream = {} stream['streamId'] = 'mem_cached' stream['data'] = [mem[2]] comp['stream'].append(stream) stream = {} stream['streamId'] = 'mem_free' stream['data'] = [mem[3]] comp['stream'].append(stream) stream = {} stream['streamId'] = 'swap_total' stream['data'] = [mem[4]] comp['stream'].append(stream) stream = {} stream['streamId'] = 'swap_free' stream['data'] = [mem[5]] comp['stream'].append(stream) #disk disk = disk_stat.disk_usage('/') stream = {} stream['streamId'] = 'disk_size' stream['data'] = [disk[1]] comp['stream'].append(stream) stream = {} stream['streamId'] = 'disk_used' stream['data'] = [disk[2]] comp['stream'].append(stream) #network net = net_stat.rx_tx_bytes('eth0') stream = {} stream['streamId'] = 'net_download' stream['data'] = [net[0]] comp['stream'].append(stream) net = net_stat.rx_tx_bytes('eth0') stream = {} stream['streamId'] = 'net_upload' stream['data'] = [net[1]] comp['stream'].append(stream) jobj = {} jobj['feed'] = {} jobj['feed']['component'] = [] jobj['feed']['component'].append(comp) return jobj
def read_cpu_procs(): cnt = cpu_stat.procs_running() return cpu_pro_filter.filter(cnt)
def read_cpu_procs(): """ User defined method :return: number of running cpu processes. """ return cpu_stat.procs_running()
def test_procs_running(self): value = cpu_stat.procs_running() self.assertTrue(value >= 0, value)