Monitoring Raspberry Pi using my DigitalOcean VPS

Published: by

  • Categories:

So, this is a simple one and just felt like sharing in case someone wants to save time writing those one-liners.

I had a faulty raspberry pi power supply and my Rpi used to hang unexpectedly. Here is what I did to monitor uptime of my Rpi.

  • Host a simple text file via nginx on my DigitalOcean VPS.
➜ $?=0 /home/shadyabhi [ 1:20PM] % cat /var/www/html/rpihealth

>>>  0s elasped...
➜ $?=0 /home/shadyabhi [ 1:20PM] %
  • Write a simple systemd service in Rpi to curl this file.
➜ $?=0 /home/shadyabhi [ 5:21PM] % sudo cat /usr/lib/systemd/system/send_latest_ip.service
Description=Latest IP sender



>>>  0s elasped...
➜ $?=0 /home/shadyabhi [ 5:21PM] % cat /usr/local/bin/

while [ 1 ]; do
		sleep 1

>>>  0s elasped...
➜ $?=0 /home/shadyabhi [ 5:21PM] % sudo systemctl enable send_uptime
  • A sample logline for a health checks looks like this. - - [06/Sep/2016:13:37:46 -0400] "GET /rpihealth HTTP/1.1" 200 5 "-" "curl/7.50.0" "-"
  • A cronjob on my VPS to send me notifications via pushover if there are no log lines for this health check in the last 10 seconds. (using
* * * * * sudo /usr/bin/perl -MDate::Parse -ne 'print if/^.*- - \[(.*?)\] .*?/&&str2time($1)>time-10' /var/log/nginx/access.log | if ! /bin/grep -q "/rpihealth"; then /home/shadyabhi/ -t "RPi Health" "Rpi is down"; fi

Now, whenever my Rpi is down, I get push notifications on my phone.