-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsystemstats.py
More file actions
76 lines (64 loc) · 1.85 KB
/
Copy pathsystemstats.py
File metadata and controls
76 lines (64 loc) · 1.85 KB
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
import io
import time
import psutil
import signal
import sys
import Adafruit_Nokia_LCD as LCD
import Adafruit_GPIO.SPI as SPI
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
# Raspberry Pi hardware SPI config:
DC = 23
RST = 24
SPI_PORT = 0
SPI_DEVICE = 0
# Hardware SPI usage:
disp = LCD.PCD8544(DC, RST, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=4000000))
# Initialize library.
disp.begin(contrast=55)
disp.set_contrast(55)
# Clear display.
disp.clear()
disp.display()
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
image = Image.new('1', (LCD.LCDWIDTH, LCD.LCDHEIGHT))
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Load default font.
font = ImageFont.load_default()
def signal_term_handler(signum = None, frame = None):
sys.stderr.write("Terminated.\n")
tFile.close()
disp.clear()
disp.display()
sys.exit(0)
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
signal.signal(sig, signal_term_handler)
#sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
try:
while 1:
# Clear image buffer.
draw.rectangle((0,0,83,47), outline=255, fill=255)
#disp.clear()
cpustr = "CPU: " + str(psutil.cpu_percent(interval=None)) + "%"
draw.text((0,00), cpustr, font=font)
memstr = "Mem: " + str(psutil.virtual_memory()[2]) + "%"
draw.text((0,10), memstr, font=font)
diskstr = "Disk: " + str(psutil.disk_usage("/")[3]) + "%"
draw.text((0,20), diskstr, font=font)
#clock
#timestr = time.strftime("%H:%M:%S", time.localtime())
tFile = open('/sys/class/thermal/thermal_zone0/temp')
temp = "Temp: " + "{:.2f}".format(float(tFile.read())/1000) + " C"
draw.text((0,30), temp, font=font)
# Display image.
disp.image(image)
disp.display()
time.sleep(1)
except:
tFile.close()
# clear display.
disp.clear()
disp.display()