60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
__author__ = 'asc'
|
|
import os
|
|
import psutil
|
|
|
|
|
|
class System():
|
|
|
|
def __init__(self):
|
|
#TODO add system initialization
|
|
pass
|
|
|
|
@property
|
|
def status (self):
|
|
#TODO status check
|
|
return (0, "System functioning properly")
|
|
|
|
import os
|
|
|
|
# Return CPU temperature as a character string
|
|
def getCPUtemperature(self):
|
|
res = os.popen('vcgencmd measure_temp').readline()
|
|
return(res.replace("temp=","").replace("'C\n",""))
|
|
|
|
def getCPUusage(self):
|
|
p=psutil.cpu_percent(interval=1)
|
|
return p
|
|
|
|
def getRAMinfo(self):
|
|
p = dict(psutil.virtual_memory()._asdict())
|
|
p = dict(psutil.swap_memory()._asdict())
|
|
return p
|
|
|
|
def getDiskSpace(self):
|
|
p = dict(psutil.disk_usage('/')._asdict())
|
|
return p
|
|
|
|
@property
|
|
def stats (self):
|
|
# CPU informatiom
|
|
CPU_temp = self.getCPUtemperature()
|
|
CPU_usage = self.getCPUusage()
|
|
|
|
# RAM information
|
|
# Output is in kb, here I convert it in Mb for readability
|
|
RAM_stats = self.getRAMinfo()
|
|
|
|
|
|
# Disk information
|
|
DISK_stats = self.getDiskSpace()
|
|
|
|
pid = os.getpid()
|
|
|
|
|
|
# print(type(DISK_stats._asdict()))
|
|
|
|
return {"cpu_temp":CPU_temp,
|
|
"cpu_usage":CPU_usage,
|
|
"ram_stats":RAM_stats,
|
|
"disk_stats":DISK_stats,
|
|
"PID":pid} |