Server uptime monitoring using UptimeRobot

Today I’m going to present you a simple script that uses the UptimeRobot APIs; UptimeRobot is an awesome service that, for free, allows you to check the uptime of your servers (max 50) with a check based on a webpage or an open listening port on the server with a minimum delay between the checks of 5 minutes (or higher). It also supports webhooks, basically when one of your server goes offline UptimeRobot makes a call to url. I use this feature to send an SMS to my telephone using a paid SMS Gateway (unsupported by UptimeRobot). For more infomation visit their website: UptimeRobot.com

Anyway, I created this script to present some statistics on the servers monitored such as the uptime in the last days, the response time during the last 24 hours and more important than everything else the current status of the server (Online or not).

The script is configurable, you can:

  • select which server to add: UptimeRobots supports two types of API keys, a private one that allows access to all the monitors inside your account and a public key that allows access to the statistics of a specific monitor; it’s up to you to choose which key to use, but keep in mind that you can’t add the same monitor two times;
  • choose if you want to see the response time of the last 24 hours and how precisely you want to see it, take in mind that by enabling this feature the loading time of the page will be higher (no problems with 4-5 monitors); the precision is indicated in minutes, for example 30 minutes mean that in the graph there will be the response time every 30 minutes, I prefer 120 minutes to avoid spikes in the graph;
  • regarding the uptime statistics, select the period used to calculate the uptime ratio, by default is last day, last week and last month: 1, 7 and 30 days; you can add other values such as ‘1-7-30-60′.

You can see the script in action here Status page. As you can see the script is fully responsive, if it works in every browser at every resolution 😛
I left some comments in the script so you should be able to customize it (like I did to add the munin graphs and Laura Bodewig, the anime girl in the background).

Now to the download links, remember to edit the config file. Feel free to contact me if anything goes wrong.

I also used these awesome libraries:

    • Dennis
    • 08/22. 2014 6:46pm

    This is great! Thanks a lot.

    • Andy
    • 04/04. 2015 10:48am

    Not working for me unfortunately.
    It does render a white page with a header stating “UptimeRobot stats” also all columns are present but no actual data is published. My web server is running PHP 5 on Apache and the API key has been added properly to the config file.

      • croma25td
      • 06/03. 2015 9:50am

      Sorry for the late response, do you solved the problem? The error log says something?

  1. Where download link?

    • gregor
    • 06/15. 2015 10:07am

    Hi! Looks great, but where can i download the script? Thank you!

    • Alexander
    • 07/08. 2015 5:07am

    Hey. Im currently using you script for my website but i fail to add more than 7 monitors to the site. I inputed the api keys as they are supposed to but the eight one isn’t showing :/

      • croma25td
      • 08/11. 2015 11:52pm

      Hi, sorry for the late response. Can you give to me more details about the key (it’s the account key or the monitor key)? Are there any error logs? I just added 10 keys (for the same monitors) and I see every entry.

    • Erwin Quek
    • 08/08. 2015 12:46pm

    Thanks for the great work.

    “regarding the uptime statistics, select the period used to calculate the uptime ratio, by default is last day, last week and last month: 1, 7 and 30 days”

    In Uptime, it is reflecting 24h, 7h and 30h. Any idea why?

      • croma25td
      • 08/12. 2015 12:00am

      In the config try to use these values (in days): ‘customUptimeRatio’ => ‘1-7-30′
      In my setup I see the right values (as showed in the uptimerobot.com dashboard) and I don’t see updates in the APIs.
      Let me know if it works and if not it’ll be useful to have your config file (without the keys obviously)

  2. Hi,

    This script is very well put together and just what I am looking for. However, I have 2 questions. I am receiving the error “Warning: Invalid argument supplied for foreach() in /var/sites/p/pvmon.uk/public_html/status2/index.php on line 46″ even though the script is working fine and showing all of my monitors. Why is this happening? I can’t find a fix for it.

    My second question, how easy would it be to modify the script to show only the first two columns, and display only the monitor and response time without the graphs? I use two instances of my uptime scripts, one runs in a narrow column on a large wall mounted screen and simply needs to show “Online” or “Offline” – the response is a bonus! 😉

    I’m not a coder by any stretch of the imagination and all attempts at API coding have failed.

    Many thanks in advance,

    Bret

    • *UPDATE*
      Oops, schoolboy error! I’ve now removed the ‘another_one’ from the apiKey line in config.php and the error has gone so I’ve only got one question.

        • croma25td
        • 12/02. 2015 9:18pm

        Hi, I’m sorry for the late response. If you still need this you can just remove the first < td > and the < script > tag. This way the page should automatically became a two coloumn like you need :)

    • Eduardo
    • 11/22. 2015 9:31pm

    Hello,
    Thanks for the work.
    I’m trying to use it but I got this,

    Warning: Invalid argument supplied for foreach() in /home/xxxxx/public_html/Otromonitor/index.php on line 46

    Ideas ?

      • croma25td
      • 12/02. 2015 9:23pm

      Hi, I’m sorry for the late response. If you still need help it seems that you didn’t configured any monitors in the config file (line 17 the api keys that need to be activated and then retrieved from the UptimeRobot’s console). You can check the json response by adding the correct variabiles in the url variabile at line 36-37. If you still have problems you can contact me directly via email because I’m usually faster to respond that way

    • Carlos
    • 12/02. 2015 6:14pm

    Thank you very much for the contribution. How do I add munin graphs? How is a example code? Thanks.

      • croma25td
      • 12/02. 2015 9:25pm

      Hi, to add the munin graphs you only need to find the static image that is generated by munin on the webserver and add it inside an < img src="path_to_image" >. Or you can check the source of my page: view-source:http://status.croma25td.com/
      I hope it helps, if you have any questions feel free to send me an email

    • Tmn
    • 12/11. 2015 6:48am

    Thanks for the contribution. Sometimes the graph didn’t showing and the 7 days and 30 days showing 7h and 30h.

      • croma25td
      • 12/23. 2015 1:56pm

      Sorry for the late response, the problem of graph not showing up may be due to temporary problems with APIs. As for the other problem, in the code I pass in GET this variable to their APIs customUptimeRatio=”.$configs[‘customUptimeRatio’] and the documentation states (https://uptimerobot.com/api) that
      customUptimeRatio - optional (defines the number of days to calculate the uptime ratio(s) for. Ex: customUptimeRatio=7-30-45 to get the uptime ratios for those periods))
      Can you provide more info (for example a screenshot) so I can check myself and eventually try to contact their support? Thanks

  1. No trackbacks yet.

return top