~vesto/hackny-uptime-monitor

A Clojure/Babashka script for monitoring hackny.social's uptime
update readme with systemd unit files
properly handle bad status codes

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~vesto/hackny-uptime-monitor
read/write
git@git.sr.ht:~vesto/hackny-uptime-monitor

You can also use your local clone with git send-email.

#hackNY uptime monitor

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:

  1. Requests the homepage of hackny.social and checks the HTTP status code.
  2. Records the status code to a SQLite3 database.
  3. If the status code is 200, do nothing.
  4. If the status code is not 200, check to see when the last notification was sent and, if it was greater than an hour ago, ping my phone via PushOver to let me know something is awry.

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.

#Systemd unit files

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

#License

This project is released under the MIT License. See LICENSE.txt for more information.