-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlcdSysInfo
executable file
·81 lines (69 loc) · 1.78 KB
/
lcdSysInfo
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
#
# !!! Needs psutil installing:
#
# $ sudo pip install psutil
#
import os
import sys
from time import sleep
if os.name != 'posix':
sys.exit('platform not supported')
from datetime import datetime
import psutil
import lcd as lcd
def bytes2human(n):
"""
>>> bytes2human(10000)
'9K'
>>> bytes2human(100001221)
'95M'
"""
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
prefix = {}
for i, s in enumerate(symbols):
prefix[s] = 1 << (i+1)*10
for s in reversed(symbols):
if n >= prefix[s]:
value = int(float(n) / prefix[s])
return '%s%s' % (value, s)
return "%sB" % n
def cpu_usage():
# load average, uptime
av1 = psutil.cpu_percent(interval=None)
#av1, av2, av3 = os.getloadavg()
return "Load: %.1f%% " \
% (av1 )
def uptime():
# uptime
uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME)
return "Up: %sh" \
% (str(uptime).split('.')[0])
def mem_usage():
usage = psutil.phymem_usage()
return "Mem Used: %s " \
% (bytes2human(usage.used))
def disk_usage(dir):
usage = psutil.disk_usage(dir)
return "SDCard: %s %.0f%%" \
% (bytes2human(usage.used), usage.percent)
def network(iface):
stat = psutil.network_io_counters(pernic=True)[iface]
return "%s:Tx%s,Rx%s" % \
(iface, bytes2human(stat.bytes_sent), bytes2human(stat.bytes_recv))
def stats():
lcd.str(0,"Olimexino:")
lcd.str(1,cpu_usage())
lcd.str(2,uptime())
lcd.str(3,mem_usage())
lcd.str(4,disk_usage('/'))
#lcd.str(3,network('wlan7'))
lcd.update()
def main():
lcd.init()
lcd.clear()
while(1):
stats()
sleep(1)
if __name__ == "__main__":
main()