def virtual_memory(): total, free, buffers, shared, _, _ = _psutil_linux.get_sysinfo() cached = active = inactive = None f = open('/proc/meminfo', 'r') try: for line in f: if line.startswith('Cached:'): cached = int(line.split()[1]) * 1024 elif line.startswith('Active:'): active = int(line.split()[1]) * 1024 elif line.startswith('Inactive:'): inactive = int(line.split()[1]) * 1024 if cached is not None \ and active is not None \ and inactive is not None: break else: # we might get here when dealing with exotic Linux flavors, see: # http://code.google.com/p/psutil/issues/detail?id=313 msg = "'cached', 'active' and 'inactive' memory stats couldn't " \ "be determined and were set to 0" warnings.warn(msg, RuntimeWarning) cached = active = inactive = 0 finally: f.close() avail = free + buffers + cached used = total - free percent = usage_percent((total - avail), total, _round=1) return nt_virtmem_info(total, avail, percent, used, free, active, inactive, buffers, cached)
def virtual_memory(): total, free, buffers, shared, _, _ = _psutil_linux.get_sysinfo() cached = active = inactive = None f = open('/proc/meminfo', 'r') try: for line in f: if line.startswith('Cached:'): cached = int(line.split()[1]) * 1024 elif line.startswith('Active:'): active = int(line.split()[1]) * 1024 elif line.startswith('Inactive:'): inactive = int(line.split()[1]) * 1024 if cached is not None \ and active is not None \ and inactive is not None: break else: raise RuntimeError("line(s) not found") finally: f.close() avail = free + buffers + cached used = total - free percent = usage_percent((total - avail), total, _round=1) return nt_virtmem_info(total, avail, percent, used, free, active, inactive, buffers, cached)
def swap_memory(): _, _, _, _, total, free = _psutil_linux.get_sysinfo() used = total - free percent = usage_percent(used, total, _round=1) # get pgin/pgouts f = open("/proc/vmstat", "r") sin = sout = None try: for line in f: # values are expressed in 4 kilo bytes, we want bytes instead if line.startswith('pswpin'): sin = int(line.split(' ')[1]) * 4 * 1024 elif line.startswith('pswpout'): sout = int(line.split(' ')[1]) * 4 * 1024 if sin is not None and sout is not None: break else: # we might get here when dealing with exotic Linux flavors, see: # http://code.google.com/p/psutil/issues/detail?id=313 msg = "'sin' and 'sout' swap memory stats couldn't " \ "be determined and were set to 0" warnings.warn(msg, RuntimeWarning) sin = sout = 0 finally: f.close() return nt_swapmeminfo(total, used, free, percent, sin, sout)
def swap_memory(): _, _, _, _, total, free = _psutil_linux.get_sysinfo() used = total - free percent = usage_percent(used, total, _round=1) # get pgin/pgouts f = open("/proc/vmstat", "r") sin = sout = None try: for line in f: # values are expressed in 4 kilo bytes, we want bytes instead if line.startswith('pswpin'): sin = int(line.split(' ')[1]) * 4 * 1024 elif line.startswith('pswpout'): sout = int(line.split(' ')[1]) * 4 * 1024 if sin is not None and sout is not None: break else: raise RuntimeError("line(s) not found") finally: f.close() return nt_swapmeminfo(total, used, free, percent, sin, sout)
line = line.split(' ')[0] if search.match(line): num += 1 if num == 0: raise RuntimeError("can't determine number of CPUs") return num # Number of clock ticks per second _CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"]) _PAGESIZE = os.sysconf("SC_PAGE_SIZE") _TERMINAL_MAP = _psposix._get_terminal_map() BOOT_TIME = _get_boot_time() NUM_CPUS = _get_num_cpus() TOTAL_PHYMEM = _psutil_linux.get_sysinfo()[0] # ioprio_* constants http://linux.die.net/man/2/ioprio_get IOPRIO_CLASS_NONE = 0 IOPRIO_CLASS_RT = 1 IOPRIO_CLASS_BE = 2 IOPRIO_CLASS_IDLE = 3 # http://students.mimuw.edu.pl/lxr/source/include/net/tcp_states.h _TCP_STATES_TABLE = {"01" : "ESTABLISHED", "02" : "SYN_SENT", "03" : "SYN_RECV", "04" : "FIN_WAIT1", "05" : "FIN_WAIT2", "06" : "TIME_WAIT", "07" : "CLOSE", "08" : "CLOSE_WAIT",
# Since these constants get determined at import time we do not want to # crash immediately; instead we'll set them to None and most likely # we'll crash later as they're used for determining process CPU stats # and creation_time try: BOOT_TIME = get_system_boot_time() except Exception: BOOT_TIME = None warnings.warn("couldn't determine platform's BOOT_TIME", RuntimeWarning) try: NUM_CPUS = get_num_cpus() except Exception: NUM_CPUS = None warnings.warn("couldn't determine platform's NUM_CPUS", RuntimeWarning) try: TOTAL_PHYMEM = _psutil_linux.get_sysinfo()[0] except Exception: TOTAL_PHYMEM = None warnings.warn("couldn't determine platform's TOTAL_PHYMEM", RuntimeWarning) # ioprio_* constants http://linux.die.net/man/2/ioprio_get IOPRIO_CLASS_NONE = 0 IOPRIO_CLASS_RT = 1 IOPRIO_CLASS_BE = 2 IOPRIO_CLASS_IDLE = 3 # http://students.mimuw.edu.pl/lxr/source/include/net/tcp_states.h _TCP_STATES_TABLE = {"01" : CONN_ESTABLISHED, "02" : CONN_SYN_SENT, "03" : CONN_SYN_RECV,