├── README.md └── pihealth.py /README.md: -------------------------------------------------------------------------------- 1 | # pi-health-dashboard 2 | 3 | ![Pi System Health Dashboard](https://github.com/InitialState/pi-health-dashboard/wiki/img/dashboard_final.gif) 4 | 5 | This is a hub for the System Health Dashboard for your Raspberry Pi project. 6 | 7 | Here you will find code materials for the tutorial as well as the tutorial itself in the [wiki](https://github.com/InitialState/pi-health-dashboard/wiki). 8 | 9 | Raspberry Pis are being used to drive a ridiculous number of projects ranging from fun hobby projects to mission critical functions. Despite being small, user-friendly, and inexpensive, your Pi contains an impressive number of complex subsystems that must work to keep your project running. This makes being able to monitor the health of your Pi important in many applications from ongoing maintenance of a long-term project to profiling the performance of a new prototype ... [read more](https://github.com/InitialState/pi-health-dashboard/wiki) 10 | 11 | -------------------------------------------------------------------------------- /pihealth.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import division 3 | from subprocess import PIPE, Popen 4 | import psutil 5 | import time 6 | from ISStreamer.Streamer import Streamer 7 | 8 | # --------- User Settings --------- 9 | # Initial State settings 10 | BUCKET_NAME = ":computer: Pi3 Performance" 11 | BUCKET_KEY = "pi0708" 12 | ACCESS_KEY = "PUT YOUR INITIAL STATE ACCESS_KEY HERE" 13 | # Set the time between checks 14 | MINUTES_BETWEEN_READS = 1 15 | METRIC_UNITS = False 16 | # --------------------------------- 17 | 18 | def get_cpu_temperature(): 19 | process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE) 20 | output, _error = process.communicate() 21 | return float(output[output.index('=') + 1:output.rindex("'")]) 22 | 23 | 24 | def main(): 25 | streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY) 26 | while True: 27 | cpu_temperature = get_cpu_temperature() 28 | if METRIC_UNITS: 29 | streamer.log("CPU Temperature(C)",cpu_temperature) 30 | else: 31 | cpu_temperature = cpu_temperature * 9.0 / 5.0 + 32.0 32 | streamer.log("CPU Temperature(F)",str("{0:.2f}".format(cpu_temperature))) 33 | 34 | cpu_percents = psutil.cpu_percent(percpu=True) 35 | streamer.log_object(cpu_percents, key_prefix="cpu") 36 | 37 | cpu_percent = psutil.cpu_percent(percpu=False) 38 | streamer.log("CPU Usage",cpu_percent) 39 | 40 | disk = psutil.disk_usage('/') 41 | disk_total = disk.total / 2**30 42 | streamer.log("Disk Total(GB)",str("{0:.2f}".format(disk_total))) 43 | disk_used = disk.used / 2**30 44 | streamer.log("Disk Used(GB)",str("{0:.2f}".format(disk_used))) 45 | disk_free = disk.free / 2**30 46 | streamer.log("Disk Free(GB)",str("{0:.2f}".format(disk_free))) 47 | disk_percent_used = disk.percent 48 | streamer.log("Disk Used(%)",str("{0:.2f}".format(disk_percent_used))) 49 | 50 | mem = psutil.virtual_memory() 51 | mem_total = mem.total / 2**20 52 | streamer.log("Memory Total(MB)",str("{0:.2f}".format(mem_total))) 53 | mem_avail = mem.available / 2**20 54 | streamer.log("Memory Available(MB)",str("{0:.2f}".format(mem_avail))) 55 | mem_percent_used = mem.percent 56 | streamer.log("Memory Used(%)",str("{0:.2f}".format(mem_percent_used))) 57 | mem_used = mem.used / 2**20 58 | streamer.log("Memory Used(MB)",str("{0:.2f}".format(mem_used))) 59 | mem_free = mem.free / 2**20 60 | streamer.log("Memory Free(MB)",str("{0:.2f}".format(mem_free))) 61 | 62 | net = psutil.net_io_counters() 63 | net_bytes_sent = net.bytes_sent / 2**20 64 | streamer.log("Network MB Sent",str("{0:.2f}".format(net_bytes_sent))) 65 | net_bytes_recv = net.bytes_recv / 2**20 66 | streamer.log("Network MB Received",str("{0:.2f}".format(net_bytes_recv))) 67 | net_errin = net.errin 68 | streamer.log("Network Errors Receiving",str(net_errin)) 69 | net_errout = net.errout 70 | streamer.log("Network Errors Sending",str(net_errout)) 71 | net_dropin = net.dropin 72 | streamer.log("Incoming Packets Dropped",str(net_dropin)) 73 | net_dropout = net.dropout 74 | streamer.log("Outgoing Packets Dropped",str(net_dropout)) 75 | 76 | streamer.flush() 77 | time.sleep(60*MINUTES_BETWEEN_READS) 78 | 79 | if __name__ == '__main__': 80 | main() 81 | --------------------------------------------------------------------------------