def read_mem_free():
    """
    User defined method.
    :return: percentage of memory free.
    """
    total_mem = round(mem_stat.mem_stats()[1], 4)
    free_mem = round(mem_stat.mem_stats()[3], 4)
    mem_free_percent = ((total_mem - free_mem) / total_mem) * 100
    return round(mem_free_percent, 2)
def read_mem_free():
    """
    User defined method.
    :return: percentage of memory free.
    """
    total_mem = round(mem_stat.mem_stats()[1], 4)
    free_mem = round(mem_stat.mem_stats()[3], 4)
    mem_free_percent = ((total_mem - free_mem) / total_mem) * 100
    return round(mem_free_percent, 2)
Example #3
0
    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'
 
        #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)   

	
        stream = {}
        stream['streamID'] = 'temp'
        stream['data'] = [float(subprocess.check_output('./LM75.sh', shell=True))]
        comp['stream'].append(stream)	
        
        jobj = {}
        jobj['feed'] = {}
        jobj['feed']['component'] = []
        jobj['feed']['component'].append(comp)
        
        return jobj
Example #4
0
def serverStats():
    cpuPercents = cpu_stat.cpu_percents(1)
    statDict = {}
    statDict["ioWait"] = cpuPercents['iowait']
    statDict["system"] = cpuPercents['system']
    statDict["idle"] = cpuPercents['idle']
    statDict["user"] = cpuPercents['user']
    statDict["cpuUsed"] = round(100 - cpuPercents['idle'])
    statDict["loadAvg"] = cpu_stat.load_avg()
    statDict["memUsed"], statDict["memTot"], _, _, _, _ = mem_stat.mem_stats()
    statDict["memFree"] = memTot-memUsed
    return statDict
def dump_stats(handler):
	while True:
		cpu_pcts = cpu_stat.cpu_percents(1) #instantaneous cpu usage
		utilization = 100 - cpu_pcts['idle']

		#cores = all_cpu_usage()
		load_ = cpu_stat.load_avg()
		load_5,load_15 = load_[1],load_[2]
		
		mem_tuple = mem_stat.mem_stats() #instantaneous memory usage
		used,total = mem_tuple[0],mem_tuple[1]

		free = total - used
		
			
		
		
		handler.update({"vm_name":DOMAIN},{"$set":{"vm_name":DOMAIN,"vm_ip":VM_IP,"cpu":utilization,"5_min":load_5,"15_min":load_15,"mem_free":free,"mem_used":used,"mem_total":total,"mouse":"no"}},True)	 # update if document present else insert the document. update the cpu,mem of the virtual every 5 seconds
		print "upated the tuple"

		sleep(5)	
Example #6
0
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
Example #7
0
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 
Example #8
0
def read_mem_free():
    total_mem = round(mem_stat.mem_stats()[1], 4)
    free_mem = round(mem_stat.mem_stats()[3], 4)
    mem_free_percent = ((total_mem - free_mem) / total_mem) * 100
    return round(mem_free_percent, 2)
def read_mem_free():
    total_mem = round(mem_stat.mem_stats()[1], 4)
    free_mem = round(mem_stat.mem_stats()[3], 4)
    mem_free_percent = ((total_mem - free_mem) / total_mem) * 100
    return round(mem_free_percent, 2)
Example #10
0
    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_swap_mem_free():
    total_swap = round(mem_stat.mem_stats()[4], 4)
    swap_mem_free = round(mem_stat.mem_stats()[5], 4)
    swap_free_percent = (swap_mem_free / total_swap) * 100
    return round(swap_free_percent, 2)
def read_swap_mem_free():
    total_swap = round(mem_stat.mem_stats()[4], 4)
    swap_mem_free = round(mem_stat.mem_stats()[5], 4)
    swap_free_percent = (swap_mem_free/total_swap)*100
    return round(swap_free_percent, 2)
def read_mem_free():
    return round((mem_stat.mem_stats()[3]) / (1048576), 3)
def read_mem_free():
    return round((mem_stat.mem_stats()[3]) / (1048576), 3)
Example #15
0
    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
Example #16
0
def read_mem_free():
    total_mem = round(mem_stat.mem_stats()[1], 4)
    free_mem = round(mem_stat.mem_stats()[3], 4)
    mem_free_percent = ((total_mem-free_mem)/total_mem)*100
    return mem_free_filter_with_window.filter(round(mem_free_percent, 2))
Example #17
0
 def test_mem_used(self):
     value, _ = mem_stat.mem_stats()
     self.assertTrue(value > 0, value)
Example #18
0
 def test_mem_total(self):
     _, value = mem_stat.mem_stats()
     self.assertTrue(value > 0, value)