def _netstat(self, interface): """ Calculate the latest network status information. """ irx, itx = net_stat.rx_tx_bytes(interface) gevent.sleep(1) frx, ftx = net_stat.rx_tx_bytes(interface) return dict(transmitted=(ftx - itx), received=(frx - irx))
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 read_network_bytes_received(): return round(net_stat.rx_tx_bytes(network_interface)[0], 2)
def read_network_bytes_received(): return round(net_stat.rx_tx_bytes('ens33')[0], 2)
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_network_bytes_received(): return net_usage_filter.filter( round(net_stat.rx_tx_bytes(network_interface)[0], 2))
def read_network_bytes_received(): return net_usage_filter.filter(round(net_stat.rx_tx_bytes(network_interface)[0], 2))
def read_network_bytes_received(): """ User defined method. :return: network bytes received """ return round(net_stat.rx_tx_bytes(network_interface)[0], 2)
def test_tx_bytes(self): _, value = net_stat.rx_tx_bytes(self.interface) self.assertTrue(value >= 0, value)
def read_network_bytes_received(): return net_usage_filter_with_window.filter( round(net_stat.rx_tx_bytes('eth0')[0], 2))
import sys from linux_metrics import net_stat warning = (float(sys.argv[1]) * 1.0) critical = (float(sys.argv[2]) * 1.0) if warning > critical: print "-w cannot be larger than -c" sys.exit(3) if warning == critical: print "-w cannot be larger than -c" sys.exit(3) stats = (net_stat.rx_tx_bytes("eth0")) inOcts = stats[0] outOcts = stats[1] inOctsGB = float("{0:.3f}".format(inOcts / (1073741824 * 1.0))) outOctsGB = float("{0:.3f}".format(outOcts / (1073741824 * 1.0))) if inOctsGB < warning: print "OK - inOcts " + str(inOctsGB) + "GB; outOcts " + str( outOctsGB) + "GB" sys.exit(0) elif inOctsGB > warning and inOctsGB < critical: print "WARNING - inOcts " + str(inOctsGB) + "GB; outOcts " + str( outOctsGB) + "GB" sys.exit(1)