CLOSEX

Monitor and Share your Web Application Status Using StatusPage.io and Uptime Robot

We recently made a status page available for multiple OPSWAT products, to provide our users with visibility to the availability of the related services for our web applications. We wanted to share a little bit about this status page and show others a straightforward method for building a public status page to monitor critical metrics such like uptime. The specific technology we used is mentioned throughout the article, but there are other services that provide similar functionality.

Resources:

  1. Statuspage.io (https://www.statuspage.io/)
  2. Uptime Robot (https://uptimerobot.com/)
  3. Local web development environment

We leveraged the APIs provided by the first two services:

  1. Uptime Robot (https://uptimerobot.com/api)
  2. Statuspage.io (http://doers.statuspage.io/api/v1/)

We utilized a local web development environment to build an "observer" utility to keep monitoring the uptime of our mission critical web application. Just to note that the "observer" must not be on the same stack as the application to be monitored to prevent misdetection of the down time. Another assumption must be made that the "observer" should have a higher (or at least equal) Service Level Agreement (SLA) for required uptime as compared to your application.

The combination of tools, Uptime Robot and a local web environment, are presented as a no-cost alternative to a paid service like Pingdom.

How it Works:

In this article, we have set up just one metric for uptime, but you can set up additional metrics, depending on the other monitoring services you might be using in your solution. Response time, throughput (requests per minute), and Apdex (application performance index) are common metrics to track and share.

  1. We built simple web pages hosted on our web applications (you can view an example at https://gears.opswat.com/up); this simple web page only prints the keyword "up" which indicates the services are all operational. This is optional but results in a more accurate status indicator.
  2. We set up an Uptime Robot account and created a new monitor using the "Keyword" option. We pointed the URL to https://gears.opswat.com/up and set the keyword text as "up". If step 1 is skipped, step 2 must be done with an ICMP echo (traditional TCP ping), and is therefore less informative than a keyword check. This is because a server may be up and running (and thus respond to an ICMP ping request), but at the same time not be rendering pages properly and therefore be essentially down for a user. Alternatively, a keyword can be selected on an existing page if that content is unlikely to ever change.
  3. At this stage, Uptime Robot is fully functional and able to monitor the uptime for our application.
  4. In order to share this data publicly, we wrote a PHP script that uses the API of Uptime Robot to fetch the uptime value and convert the data to fit the scale of percentage. Then we submitted all data points to the status page we built on Statuspage.io, via its API.

Sample Script: 

<?php /*Note: You'll need the ID of the monitor. For that, simply go to "http://api.uptimerobot.com/getMonitors?apiKey=yourApiKey" and get the ID of the monitor to be queried.*/ /*And, this code requires PHP 5+ or PHP 4 with SimpleXML enabled.*/ $apiKey = /*replace with your apiKey on Uptime Robot*/; $monitorID = /*replace with your monitorID on Uptime Robot */; $url = "http://api.uptimerobot.com/getMonitors?apiKey=" . $apiKey . "&monitors=" . $monitorID . "&format=xml"; $c = curl_init($url); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $responseXML = curl_exec($c); curl_close($c); /*XML Parsing - Start*/ $xml = simplexml_load_string($responseXML); // Set the default value to be up $uptime = 2; // You might handle this differently if you have more than one montiors foreach($xml->monitor as $monitor) { $uptime = $monitor['status']; } /*XML Parsing - End*/ if ($uptime == 0 || $uptime == 1) { // skip on cases where monitor is actually not in service } else { // Uptime Robot value is not what we want to display if ($uptime == 2) // Up { // Convert to 100 for max percentage score $uptime = 100; } elseif ($uptime == 9) // Down { // Alert, do something, your app is down! $uptime = 0; } elseif ($uptime == 8) // seems Down { // We set as 50 but you can treat it as Up or Down $uptime = 50; } // The following code segments will submit Uptime Robot data points to your status page set up on StatusPage.io $API_KEY = /*replace with your apiKey on StatusPage.io*/; $PAGE_ID = /*replace with your page ID on StatusPage.io*/; $METRIC_ID = /*replace with your Metric ID on StatusPage.io*/; $BASE_URI = 'https://api.statuspage.io/v1'; $ch = curl_init(sprintf("%s/pages/%s/metrics/%s/data.json", $BASE_URI, $PAGE_ID, $METRIC_ID)); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: OAuth " . $API_KEY, "Expect: 100-continue" ) ); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $ts = time(); // Get the current time $postparams = array( "data[timestamp]" => $ts, "data[value]" => $uptime ); curl_setopt($ch, CURLOPT_POSTFIELDS, $postparams); curl_exec($ch); } ?>

  1. To keep submitting data, a cron job needs to be created on the "observer" site to run a PHP script so that Statuspage.io can periodically get data points for our web application's uptime.
    Sample code below: 

curl -s <the URL of your observer script or web page>

  1. You now have a status page showing your web application's uptime; enjoy monitoring it!

References:

For more information, please contact one of our critical infrastructure cybersecurity experts.

Sign up for Blog updates
Get information and insight from the leaders in advanced threat prevention.