Server Uptime

October 25th, 2007

This Chumby widget will check your linux web server every 30 seconds and display the server uptime as well as the average load for the past minute, 5 minutes, and 15 minutes. If the widget can’t reach your server, the screen will turn red and an alarm will sound.

After you load this widget into your Chumby, you must do three things to get it to work:

  1. Create a PHP file for the Widget to talk to.
  2. Put a crossdomain.xml file on your server.
  3. Configure the Widget on the Chumby website.

PHP File
A small php file must be created and posted on your website (this is the file that the widget will get the server uptime from).

Here’s the code:

<?php
if($_REQUEST[’pass’]==”pass”){
$uptime = explode(” “, @exec(”cat /proc/uptime”));
echo “uptime=”.(int)$uptime[0];
$load = explode(” “, @exec(”cat /proc/loadavg”));
echo “&load0=”.$load[0].”&load1=”.$load[1].”&load2=”.$load[2].”&”;
}
?>

Drop that code into a file (I called mine uptime.php) and place it on your server.

Cross-domain XML File
In order for Flash to access data from a server, a crossdomain.xml file must exist on the top level of your website and must be setup properly. You can read more about it here. Below is the contents of my file which is also available at http://www.ryanc.com/crossdomain.xml

<?xml version=”1.0″?>
<!DOCTYPE cross-domain-policy SYSTEM “http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd”>
<cross-domain-policy>
<allow-access-from domain=”*” />
</cross-domain-policy>

Configure the Widget
When you configure this widget on the Chumby website, enter the full URL to the php file. You’ll also need to enter a password. By default, the password is “pass”, but you can change this on the 2nd line of the php code.

A few notes about this widget…

  • If it can’t read the php file, the screen will turn red and an alarm will sound :) You should test this at least once by temporarily renaming or removing your php file.
  • The widget checks your server every 30 seconds, but you can press anywhere on your Chumby’s screen to force a refresh.
  • This widget is in beta and probably will stay that way. Please do not rely solely on this widget to monitor your server. I’m not responsible for any incorrect or inaccurate messages on this widget.

I’d appreciate your comments & suggestions..

-Ryan