Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Uptime Kuma - Configure Push Monitor

Introduction

I recently had an issue with a background job no longer being run by Supervisor. I realized that I needed a way monitor that it was still running, ideally with the least amount of effort possible due to my extreme laziness. Since this is a background job, and not a RESTful web service, my normal HTTPS Uptime Kuma monitors would not suffice. Luckily, Uptime Kuma supports "passive" push monitors, which is ideal for this use-case. This tutorial will show you how to set one up.

Steps

Log into your Uptime Kuma service and click Add New Monitor.


Click on Monitor Type and select Push from the dropdown. It is the only one within the Passive Monitor Type at the time of writing this.


  1. Set the name for the service to identify it by when you get an alert.
  2. Copy this URL for your code (you will need this later).
  3. Set a heartbeat interfal. If your service does not "check in" within this time period of its last "check in", then Uptime Kuma will assume the service is down and send you an alert. The minimum is 20 seconds and since my service runs once every 3 seconds, I set this as my interval.
  4. Set the number of retry a limit and the retry interval. This will give a "grace period" for if your service missed a "check in" or two for whatever reason (such as a reboot of the server etc).
  5. Specify which notifications to send out when the service is down.
  6. Save.


To test this works, copy the URL from part (2) in the previous step, and go there in your browser. You should see the following response, and this will have counted as a "check in" with Uptime Kuma.

Code Implementation

Finally, you need to add some piece of logic to your code that can make a GET request to the URL.

PHP

For PHP this could be as simple/basic as a call to file_get_contents. Alternatively you may wish to do this asynchronously to prevent waiting around and blocking your logic in the event of your Uptime Kuma server becomes unreachable. To do this, you can make use of curl_multi_exec for which I have a package to make life easier. There is also the symfony/http-client package that I believe will do the job, but I have not tried yet.

Python

For Python codebases, I believe the easiest way is to do the following:

import requests
r = requests.get("http://uptimekuma.mydomain.com/api/push/xyz")

Conclusion

That's it! You will now get a notification any time that your service fails to "check in", suggesting that it is no longer working, and that your IT administrator needs to go investgiate what has happened.

References

Last updated: 2nd April 2024
First published: 2nd April 2024

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch