def mem(self, widget, data=None) :
	print ' \n DETAILS OF PHYSICAL AND VIRTUAL MEMORY\n '
	print 'Total physical memory (in bytes) - '
	print psutil.TOTAL_PHYMEM
	print 'Available physical memory (in bytes) - '
	print psutil.avail_phymem()
	print 'Used physical memory (in bytes) - '
	print psutil.used_phymem()
	print 'Total virtual memory (in bytes) - '
	print psutil.total_virtmem()
	print 'Available virtual memory (in bytes) - '
	print psutil.avail_virtmem()
	print 'Used virtual memory (in bytes) - '
	print psutil.used_virtmem()
	print 'Total cached memory (in bytes) - '
	print psutil.cached_phymem()
Exemple #2
0
    def generate(self, **kwargs):
        result = {'mem_phys_total': psutil.TOTAL_PHYMEM,
                  'mem_phys_avail': psutil.avail_phymem(),
                  'mem_phys_used': psutil.used_phymem(),
                  'mem_virt_total': psutil.total_virtmem(),
                  'mem_virt_avail': psutil.used_virtmem(),
                  'cpu_cores': self._get_total_core(),
                }

        return result
 def generate(self, **kwargs):
     result = {
         'mem_phys_total': psutil.TOTAL_PHYMEM,
         'mem_phys_avail': psutil.avail_phymem(),
         'mem_phys_used': psutil.used_phymem(),
         'mem_virt_total': psutil.total_virtmem(),
         'mem_virt_avail': psutil.avail_virtmem(),
         'mem_virt_used': psutil.used_virtmem(),
         'cpu_cores': self._get_total_cores(),
     }
     return result
Exemple #4
0
def get_host_info():
    """Return a ``dict`` with system's information

    `Example of its output <https://gist.github.com/gists/2891134>`_
    """
    memory_usage = psutil.phymem_usage()
    cached_memory = psutil.cached_phymem()
    buffered_memory = psutil.phymem_buffers()
    real_used = memory_usage.used - buffered_memory - cached_memory
    real_free = memory_usage.total - real_used
    percent = 100 * (float(memory_usage.used) / memory_usage.total)
    real_percent = 100 * (float(real_used) / memory_usage.total)
    virtual_used = psutil.used_virtmem()
    virtual_free = psutil.avail_virtmem()
    virtual_total = virtual_used + virtual_free
    info_per_nic = psutil.network_io_counters(pernic=True)
    network_info = {}
    for key, value in info_per_nic.iteritems():
        network_info[key] = {'bytes sent': value.bytes_sent,
                             'bytes received': value.bytes_recv,
                             'packets sent': value.packets_sent,
                             'packets received': value.packets_recv,}
    partitions = psutil.disk_partitions()
    storage_info = {}
    for partition in partitions:
        disk_usage = psutil.disk_usage(partition.mountpoint)
        storage_info[partition.device] = {'mount point': partition.mountpoint,
                                          'file system': partition.fstype,
                                          'total bytes': disk_usage.total,
                                          'total used bytes': disk_usage.used,
                                          'total free bytes': disk_usage.free,
                                          'percent used': disk_usage.percent,}
    return {'memory': {'free': memory_usage.free,
                       'total': memory_usage.total,
                       'used': memory_usage.used,
                       'cached': cached_memory,
                       'buffers': buffered_memory,
                       'real used': real_used,
                       'real free': real_free,
                       'percent': percent,
                       'real percent': real_percent,
                       'total virtual': virtual_total,
                       'used virtual': virtual_used,
                       'free virtual': virtual_free,},
            'cpu': {'number of cpus': psutil.NUM_CPUS,
                    'cpu percent': psutil.cpu_percent(),},
            'network': {'interfaces': network_info,},
            'storage': storage_info,
            'uptime': time() - psutil.BOOT_TIME,}
Exemple #5
0
 def on_global(self, msg=None):
     global_cpu = psutil.get_system_cpu_times()
     global_cpu['percent'] = psutil.cpu_percent()
     global_mem = {
         'used_physical': psutil.used_phymem(),
         'used_virtual': psutil.used_virtmem(),
         'available_physical': psutil.avail_phymem(),
         'available_virtual': psutil.avail_virtmem(),
     }
     result = {
         'hostnome': socket.gethostname(),
         'cpu': global_cpu,
         'mem': global_mem,
     }
     return {'global': result}
Exemple #6
0
 def collect(self):
     return dict(
         cpu_times=psutil.cpu_times()._asdict(),
         mem=dict(
             total_phymem=psutil.TOTAL_PHYMEM,
             avail_phymem=psutil.avail_phymem(),
             avail_virtmem=psutil.avail_virtmem(),
             cached_phymem=psutil.cached_phymem(),
             phymem_buffers=psutil.phymem_buffers(),
             total_virtmem=psutil.total_virtmem(),
             used_phymem=psutil.used_phymem(),
             used_virtmem=psutil.used_virtmem(),
         ),
         processes=list(self._processes()),
         net=dict(ifaces=self._net_dev(), proto=self._net_proto()),
         io=self._io_stats(),
         fs=dict(self._fs_usage()),
         fh=self._file_handles(),
     )
 def __call__(self):
     status = []
     status.append(('num cpus', psutil.NUM_CPUS))
     status.append(('cpu used', '%.2f%%' % psutil.cpu_percent()))
     total_phy = psutil.TOTAL_PHYMEM
     used_phy = psutil.used_phymem()
     status.append(('total phy mem', ConvertBytes(total_phy)))
     status.append(('used phy mem', ConvertBytes(used_phy)))
     status.append(('free phy mem', ConvertBytes(total_phy - used_phy)))
     try:
         status.append(('buffers', ConvertBytes(psutil.phymem_buffers())))
         status.append(('cached', ConvertBytes(psutil.cached_phymem())))
     except:
         pass
     total_virt = psutil.total_virtmem()
     used_virt = psutil.used_virtmem()
     status.append(('total virt mem', ConvertBytes(total_virt)))
     status.append(('used virt mem', ConvertBytes(used_virt)))
     status.append(('free virt mem', ConvertBytes(total_virt - used_virt)))
     return status
Exemple #8
0
 def collect(self):
     return dict(
         cpu_times=psutil.cpu_times()._asdict(),
         mem=dict(
             total_phymem=psutil.TOTAL_PHYMEM,
             avail_phymem=psutil.avail_phymem(),
             avail_virtmem=psutil.avail_virtmem(),
             cached_phymem=psutil.cached_phymem(),
             phymem_buffers=psutil.phymem_buffers(),
             total_virtmem=psutil.total_virtmem(),
             used_phymem=psutil.used_phymem(),
             used_virtmem=psutil.used_virtmem(),
         ),
         processes=list(self._processes()),
         net=dict(
             ifaces=self._net_dev(),
             proto=self._net_proto()
         ),
         io=self._io_stats(),
         fs=dict(self._fs_usage()),
         fh=self._file_handles(),
     )
 def done(self):
     server = {}
     server['load_average']  = os.getloadavg()
     server['total_phymem']  = psutil.TOTAL_PHYMEM
     server['total_virtmem'] = psutil.total_virtmem()
     server['used_phymem']   = psutil.used_phymem()
     server['used_virtmem']  = psutil.used_virtmem()
     server['cpu_percent']   = psutil.cpu_percent()
     server['cpu_count']     = psutil.NUM_CPUS
     
     f_processes = []
     processes = psutil.get_process_list()
     processes.sort(key=lambda x: x.get_cpu_times())
     processes.reverse()
     for p in processes[:10]:
         f_processes.append((p.name, p.get_cpu_times(), p.get_memory_percent(),time.ctime(p.create_time),))
     
     server['processes'] = f_processes
     return server
     
     
     
Exemple #10
0
					break
				except:
					sensorvals[sensor] = 0
		else:
			sensorvals[sensor] = 0
	sql("INSERT INTO temperature VALUES (%i, %f, %f, %f)" %
		(timestamp, sensorvals['cpu'], sensorvals['indoor'], sensorvals['outdoor'])
	)

	# Load
	cpu = psutil.cpu_percent()
	sql("INSERT INTO load VALUES (%i, %d)" % (timestamp, cpu))

	# Memory
	ram = int(psutil.used_phymem() / 1024 / 1024)
	swap = int(psutil.used_virtmem() / 1024 / 1024)
	sql("INSERT INTO memory VALUES (%i, %d, %d)" % (timestamp, ram, swap))

	# Power
	sensorvals = {}
	got_data = False
	ec3k_cache_dir = os.path.join(config['cache_dir'], 'ec3k')
	if not os.path.exists(ec3k_cache_dir):
		os.makedirs(ec3k_cache_dir)
	for sensor in ['powersupply_12v']:
		if config['ec3k']['sensors'].get(sensor, False):
			sensorid = config['ec3k']['sensors'][sensor].upper()
			filename = "%s.json" % sensorid
			sensor_file = os.path.join(config['ec3k']['fs_dir'], filename)
			sensor_cache = os.path.join(ec3k_cache_dir, filename)
			if not os.path.exists(sensor_file):
Exemple #11
0
def swapinfo():
	return (psutil.total_virtmem(),psutil.used_virtmem(),) # Return total and used swap
Exemple #12
0
Created on Tue Sep  3 09:21:57 2013

@author: ozdemircili
"""


import psutil
psutil.phymem_usage()
psutil.virtmem_usage()
psutil.cached_phymem()
psutil.phymem_buffers()
psutil.avail_phymem()
psutil.used_phymem()
psutil.total_virtmem()
psutil.avail_virtmem()
psutil.used_virtmem()

psutil.cpu_percent()

#CPU

from __future__ import print_function

with open('/proc/cpuinfo') as f:
    for line in f:
       
        #Formatting the output!!
        if line.strip():
            if line.rstrip('\n').startswith('model name'):
                model_name = line.rstrip('\n').split(':')[1]
                print(model_name)
Exemple #13
0
"""
Created on Tue Sep  3 09:21:57 2013

@author: ozdemircili
"""

import psutil
psutil.phymem_usage()
psutil.virtmem_usage()
psutil.cached_phymem()
psutil.phymem_buffers()
psutil.avail_phymem()
psutil.used_phymem()
psutil.total_virtmem()
psutil.avail_virtmem()
psutil.used_virtmem()

psutil.cpu_percent()

#CPU

from __future__ import print_function

with open('/proc/cpuinfo') as f:
    for line in f:

        #Formatting the output!!
        if line.strip():
            if line.rstrip('\n').startswith('model name'):
                model_name = line.rstrip('\n').split(':')[1]
                print(model_name)
 def test_used_virtmem(self):
     x = psutil.used_virtmem()
     self.assertTrue(isinstance(x, (int, long)))
     self.assertTrue(x >= 0)
def readMem():
	return psutil.used_virtmem()
Exemple #16
0
def check_mem():
	server = 'localhost'
	port = 2003
	##	hostname needed for the graphite tree
	hostname = socket.gethostname()
	##	build the tree up a bit
	tree = hostname+".memory."
	##	build a dictionary of the values we want to graph
	try:
		mem_dict = {"total_physical_memory": psutil.phymem_usage().total, 'free_physical_memory':psutil.phymem_usage().free, "used_physical_memory": psutil.phymem_usage().used, "total_virtual_memory":psutil.total_virtmem(), "free_virtual_memory": psutil.avail_virtmem(), "used_virtual_memory": psutil.used_virtmem()}
		##	Iterate the dictionary and write out the value to graphite for each key
		for key in mem_dict:
			w2g(server, port, tree+key, mem_dict[key])
	except Exception as e: ##	clean up errors a bit
		print e
		exit(1)
Exemple #17
0
    def _store_resources(self, store=True):
        """Looks at the resources usage and store the data locally.

        store (bool): if False, run the method but do not store the
                      resulting values - useful for initializing the
                      previous values

        """
        logger.debug("ResourceService._store_resources")
        # We use the precise time to compute the delta
        now = time.time()
        delta = now - self._last_saved_time
        self._last_saved_time = now
        now = int(now)

        data = {}

        # CPU
        cpu_times = self._get_cpu_times()
        data["cpu"] = dict((x, int(round((cpu_times[x] -
                                          self._prev_cpu_times[x])
                                   / delta * 100.0)))
                            for x in cpu_times)
        data["cpu"]["num_cpu"] = psutil.NUM_CPUS
        self._prev_cpu_times = cpu_times

        # Memory. We differentiate from old and deprecated (< 0.3.0)
        # methods to the new ones. Remove the differentiation when we
        # drop the support for Ubuntu 11.10 (which ships 0.2.1).
        ram_cached = psutil.cached_phymem()
        ram_buffers = psutil.phymem_buffers()
        if psutil_version < (0, 3, 0):
            data["memory"] = {
                "ram_total": psutil.TOTAL_PHYMEM / B_TO_MB,
                "ram_available": psutil.avail_phymem() / B_TO_MB,
                "ram_cached": ram_cached / B_TO_MB,
                "ram_buffers": ram_buffers / B_TO_MB,
                "ram_used": (psutil.used_phymem() - ram_cached - ram_buffers)
                                  / B_TO_MB,
                "swap_total": psutil.total_virtmem() / B_TO_MB,
                "swap_available": psutil.avail_virtmem() / B_TO_MB,
                "swap_used": psutil.used_virtmem() / B_TO_MB,
                }
        else:
            phymem = psutil.phymem_usage()
            virtmem = psutil.virtmem_usage()
            data["memory"] = {
                "ram_total": phymem.total / B_TO_MB,
                "ram_available": phymem.free / B_TO_MB,
                "ram_cached": ram_cached / B_TO_MB,
                "ram_buffers": ram_buffers / B_TO_MB,
                "ram_used": (phymem.used - ram_cached - ram_buffers) / B_TO_MB,
                "swap_total": virtmem.total / B_TO_MB,
                "swap_available": virtmem.free / B_TO_MB,
                "swap_used": virtmem.used / B_TO_MB,
                }

        data["services"] = {}
        # Details of our services
        for service in self._local_services:
            dic = {"autorestart": self._will_restart[service],
                   "running": True}
            proc = self._procs[service]
            # If we don't have a previously found process for the
            # service, we find it
            if proc is None:
                proc = self._find_proc(service)
            # If we still do not find it, there is no process
            if proc is None:
                dic["running"] = False
            # We have a process, but maybe it has been shut down
            elif not proc.is_running():
                # If so, let us find the new one
                proc = self._find_proc(service)
                # If there is no new one, continue
                if proc is None:
                    dic["running"] = False
            # If the process is not running, we have nothing to do.
            if not dic["running"]:
                data["services"][str(service)] = dic
                continue

            try:
                dic["since"] = self._last_saved_time - proc.create_time
                dic["resident"], dic["virtual"] = \
                    (x / 1048576  for x in proc.get_memory_info())
                cpu_times = proc.get_cpu_times()
                dic["user"] = int(
                    round((cpu_times[0] -
                           self._services_prev_cpu_times[service][0])
                          / delta * 100))
                dic["sys"] = int(
                    round((cpu_times[1] -
                           self._services_prev_cpu_times[service][1])
                          / delta * 100))
                self._services_prev_cpu_times[service] = cpu_times
                try:
                    dic["threads"] = proc.get_num_threads()
                except AttributeError:
                    dic["threads"] = 0  # 0 = Not implemented

                self._procs[service] = proc
            except psutil.error.NoSuchProcess:
                # Shut down while we operated?
                dic = {"autorestart": self._will_restart[service],
                       "running": False}
            data["services"][str(service)] = dic

        if store:
            if len(self._local_store) >= 5000:  # almost 7 hours
                self._local_store = self._local_store[1:]
            self._local_store.append((now, data))

        return True
Exemple #18
0
    def run(self):
        speed_avg = psutil.network_io_counters(pernic=True)
        seguir = True
        while seguir:
            #calculate time generate stats
            start = time.time()
            #calculate stats
            # speed network #
            network_actual = pick_speed_in_secs(2)
            network_avg = pick_speed_avg(speed_avg);
            speed_avg = network_avg[2];
            # pack all #
            try:
                temperature = int(int(os.popen("cat /sys/class/thermal/thermal_zone0/temp").read())/1000)
            except:
                temperature = 40
            data = {
                "network_down": network_actual[1],#
                "network_up": network_actual[0],#
                "network_avg_down": network_avg[1],#
                "network_avg_up": network_avg[0],#
                "cache": psutil.cached_phymem(),#
                "buffer": psutil.phymem_buffers(),#
                "used": psutil.used_phymem(),#
                "swap_total": psutil.total_virtmem(),#
                "swap_used": psutil.used_virtmem(),#
                "hdd_use_": psutil.disk_usage('/')[3],
                "hdd_use_home": psutil.disk_usage('/home')[3],
                "cpu_use": psutil.cpu_percent(interval=1),#
                "cpu_mhz": int(os.popen("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq").read()[:-3]),
                "temp": temperature
            }
            data_string = json.dumps(data)
            #print 'ENCODED:', data_string
            temp = time.localtime(start)
            datatime = str(temp[2])+"/"+str(temp[1])+"/"+str(temp[0])+" "+str(temp[3])+"/"+str(temp[4])+"/"+str(temp[5])
                
            if (os.path.exists(url_file_location) != True):
                data = {
                    "ava": psutil.avail_phymem(),#
                    "swap_ava": psutil.avail_virtmem(),#
                }
                data_string_2 = json.dumps(data)
                tmp = True
            else:
                tmp = False

            f=open(str(url_file_location),"a")
            if (tmp == True):
                f.write('"data":'+data_string_2)
            f.write(', '+'"'+datatime+'":'+data_string)

            f.close()
            
            del data
            del data_string
            del temp
            del datatime
            del network_actual
            del temperature

            time.sleep(generate_time - int(time.time() - start))
Exemple #19
0
    def _store_resources(self, store=True):
        """Looks at the resources usage and store the data locally.

        store (bool): if False, run the method but do not store the
                      resulting values - useful for initializing the
                      previous values

        """
        logger.debug("ResourceService._store_resources")
        # We use the precise time to compute the delta
        now = time.time()
        delta = now - self._last_saved_time
        self._last_saved_time = now
        now = int(now)

        data = {}

        # CPU
        cpu_times = self._get_cpu_times()
        data["cpu"] = dict((x, int(round((cpu_times[x] -
                                          self._prev_cpu_times[x])
                                   / delta * 100.0)))
                            for x in cpu_times)
        data["cpu"]["num_cpu"] = psutil.NUM_CPUS
        self._prev_cpu_times = cpu_times

        # Memory. We differentiate from old and deprecated (< 0.3.0)
        # methods to the new ones. Remove the differentiation when we
        # drop the support for Ubuntu 11.10 (which ships 0.2.1).
        ram_cached = psutil.cached_phymem()
        ram_buffers = psutil.phymem_buffers()
        if psutil_version < (0, 3, 0):
            data["memory"] = {
                "ram_total": psutil.TOTAL_PHYMEM / B_TO_MB,
                "ram_available": psutil.avail_phymem() / B_TO_MB,
                "ram_cached": ram_cached / B_TO_MB,
                "ram_buffers": ram_buffers / B_TO_MB,
                "ram_used": (psutil.used_phymem() - ram_cached - ram_buffers)
                                  / B_TO_MB,
                "swap_total": psutil.total_virtmem() / B_TO_MB,
                "swap_available": psutil.avail_virtmem() / B_TO_MB,
                "swap_used": psutil.used_virtmem() / B_TO_MB,
                }
        else:
            phymem = psutil.phymem_usage()
            virtmem = psutil.virtmem_usage()
            data["memory"] = {
                "ram_total": phymem.total / B_TO_MB,
                "ram_available": phymem.free / B_TO_MB,
                "ram_cached": ram_cached / B_TO_MB,
                "ram_buffers": ram_buffers / B_TO_MB,
                "ram_used": (phymem.used - ram_cached - ram_buffers) / B_TO_MB,
                "swap_total": virtmem.total / B_TO_MB,
                "swap_available": virtmem.free / B_TO_MB,
                "swap_used": virtmem.used / B_TO_MB,
                }

        data["services"] = {}
        # Details of our services
        for service in self._local_services:
            dic = {"autorestart": self._will_restart[service],
                   "running": True}
            proc = self._procs[service]
            # If we don't have a previously found process for the
            # service, we find it
            if proc is None:
                proc = self._find_proc(service)
            # If we still do not find it, there is no process
            if proc is None:
                dic["running"] = False
            # We have a process, but maybe it has been shut down
            elif not proc.is_running():
                # If so, let us find the new one
                proc = self._find_proc(service)
                # If there is no new one, continue
                if proc is None:
                    dic["running"] = False
            # If the process is not running, we have nothing to do.
            if not dic["running"]:
                data["services"][str(service)] = dic
                continue

            try:
                dic["since"] = self._last_saved_time - proc.create_time
                dic["resident"], dic["virtual"] = \
                    (x / 1048576  for x in proc.get_memory_info())
                cpu_times = proc.get_cpu_times()
                dic["user"] = int(
                    round((cpu_times[0] -
                           self._services_prev_cpu_times[service][0])
                          / delta * 100))
                dic["sys"] = int(
                    round((cpu_times[1] -
                           self._services_prev_cpu_times[service][1])
                          / delta * 100))
                self._services_prev_cpu_times[service] = cpu_times
                try:
                    dic["threads"] = proc.get_num_threads()
                except AttributeError:
                    dic["threads"] = 0  # 0 = Not implemented

                self._procs[service] = proc
            except psutil.error.NoSuchProcess:
                # Shut down while we operated?
                dic = {"autorestart": self._will_restart[service],
                       "running": False}
            data["services"][str(service)] = dic

        if store:
            if len(self._local_store) >= 5000:  # almost 7 hours
                self._local_store = self._local_store[1:]
            self._local_store.append((now, data))

        return True
Exemple #20
0
 def test_used_virtmem(self):
     x = psutil.used_virtmem()
     self.assertTrue(isinstance(x, (int, long)))
     self.assertTrue(x >= 0)