Server Uptime

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

25 Responses to “Server Uptime”

  1. Mike says:

    I manage a number of websites. I’d like to be able to display a name or custom message on each screen so I can tell which server is being described. Should be easy to add another parameter, no?

  2. arkasha says:

    love the plugin!
    two things that might make it stronger (it’s already awesome, don’t get me wrong):

    1.) let the script publish server name/some random nickname as a parameter (i have a lot of projects, would like to add one for each)
    2.) allow “turning off” the alarm when the server is down (an “ok, stop playing the klaxon” button)

    thanks for the neat plugin

  3. RyanC says:

    Thanks for the feedback! I’ll add a nickname in the next version.

  4. Vineus says:

    I have issues with your plugin …

    I can access my uptime.php file from my webbrowser without no problem, I have the crossdomain.xml file on the root of my serveur (with a reading access to it) and I have configured the widget on chumby.com

    When I load the widget from my chumby, it show a blue screen with “Loading” in the middle and a little antenna icon blinking on the top right corner.

    My chumby is well connected to the internet (ie: other widgets access their remote data).
    I tried to remove the password checking to see if it was not a php configuration issue (like “do not allow shell commands”) but I see the result well in my regular browser.

    Any other things I should check ?

    Thank you !

  5. Vineus says:

    Forgot my previous message, I’m stupid :-) I copy / paste your code which use non ASCII characters for brackets so when I pasted it into my term I lost them (replaced by ‘?’ character) and I screwed up on my :%s/?/’/g

    my mistake, works great, thank you !

  6. My widget is not working. I’ve used the following code:

    When I run it from the internet I get: uptime=6635412load0=0.75&load1=0.59&load2=0.53&

    But when the widget runs it displays
    NaN
    NaN
    NaN
    Average Load blank 0.36 0.45

    Where do I start?
    Thanks!

  7. RyanC says:

    Hi Kathleen.. It looks like you’re missing the & before the load0=… So, check your PHP script — it should have a & before the load0.

  8. John Gray says:

    I’d like to report my worst case scenario. (the server with the high load). I’ve hack the php to give me a poor man’s version of this. Any chnage I could muck the flash to do it right?

  9. Jason says:

    Installed and ran correctly on one server, tried to use it on a second and the only thing it does is show “loading…” and the “antenna” blinks. Any suggestions on how I might get it to work? Maybe it is only one copy of this plugin per chumby?

  10. josh says:

    Howdy,

    Does this widget ping the server from the chumby itself, or from some host on the internet?

    I have a funky setup (server resides behind my residential ADSL), and if I go to http://www.myserver.com, it actually hits my router. I have ‘hosts’ entries in all of my linux boxes pointing to the correct IP address of the server as it exists on my local lan.

    The output from my server, either way, looks like:
    uptime=9688923&load0=0.00&load1=0.00&load2=0.00&

    But, alas, it doesn’t work from the chumby - it gives the red klaxon alarm. I’ve tried both the regular server name as well as the IP address of the server on my lan. How should I debug this?

    Thanks,
    -J

  11. josh says:

    Ok, it looks like it does ping from the Chumby - the widget now works when I enter the local IP address of my server.

  12. John says:

    I *think* this works on my Mac (Leopard, Apache 2).

  13. John says:

    OK, I can’t post PHP here :-)

    Basically, you need to substitute a call to /usr/bin/uptime and then process that string, and do some maths to create an uptime in seconds.

  14. Halim says:

    Hi,

    I cannot get the PHP script to work. The web server logs the following error:
    PHP Parse error: syntax error, unexpected ‘.’, expecting ‘]’ in /var/www/htdocs/uptime.php on line 2, referer: http://www.chumby.com/xml/……etc...

    I’m not familiar with PHP so I do not know where to start. I’m on PHP version 5.2.5.

    Any feedback greatly appreciated!

  15. Le Tartar says:

    I can’t get the php script running. I always get the following error:

    Parse error: syntax error, unexpected T_STRING in /var/www/uptime.php on line 3

    Can you give me any advice what to do ???

    Thanks

  16. RyanC says:

    If you have getting a syntax error, look through your code and compare it to the code on this page. Apparently you can’t copy & paste from this site. If someone knows the correct way to post code in a wordpress blog, please let me know!

  17. Le Tartar says:

    I’v found the error. The “-signs aren’t copied correct.
    You have to replace them in the script and then everything works fine.

  18. Horsey says:

    For those interested, here is the code for Windows servers (2003 server anyway)/
    It shows uptime and CPU% for the 1min option (doesn’t use the 5 and 15 minute variables yet)

    Thanks to these sites for some of the code:
    http://www.xenocafe.com/tutorials/php/r … /index.php
    http://www.jcxp.net/forums/index.php?showtopic=16711
    (Post also on the Chumby site)

  19. Horsey says:

    Ah, no code shows up. Please see this link for the full post:
    http://forum.chumby.com/viewtopic.php?id=832

  20. Raymond Day says:

    Because this will not show the code I uploaded the one that works for me at:

    http://home.comcast.net/~kday160540mi/chumby-uptime/uptime

    So on a Linux box to get it. Go to were your web pages are like:

    cd /var/www
    wget http://home.comcast.net/~kday160540mi/chumby-uptime/uptime
    mv uptime uptime.php

    That will go to that folder, download the uptime.php and rename it to uptime.php. Can’t make it work on the web page if the name is .php.

    I hope this helps others to get it working.

    -Raymond Day

  21. Damien says:

    You’ve made a really neat widget, but there is one small problem that I’ve noticed (unfortunately for me).

    When the php page is unreachable for whatever reason, the widget goes to alarm state: yay.

    It seems when the server is down completely the widget gets stuck in a connect loop and displays what ever was last on screen. Oops.

    Thanks for the neat-o widget though.

  22. kayakbabe says:

    When you do your next version that will allow adding nicknames.. how about also letting us have a paramter for the ping time. I don’t want to poll my server every 30 seconds. that really is too often for me. I’d rather do it every 2 minutes or something like that.

  23. John says:

    Any ASP version of the same code that can spit out the same info as the PHP?

  24. RyanC says:

    I’m not aware of an ASP version… But if someone writes one, post it here!

  25. Horsey says:

    I have amended the windows version of the PHP script for Server 2008.

    Please see this post for the code: http://forum.chumby.com/viewtopic.php?pid=19975#p19975

Leave a Reply