Raspberry Pi with Sense HAT
Image credit: Martin Lanser

f451 Labs piF451 - System Monitor With Sense HAT

Overview

The main objective of this project is to run one or more monitoring applications, which collect data, upload it to the cloud, and display some form of progress on an onboard display. This Raspberry Pi has a Raspberry Pi Sense HAT with an 8x8 LED display. And while the Sense HAT has several onboard sensors, we’ll only use the display and joystick.

I have another Rasberry Pi equipped with a Sense HAT, which collects data from the onboard sensor. And no, I can not for the life of me remember why I decided to get two Sense HATs. It turns out that I have bought many things over the years, but I cannot remember what projects I purchased them for 🤓

This particular Raspberry Pi device currently runs one application — sysmon — and the main task is to perform an internet speed test at regular intervals. This data is then uploaded to an Adafruit IO feed and displayed (crudely) on the onboard 8x8 LED display.

The Sense HAT joystick can switch display modes to show upload or download speeds and ping response times. There is even a “Sparkle Mode,” which simply lights up random LEDs. It’s pretty at night, and it lets me know that the app is still running 😊

Device specifications & configuration

General specifications

I decided to use this (fairly) powerful Raspberry Pi so that I can host various types of projects and websites without worrying much about performance.

Main tools & applications

Most software on this device focuses on running various Python applications. But I’ve also added a few tools to make life easier when I need to debug stuff after things go sideways.

  • NetworkManager — my default tool for managing network settings on my RPIs
  • UFW (firewall) — my default tool for managing firewall settings on my RPIs
  • htop — my default process viewer/manager on my RPIs
  • Misc. tools — e.g. PIPX, git, etc.

As a side note, most of my devices are configured in similar ways with (mostly) the same tools. And while some devices have GUIs, most do not, and I usually access all devices from my laptop via SSH.

Custom applications & scripts

This Raspberry Pi is configured the following applications and scripts:

  • sysmon — this application performs internet speed test checks using the SpeedTest CLI library. The data is uploaded to Adafruit IO and is also displayed in real-time on the onboard 8x8 LED display.

The sysmon application is installed as part of the overall f451-piF451 package. You can run it directly from the terminal when the package is installed with the pip or pipx commands (see below for more info).

Common workflows

Given its role as a single-purpose monitoring device, there is essentially only one workflow (aside from maintaining the device itself): install and run monitoring applications.

My CLI applications can be installed via the pip command, so the workflow is straightforward. Although, I have switched to using the pipx command to ensure that whatever application I install does not “pollute” the Python environment on this Raspberry Pi device.

Now, one additional wrinkle is that my applications and packages are not hosted on PyPi. Instead, I install them directly from my GitHub repo as follows:

$ pipx install git+ssh://<username>@github.com/<path-to-my-app.git>

This method allows me to install Python applications quickly, and I can run each CLI application by simply typing my_app_name in the terminal.

The pipx install command is very flexible, and several switches are available. For example, the --python switch allows us to define which version of Python (v3.6+) to use for the installation, which can be very useful when trying different scenarios.

It’s also possible to use the pipx upgrade to upgrade one’s application. However, that assumes that one first has bumped the version number in GitHub. Instead, I rerun the pip install command with the --force switch, which doesn’t care whether the version has been bumped.

Finally, I do not install my applications in “editable” mode (using the -e switch) on this Raspberry Pi as I do not edit code directly on this device.

Install f451-piF451 package

This package installs all custom applications and scripts for this Raspberry Pi device. There is currently only one application — sysmon — but others maybe added in the future.

When the f451-piF451 package is intalled, the sysmon command is enabled and can be launched from the terminal as follows:

# == If installed with 'pip' == 
# -1- Run in current terminal session
$ sysmon --debug

# -2- Run in background 
$ nohup sysmon > sysmon.out &

# == If NOT installed with 'pip' ==
# -3- Run in background 
$ nohup python -u sysmon.py > sysmon.out &

The first command simply runs the sysmon application in “debug’ mode in the current terminal session. This is a great way to test if your settings and the device are configured properly.

The second command launches the sysmon application in the background, and it will keep running even after the terminal window is closed. Any output will be redirected to the sysmon.out file.

Finally, the third command shows how to run sysmon in the background if the pacakage is not installed with pip.

The README.md file for the f451-piF451 package has further instructions on how to configure the settings.toml file, etc.

Summary

Getting this Raspberry Pi up and running as a single-purpose device running a few CLI applications was trivial. However, it’s worth noting that the goal is for this device to essentially never stop running. That means one needs to think through how to automate and streamline maintenance and support routines.

For example, from time to time, we’ll need to update the OS, the various support libraries, etc. And, of course, every once in a while, we’ll want to update the actual monitoring applications. Most maintenance tasks can be done without restarting the device. But there are occasions when the updates require a restart.

Finally, there are external events that may affect this device. For example, we had a day-long internet outage not too long ago, and when everything came back online, we had to restart the router. Then, there have been power outages in the neighborhood. And no, my home network of Raspberry Pis is not hosted in a data center with fail-over power, etc. So when the lights go out, the devices go down.

All this means that it’s worth spending a bit of time creating easy (re-)start processes, upgrade scripts, and so on 😊