Skip to content

Instantly share code, notes, and snippets.

@youqingkui
Forked from 582033/python
Created July 5, 2018 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youqingkui/6b43b43460df7df164299cf05076611c to your computer and use it in GitHub Desktop.
Save youqingkui/6b43b43460df7df164299cf05076611c to your computer and use it in GitHub Desktop.
树莓派获取[cpu温度/cpu使用率/内存空闲率]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
显示树莓派cpu温度、使用率及内存使用率
'''
import os
def show_temp():
file = open("/sys/class/thermal/thermal_zone0/temp")
temp = float(file.read()) / 1000
file.close()
print "Temp: %.1f ℃" %temp
def show_mem():
mem_cmd = "free -m | grep Mem | awk '{print ($4+$6)/$2}'"
mem_sur = round(float(os.popen(mem_cmd).read()), 2) * 100
print "Mem: %d%%" % mem_sur
def show_cpu():
cpu_cmd = "uptime | awk '{print $8,$9,$10,$11,$12}'"
cpu_used = os.popen(cpu_cmd).read()
print "Cpu: %s" % cpu_used.replace('\n', '')
if __name__ == '__main__':
show_temp()
show_cpu()
show_mem()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment