-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiagnostics.py
53 lines (42 loc) · 1.67 KB
/
diagnostics.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
import socket
import time
import requests
import psutil
import os
from screen import Screen
class Diagnostics(Screen):
def __init__(self, hat):
self.hat = hat
self.cpu_usage = psutil.cpu_percent()
def down(self):
return "Wifi"
def getLocalIp(self):
return socket.gethostbyname(socket.getfqdn())
def printLocalIp(self):
self.hat.show_message(self.getLocalIp(), scroll_speed=0.1, text_colour=[100,0,0])
def getWan(self):
ret = requests.request('GET', 'http://myip.dnsomatic.com')
return ret.text
def printWan(self):
try:
self.hat.show_message(self.getWan(), scroll_speed=0.1, text_colour=[100,0,0])
except Exception as e:
self.hat.show_message("No IP", scroll_speed=0.1, text_colour=[100,0,0])
def printCpuUsage(self):
cpu = psutil.cpu_percent(interval=1)
self.hat.show_message("CPU: "+str(cpu)+"%", scroll_speed=0.1, text_colour=[100,0,0])
def printCpuTemp(self):
cpu_temp = os.popen('/opt/vc/bin/vcgencmd measure_temp').read()
cpu_temp = cpu_temp.replace("temp=","")
self.hat.show_message("CPU Temp: " + cpu_temp, scroll_speed=0.1, text_colour=[100,0,0])
def printDiskUsage(self):
percent = psutil.disk_usage('/').percent
self.hat.show_message("Disk: "+str(percent)+"%", scroll_speed=0.1, text_colour=[100,0,0])
def run(self, going):
while going.isSet():
func = [self.printCpuUsage, self.printCpuTemp, self.printDiskUsage, self.printWan]
for f in func:
f()
self.delay(2, going)
if not going.isSet():
break