info.py 1.07 KiB
#!/usr/bin/python3
# File name : Ultrasonic.py
# Description : Detection distance and tracking with ultrasonic
# Website : www.gewbot.com
# Author : William
# Date : 2019/08/28
import psutil
def get_cpu_tempfunc():
""" Return CPU temperature """
result = 0
mypath = "/sys/class/thermal/thermal_zone0/temp"
with open(mypath, 'r') as mytmpfile:
for line in mytmpfile:
result = line
result = float(result)/1000
result = round(result, 1)
return str(result)
def get_gpu_tempfunc():
""" Return GPU temperature as a character string"""
res = os.popen('/opt/vc/bin/vcgencmd measure_temp').readline()
return res.replace("temp=", "")
def get_cpu_use():
""" Return CPU usage using psutil"""
cpu_cent = psutil.cpu_percent()
return str(cpu_cent)
def get_ram_info():
""" Return RAM usage using psutil """
ram_cent = psutil.virtual_memory()[2]
return str(ram_cent)
def get_swap_info():
""" Return swap memory usage using psutil """
swap_cent = psutil.swap_memory()[3]
return str(swap_cent)