Skip to content

Instantly share code, notes, and snippets.

@youqingkui
Forked from 582033/python
Created July 5, 2018 14:19
Show Gist options
  • Save youqingkui/6b43b43460df7df164299cf05076611c to your computer and use it in GitHub Desktop.
Save youqingkui/6b43b43460df7df164299cf05076611c to your computer and use it in GitHub Desktop.

Revisions

  1. @582033 582033 created this gist Jun 28, 2016.
    32 changes: 32 additions & 0 deletions python
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/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()