update readme with systemd unit files
properly handle bad status codes
update readme
Occasionally we have some issues with hackNY.social going down for whatever reason. It sometimes takes me a bit to realize when this happens, so I figured a simple monitoring script would help me ensure better uptime.
I couldn've done this in Python or Ruby or some other mundane language but I've been on a Clojure binge lately and have been looking for an excuse to try babashka. After fiddling around with this script I can say I'm a fan!
Anyways, this script does the following:
That's it! To run it, just make sure you have Babashka's bb
in your $PATH
and run bb check
. It will create a new log.db file in your current working directory.
If you like what you see here I can imagine this is very easy to port over to your own use case (there's not a lot going on). Feel free to send me an email if you end up using it for something interesting and/or have any questions.
This script isn't all that useful without some kind of cron job that runs it periodically. I use the following systemd unit files to activate the job:
hackny-monitor.service
Description=Monitor hackNY.social status
[Service]
ExecStart=/home/steve/.local/bin/bb check
WorkingDirectory=/home/steve/Code/hackny-uptime-monitor
[Install]
WantedBy=default.target
hackny-monitor.timer
[Unit]
Description=Periodically checks hackNY.social's uptime
Requires=hackny-monitor.service
[Timer]
Unit=hackny-monitor.service
OnUnitActiveSec=15m
[Install]
WantedBy=default.target
You can use these as user-level units by placing them in ~/.config/systemd/user
and activating them with:
$ systemd --user start hackny-monitor.timer
$ systemd --user enable hackny-monitor.timer
Just remember to enable lingering so that the timers will run even if you're not logged in to your server:
$ loginctl enable-linger username
This project is released under the MIT License. See LICENSE.txt for more information.