-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstate.py
64 lines (63 loc) · 1.73 KB
/
state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python2.7
#-*- coding: UTF-8 -*-
import commands
import os
import thread
import time
import random
import sys
#
def get_cpu_used():
cpu_used = commands.getoutput( 'top -n 2 -d 0.5| grep Cpu' ).split()[24]
cpu_used_re = 100 - float(cpu_used)
return cpu_used_re
#
def get_cpu_temp():
tmpFile = open( '/sys/class/thermal/thermal_zone0/temp' )
cpu_temp = tmpFile.read()
tmpFile.close()
return round(float(cpu_temp)/1000, 1)
#
def get_cpu_freq():
tmpFile = open( '/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq' )
cpu_freq = tmpFile.read()
tmpFile.close()
return float(cpu_freq)/1000
#
def get_gpu_temp():
gpu_temp = commands.getoutput( '/opt/vc/bin/vcgencmd measure_temp' ).replace( 'temp=', '' ).replace( '\'C', '' )
return float(gpu_temp)
#
def get_gpu_freq():
gpu_temp = commands.getoutput( '/opt/vc/bin/vcgencmd measure_clock core' ).replace( 'frequency(1)=', '' )
return float(gpu_temp)/1000000
#
def get_men_total():
tmpFile = open( '/proc/meminfo' )
lines = tmpFile.readlines()
mem_total = round(float(lines[0].split()[1]) / 1024, 1)
return float(mem_total)
#
def get_men_used():
tmpFile = open( '/proc/meminfo' )
lines = tmpFile.readlines()
mem_total = round(float(lines[0].split()[1]) / 1024, 1)
mem_free = round(float(lines[2].split()[1]) / 1024, 1)
men_used = round((mem_free/mem_total)*100, 1)
men_used = 100 - men_used
return men_used
#
def get_disk_total():
disk_used = round(float(commands.getoutput( 'df -m / | grep /' ).split()[1]) / 1024, 1)
return disk_used
#
def get_disk_used():
disk_used = round(float(commands.getoutput( 'df -m / | grep /' ).split()[2]) / 1024, 1)
return disk_used
#
def get_ip_addr():
ip_addr = commands.getoutput( 'hostname -I' )
if ip_addr:
return ip_addr
else:
return 'No network'