-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCPU.py
46 lines (35 loc) · 1.05 KB
/
CPU.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
#!/usr/bin/python2.7
from __future__ import division
from subprocess import PIPE, Popen
import psutil
import json
def get_cpu_temperature():
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE)
output, _error = process.communicate()
return float(output[output.index('=') + 1:output.rindex("'")])
def main():
cpu_temperature = get_cpu_temperature()
cpu_usage = psutil.cpu_percent()
ram = psutil.virtual_memory()
ram_total = ram.total / 2**20 # MiB.
ram_used = ram.used / 2**20
ram_free = ram.free / 2**20
ram_percent_used = ram.percent
disk = psutil.disk_usage('/')
disk_total = disk.total / 2**30 # GiB.
disk_used = disk.used / 2**30
disk_free = disk.free / 2**30
disk_percent_used = disk.percent
jsonData = {
'ram_total':ram_total,
'ram_used':ram_used,
'ram_free':ram_free,
'ram_percent_used':ram_percent_used,
'disk_total':disk_total,
'disk_used':disk_used,
'disk_free':disk_free,
'disk_percent_used':disk_percent_used,
}
print json.dumps(jsonData)
if __name__ == '__main__':
main()