Pi Alert

Pi Alert Screenshot from Github

Pi Alert continually scans your network and can alert you for new devices joining and devices going offline. This information is made available in a web interface and it’s light enough to run on the Pi Zero.

Unfortunately Pi Alert has no authentication whatsoever, presumably because it is only intended to be used on the same network, but we can fix that!

Tailscale

Tailscale lets me access my pi and services running on it from anywhere, it also lets me lock down those services so they can only be accessed with authentication.

Another bonus of tailscale on the pi is that it has a stable ip address so I don’t have to scan my own network every time I need to ssh in, and with dns I can use

ssh pi@pi-zero

Uptime Kuma

The Pi Zero doesn’t have enough CPU power to run Netdata which I use to monitor my servers so I will monitor it with Uptime Kuma. It’s running on my Raspberry Pi 4 and can be accessed over tailscale with https. Uptime Kuma is also dockerized which is as close as you can get to a declarative setup without NixOS.

Uptime Kuma itself is just an uptime monitor but it can be hacked into monitoring cpu usage, ram, and nearly anything else using the push API. When you create a push link that looks like this: https://<url>/api/push/<token>?status=up&msg=OK&ping=. You can make a request to that url and enter any number for the ping. To monitor RAM usage you can use a script like:

#!/usr/bin/env bash

RAM=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
LOAD=$(cut -d " " -f 1 /proc/loadavg)

RAM=$(printf "%.0f" "$RAM")
LOAD=$(($(printf "%.0f" "$LOAD") + 1))

curl -so "https://<url>/api/push/<token>?status=up&msg=OK&ping=$RAM"
curl -so "https://<url>/api/push/<token>?status=up&msg=OK&ping=$LOAD"

and use cron to have that run every 10 seconds, the result is uptime kuma shows my pi’s uptime with the ram usage % as the ping.

Uptime Stats for my Pi Zero with the ram as ping

(the random spikes are caused by the arp scans for pi alert)

It’s a pretty hacky solution due to the Pi Zero being so low power, in fact I couldn’t even use python for the scripts because CPU usage always came back as “100” due to the library imports.

You can comment on this post on Mastodon