pioneer600

Pioneer600 sample for headless raspberry pi servers
git clone git://git.ckyln.com/pioneer600.git
Log | Files | Refs | README

add_module.py (1029B)


      1 #!/usr/bin/python
      2 # -*- coding:utf-8 -*-
      3 
      4 import os
      5     
      6 # Return CPU temperature as a character string
      7 def getCPUtemperature():
      8     res = os.popen('vcgencmd measure_temp').readline()
      9     return(res.replace("temp=","").replace("'C\n",""))
     10 
     11 # Return RAM information (unit=kb) in a list
     12 # Index 0: total RAM
     13 # Index 1: used RAM
     14 # Index 2: free RAM
     15 def getRAMinfo():
     16     p = os.popen('free')
     17     i = 0
     18     while 1:
     19         i = i + 1
     20         line = p.readline()
     21         if i==2:
     22             return(line.split()[1:4])
     23 
     24 # Return % of CPU used by user as a character string
     25 def getCPUuse():
     26     return(str(os.popen("top -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip()))
     27 
     28 # Return information about disk space as a list (unit included)
     29 # Index 0: total disk space
     30 # Index 1: used disk space
     31 # Index 2: remaining disk space
     32 # Index 3: percentage of disk used
     33 def getDiskSpace():
     34     p = os.popen("df -h /")
     35     i = 0
     36     while 1:
     37         i = i +1
     38         line = p.readline()
     39         if i==2:
     40             return(line.split()[1:5])