What my Linux boxes check every hour
What the hourly health check on my two Linux boxes looks at, the numbers it warns on, and the time it failed every hour over a socket that was fine.
Both my Linux boxes run a health check every hour from a systemd timer. It’s one Python script, standard library only, niced right down, and it prints a line per check. This is most of a run on the box I carry:
OK space / 10% used, 780 GB free of 868 GB
OK space /data 65% used, 641 GB free of 1814 GB
WARN growth /data growing 58 GB a day over the last 7 days: full in about 11 days (room elsewhere: / 780 GB free, /home 587 GB free)
OK space /home 35% used, 587 GB free of 906 GB
OK services every enabled service is running
OK updates no security updates waiting (0 other)
OK backup last good run 0 days ago; repository 184 GB
OK kernel no I/O, filesystem or out-of-memory messages since the last run
The /data line is why I wrote it. At 65 per cent that partition passes any check that only reads the level, and it has eleven days left.
What it looks at
Space on every mounted filesystem: a warning at 80 per cent and a failure at 90, and on anything over 100 GB also at 50 GB and 20 GB free. Inodes too, and a filesystem that has gone read-only, which is what ext4 does to itself after errors.
Growth is the part the old daily check never had. The script keeps an hourly sample of every partition for 60 days and works out when the last week’s growth would fill it. Under 30 days is a warning and under 7 is a failure. It ignores growth below half a gigabyte a day, and it says nothing at all until it has three days of samples. When it does warn it lists the partitions that have room.
From the journal it takes everything since the last run that looks like trouble: I/O errors, filesystem errors, NVMe resets and timeouts, and out-of-memory kills. It checks that everything in fstab is mounted, that the clock is synced, and that a reboot hasn’t been waiting more than 14 days.
Services are the enabled-but-not-running ones and any failed unit. There’s one exception. I sometimes stop MySQL, Elasticsearch and Apache on the home box to give a local model the memory, and the check leaves those alone, but it warns if I’ve left the box like that for more than 12 hours.
Security updates warn after 7 days and fail after 21. The backup warns when the last good run is over two days old and fails at three.
The last check is the other box. Each one reads the other’s most recent run, and three hours without one is a warning, six a failure. A box that has died can’t raise its own alert, so the other one does it.
How it tells me
A new warning or failure puts a notice on the desktop and sends a push to my phone through ntfy, which runs on a Raspberry Pi at home. A failure repeats every 6 hours and a warning every 24 until it’s fixed. There’s a command that sends one test alert down the same path, so I know the phone end works without waiting for something to break.
A failure that wasn’t one
Early on the services check failed on both boxes, every hour, over this:
$ systemctl is-active printmd-api-proxy.socket
inactive
$ systemctl --user is-active printmd-api-proxy.socket
active
That socket starts PrintMD’s PDF service on the first connection, and it’s a user unit. systemd runs one manager for the system and one for each logged-in user, and the system manager has never heard of my socket, so it answers inactive and exits 4. The service was fine the whole time. The check now asks each unit’s own manager.
With the repeat, that was a failure alert every six hours for a service that was up, in the same list as the real ones. The first run had found one of those: logrotate.service had been failing on the home box since 00:47 that night, because a backup copy of rsyslog’s config had been left inside /etc/logrotate.d, and logrotate reads every file in there and refused the duplicate entries. The older daily check had been marking that as failed since half past eight and I hadn’t seen it.
What is still off
The SMART checks are written and the parsing has a self-test, but they need smartctl, which needs root, and I haven’t yet given an hourly job a standing sudo. Until I do, that line says SKIP.
Featured projects
-
Apple News API
Publish articles and live coverage to Apple News from PHP, with the whole Apple News Format built from objects.
-
GitHub Auditor
Health, access and activity reports for more GitHub and Bitbucket repositories than you can keep in your head.
-
PrintMD
Markdown in, and a designed PDF, Word or PowerPoint file out. Its PDF service runs on your own computer.
-
Where Should I Live
Which city would leave you best off? Cities ranked by take-home pay, living costs, visas and the way you live.
-
Solar Calendar
Thirteen months of exactly four weeks, with the year starting on the first Monday on or after the spring equinox.
Latest writing
-
Many sessions at once, and what still needs me
Fifteen coding-agent sessions across two Linux boxes, one session that watches the rest, what it may answer for me, what it never may, and why a yes it passes on gets checked against what I typed.
-
61 public repos of agent tooling, none installed, six ideas kept
One author, 61 public repositories of coding-agent tooling: what I checked before any of it got near my Linux boxes, why none of it was installed, and the six ideas I built my own way.
-
Rules a coding agent cannot talk its way round
The hook that reads every command a coding agent wants to run on my Linux boxes: what it refuses, the 27 proofs that its tests fail when a rule is taken out, and the four lines every report opens with.
-
Dozens of repos, one person
46 repositories and two Linux boxes with nobody else on them: the diary, the decision table, the rebuild guide and the job that keeps both sets of clones in step.