56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
__author__ = 'asc'
|
|
import os
|
|
import psutil
|
|
|
|
|
|
class System_Debug():
|
|
|
|
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():
|
|
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():
|
|
p = psutil.virtual_memory()
|
|
p = psutil.swap_memory()
|
|
return p
|
|
|
|
def getDiskSpace():
|
|
p = psutil.disk_usage('/')
|
|
return p
|
|
|
|
@property
|
|
def stats (self):
|
|
#courtesy of Phillipe
|
|
# https://www.raspberrypi.org/forums/memberlist.php?mode=viewprofile&u=40834&sid=dd38cc12161ac10b324ed2a2238972d3
|
|
# CPU informatiom
|
|
CPU_temp = self.getCPUtemperature()
|
|
CPU_usage = self.getCPUuse()
|
|
|
|
# RAM information
|
|
# Output is in kb, here I convert it in Mb for readability
|
|
RAM_stats = self.getRAMinfo()
|
|
|
|
|
|
# Disk information
|
|
DISK_stats = self.getDiskSpace()
|
|
|
|
return {"cpu_temp":CPU_temp,
|
|
"cpu_usage":CPU_usage,
|
|
"ram_stats":RAM_stats,
|
|
"disk_stats":DISK_stats} |