whatmon: Mozilla Extension for Monitoring Whatever

Update: July 27th, 2009

whatmon
I spend a good part of any day in my favorite web browser, and even if I don't see its whole window, the lower right part of the status bar is always visible under a pile of other application windows (mostly SSH sessions). That status bar is the ideal place to put up a small monitor with which I can keep an eye on a number of important servers, without having to wait for alerts sent to me by Nagios.

To this effect I have created a tiny Firefox and Thunderbird extension called whatmon, which can monitor almost anything you wish to monitor. Number of logged on users? Current load average? Health of your LDAP servers? Mail server queues? No problem for whatmon, as long as you can create a CGI(Common Gateway Interface) program in Perl, C, or any other language you are comfortable with, or even a PHP or Active-Whatever script which runs on your web server and can produce a wee bit o' XML(eXtensible Markup Language). There is one thing that whatmon can't watch: the web server from which it retrieves that XML … :-)

whatmon periodically reads a short bit of XML text from a web server (in my case: Apache). The XML contains an integer status and a single line of text. In practice, that line of text can contain whatever the administrator desires. I want an indication of the health of the mail queues on a number of mail servers we have inhouse. The line of text therefore contains two-letter codes with which I can identify the hostname of the mail server in question as well as a count of mails on the queue for each of the servers in question.

The program that produces that line of text also returns a numeric integer indicating okay, warning or critical so that the extension can colour-code the status bar accordingly. A sample XML read by the extension.

<whatmon>
  <code>0</code>
  <text>nprocs: 111</text>
</whatmon>

Download this code: whatmon/whatmon-simple.xml

I've tried to keep this as simple as possible so as to not overcomplicate the extension proper (and because creating Mozilla extensions is about the worst I've ever had to do :-) ). Each of the labels and values on the status bar could have been individually described in the extension, but then it would require modification whenever something changes. I didn't want that to happen.

The extension requires two preferences to be set. I've named these whatmon.url and whatmon.refresh. They are the URL from which the XML is to be read and the frequency in seconds in which the extension should do a GET request from the URL.

Both preferences are installed as defaults when whatmon is first installed, but you'll want to change these to reasonable values, using the configuration editor in Firefox or Thunderbird. To call up the preference settings in Firefox, go to the URL about:config. In Thunderbird choose Tools => Options => Advanced => General => Config Editor. The preferences for whatmon should then resemble this:

Preferences

After restarting Firefox or Thunderbird, whatmon will then periodically perform a GET request on the URL set in the whatmon.url preference.

Sample

The actual monitoring program is part of your web server, and it can be written in any language supported by it. It must return a tiny bit of XML text specifying both a status code and a string that whatmon will print to the status bar of Firefox or Thunderbird.

This simple example is a shell script which displays the number of currently running processes on the server.

#!/bin/sh

nprocs=`ps ax|wc -l | awk '{print $1}'`
text="nprocs: $nprocs"
code=0          # normal

if [ $nprocs -gt 115 ]; then
        code=1  # warning
fi
if [ $nprocs -gt 120 ]; then
        code=2  # critical
fi

cat <<ENDXML
Content-type: text/xml

<whatmon>
  <code>${code}</code>
  <text>${text}</text>
</whatmon>
ENDXML

Download this code: whatmon/simple.sh

Stocks

Another more involved example is shown below. It uses whatmon as a front-end to Yahoo!'s stock symbol lookup.

<?php
        # whatmon-stock.php by Jan-Piet Mens <jpmens at gmail dot com>
        # Simple stock watcher for whatmon (http://fupps.com/extensions/).
        # The URL to this will be specified as
        # http://www.example.com/stock.php?s=SYMB where SYMB is the stock symbol
        # as listed by Yahoo!'s site.

        header("Content-type: text/xml");
        $symbol = $_GET['s'];

        if (!isset($symbol)) {
                $symbol = 'GOOG';
        }

        $url = "http://quote.yahoo.com/d/quotes.csv?f=sl1d1t1c1ohgv&e=.csv&s=";

        print "<whatmon>";
        if ($fp = @fopen($url . "$symbol", "r")) {
                # "GOOG",401.32,"10/3/2006","1:16pm",-0.12,401.29,402.97,398.19,2729528
                $list = fgetcsv($fp, 256);

                # Note that you could add an alerting (code=1 or code=2) in case
                # a stock is lower or higher than you desire...

                print "<code>0</code><text>${list[0]}: ${list[1]}</text>";
                fclose($fp);
        } else {
                print "<code>2</code><text>Can't get stock</text>";
        }
        print "</whatmon>";
?>
 

Download this code: whatmon/whatmon-stock.php

Note the comments.

Detailed Alerting

Heiko Weber sent in a very useful patch to whatmon. If the XML received by whatmon contains an element named msgurl, whatmon will launch a new browser window to open the URL.

<whatmon>
  <code>2</code>
  <text>nprocs: 231</text>
  <msgurl>http://example.com/detailed-info.cgi</msgurl>
  <xhover>Tooltip text</xhover>
</whatmon>
 

Download this code: whatmon/whatmon-msgurl.xml

When whatmon sees a msgurl element in the XML, it will open a new browser window pointing to the specified URL. Note that this URL can of course differ from code to code: simply ensure your CGI produces a different URL.

Changelog

09-Aug-2006 1.6.0
incorporates heiko weber's patch for alert windows
27-Sep-2006 2.0.0
incorporates ian stirling: patch to support file:// URLs, support for Firefox 2.0 RC1, defaults are set upon installation, changed logo
27-Sep-2006 2.0.1
reverted to original GUID, minor code cleanups
30-Sep-2006 2.0.2
added preference observer; If no XML data returned by CGI, the issue diagnostic on status bar
15-Oct-2006 2.0.3
As per suggestion by Petr, a click on whatmon's status bar forces an immediate refresh
07-Mar-2007 2.0.4
Differing icons depending on level (suggested by "Frangi")
21-Nov-2007 2.0.5
  • install.rdf: support for Thunderbird 2.0 (LewS)
  • install.rdf: support for Firefox 3.0 (JPM)
  • click on whatmon does not add a new timer (Scott Carpenter)
  • whatmon.css: max-width: auto (Scott Carpenter)
04-Dec-2007 2.0.6
  • Hover over whatmon status bar shows content of XML's `xhover' element (suggested by Jeremy Vanderb)
19-Apr-2008 3.0.0
  • Show whatmon status as "Loading…" (w/ tooltip containing time) when XMLHTTP request is launched; allows user to detect unresponsive servers. [idea and code by "bitbyte"]
  • Many thanks to Sebastian A. who had excellent ideas, most of which had unfortunately already been implemented. :-)
21-Apr-2008 3.0.1
  • Forgot to try/catch xhover element from XML; this results in whatmon printing "Loading…" and nothing else. Update to 3.0.1 or add non-empty xhover element to XML. Bug spotted by Scott Crevier.
18-Jun-2008 3.0.4
  • Options dialog provided by Gábor Lipták (thanks!)
  • Bumped to official Firefox 3.0
26-Jul-2009 3.1.0
  • Bumped to official Firefox 3.5.*

Download

Download whatmon from the Mozilla Add-ons site, or grab a local copy.

Improve?

Can this be improved on? You bet! Firefox and/or Thunderbird need restarting whenever the URL preference changes. A nice options dialog with which the extension's preferences can be set would be welcome. Instead of plain text on the labels, I'd have liked to display images generated by the web server which change as the status changes. Any takers?

  1. Aidan
    October 3rd, 2006 at 18:03
    Reply | Quote | #1

    In the monitor panel in Firefox I get a small yellow question mark before the text. What is this?

  2. October 3rd, 2006 at 19:21
    Reply | Quote | #2

    The small yellow question mark means you are using a version lower than 2.0 (please upgrade: download link above). If there is no text behind that small logo, the output of your monitoring program hasn't produced correct XML that whatmon recognizes. Do remember to add a Content-type: text/xml if you are producing the XML with a CGI or PHP or some such script.

  3. October 13th, 2006 at 10:44
    Reply | Quote | #3

    It would be nice, if e.g. doubleclick on whatmon info on toolbar would execute instant re-load of the information.

  4. David
    November 5th, 2006 at 00:46
    Reply | Quote | #4

    Hello and thanks for whatmon!

    I am setting up a little server inside Thunderbird to respond to whatmon requests so that Firefox can show an indicator for new mail (like Mozilla used to do).

    Initially, I had my server write a file to disk and whatmon found/processed it fine.

    Now I have changed my server to accept socket connections and I point whatmon at localhost (or 127.0.0.1). However whatmon reports no XML data.

    I can point Firefox at this server and I get shown the appropriate XML text. I have tried running my server on both the standard http port (80) and on a port of my choosing (25501, for example). In both cases, Firefox gets a response but whatmon does not.

    Is there some issue with whatmon accessing localhost for its XML?

    Thanks for any pointer/tips.

  5. David
    November 5th, 2006 at 01:17
    Reply | Quote | #5

    Please ignore my previous question. I was not providing a complete and correctly formatted http response. From the look of the simple shell script example, it did not appear that this was required. Nor is it required if reading a local file. But now that I have modified my server to give a complete http response, whatmon is working fine on my localhost. I am not sure if additional documentation is warranted here or not. Thanks.

  6. November 5th, 2006 at 10:57
    Reply | Quote | #6

    @David, the examples provided above are all run by an HTTP server, so that of course provides the required headers. Thank you for your comments though, and I'll keep that in mind.

  7. Frangi
    March 7th, 2007 at 16:38
    Reply | Quote | #7

    What a wondeful extension ! Light and useful !
    It would be more efficient, if the image color changes with status. Maybe you can simply add 2 PNG images (one yellow and one red) and set them up in your process-request function :

    if (code == 2) {
    fld.style.color = '#FF0000'; // Red
    fld.style.listStyleImage = 'url("chrome://whatmon/skin/whatmon16red.png")'
    }

    It would be also more efficient if the shapes are different (i.e. triangle for the yellow PNG, square or hexagon for the red one).
    Thanks.
    Good job.

  8. March 8th, 2007 at 12:01
    Reply | Quote | #8

    @Frangi: thanks for your comments. I've implemented your idea in 2.0.4, so go ahead! ;-)

  9. April 30th, 2007 at 12:38
    Reply | Quote | #9

    First, this is a wonderful idea.

    Second, it would be nice to have control over the display color–against the dark background I use, it is almost illegible.

    Third, is there a way to run multiple instances, to monitor different xml sources? If not, that might make a nice upgrade.

    Again, well done.

  10. April 30th, 2007 at 14:26

    @Eric: some good points you make; I'll keep them in mind.

  11. LewS
    July 19th, 2007 at 17:38

    Love this extension!

    I had it working great with TB 1.5 (used it to show how many sales today from our website), but it stopped working when I upgraded to TB 2.0.

    I just uninstalled the previous version, downloaded the latest local copy from here and tried to install it — got "whatmon 2.0.4 could not be installed because it is not compatible with Thunderbird 2.0.0.4. (whatmon 2.0.4 will only work with Thunderbird versions from 1.5 to 1.5.0.*)"

    Is there a later version that does work with the latest TB version?

    LewS

  12. LewS
    July 19th, 2007 at 18:09

    Update: I started peeking inside files and found that the 'maxVersion' for Firefox was:

    2.0.0.*

    but for Thunderbird was:

    1.5.0.*

    So, I modified the install.rdf to change the Thunderbird one to:

    2.0.0.*

    Thunderbird happily installed it, I restarted TB and voila! It appears to work okay…

    Was this just an oversight in the install.rdf file, or am I taking a risk here by running it (perhaps untested) in TB 2.0.0.4 ?

    LewS

  13. July 30th, 2007 at 10:49

    This was an oversight: it should work as you've described. Thanks for that: I'll fix it for a next version. Pleased you like it.

  14. Fred
    August 7th, 2007 at 22:11

    Hello !

    Very nice tool.

    I monitor a server with whatmon 2.0.4 on firefox 2.0.0.6.
    When my webserver goes overloaded (it is so slow that it cannot serve the whatmon xml file), the extension stays green.

    Is it a bug of a feature ?

    Regards

  15. August 8th, 2007 at 10:28

    @Fred that is a good question. I would imagine that the XMLHTTP request times out, but I'll have to look at the code. Since that is difficult to test, I'll have a go at it for the next version.

  16. September 26th, 2007 at 13:53

    Hi,

    I just discovered this lovely little extension and i built a small backend (in php) to fetch e-mails from a pop3 account and serve it to whatmon.

    I have two versions:
    - one will fetch the last one and print "$from: $subj ($number_of_emails)". request this php script: http://phpfi.com/265197
    - the other one needs a small hack to support multipart responses. just add in jar:http://fupps.com/code/whatmon/whatmon-ff-tb-latest.xpi!/chrome/whatmon/content/whatmon/whatmon.js (you can edit the file $YOUR_USER_DIR\Mozilla\Firefox\Profiles\……\extensions\{bc5e7c90-f53d-11da-974d-0800200c9a66}\chrome\whatmon\content\whatmon)
    the line "request.multipart = true;" right after "request = new XMLHttpRequest();" and request this script: http://phpfi.com/265205

    Just enter your POP3 HOST, PORT, USER and PASS in the php script and md5 hash the php filename you request and have it as whatmon.url in your Firefox prefs.

    Have fun, i have it :)

    Regards
    e-voc

  17. September 26th, 2007 at 14:02

    @Uwe, very sweet!

  18. November 20th, 2007 at 18:22

    First off, this addon is wonderful! I use this to monitor all kinds of things =)

    I had to make one small change that I think should come standard – in the whatmon.css file (I believe that's the one) I changed the max-width to "auto" so that the width of the statusbar panel would auto-adjust. If your output is a little too long, it trims the end off by default.

    I noticed one thing that could potentially be a problem – if you click on the panel to force a reload of the content, ANOTHER update timer starts, rather than restarting the current time. In other words, if you have your refresh time set to 60 seconds, and you click the panel a few times in order to refresh it, it will refresh every 60 seconds from EACH click. I noticed this in my webserver log files – I had clicked a few times while I was programming the output script, and suddenly I was getting 10-15 hits to the output script within a 60 second span, rather than one every 60 seconds.

    Thanks!

  19. November 21st, 2007 at 13:41

    @Scott, thanks for the bit on the timer; I hadn't noticed. I've fixed that for the next version and hope to have that out as soon as possible.

    I can't say I notice a difference with max-width: auto; in whatmon.css; I'm happy to leave it in if it helps you, though.

  20. January 13th, 2008 at 01:54

    this is indeed very useful, and I already programmed a small PHP-script. However it would be great to be able to monitor more than one server.

  21. January 13th, 2008 at 11:13

    @Bernd, pleased you like it. Whatmon cannot, at this point, access more than one URL. It would be a nice addition to whatmon, and I'll gladly accept patches! ;-)

    A quick and dirty workaround is to have the one URL from which you gather data from other servers. I use whatmon to monitor five mail servers and a Blackberry enterprise server. The six machines "feed" their data to a central store from which my whatmon retrieves a single XML.

    That might help you.

  22. bitbyte
    February 21st, 2008 at 16:08

    #15/#16: When the XMLHTTP request times out, whatmon does not update and continues to show the old . This was not ideal for my needs since I was unable to tell if the server serving the whatmon XML was offline. To address this, I replaced the text with "Loading…" whenever whatmon is fetching new data. Should there be a timeout, it does not get updated and simply continues to show "Loading…". I also wanted to know when the data shown was last updated and added a time to the tooltip; while it was possible to add a time into on the server side, I didn't want it showing as I wanted the displayed to be shorter rather than longer.

    function load_xml(url)
    {
    var bar = document.getElementById('whatmon');
    bar.setAttribute('label', 'Loading…');
    bar.setAttribute('tooltiptext', 'whatmon @ ' + time() + ' – ' + url + ' (' + (update_interval / 1000) + 's)');

    function time() {
    var d = new Date();
    var hour = d.getHours();
    var minute = d.getMinutes();
    var second = d.getSeconds();
    var t = ((hour

  23. April 17th, 2008 at 14:52

    Love whatmon! Works great in Thunderbird v2.0.0.12. Wondering two things.

    First, will you make it work in Firefox v2.0.0.13 and now the newly released version?

    Second, I like the comments by "bitbyte" on 21-Feb. Will you implement both of those as well? They seem simple yet quite useful.

    (I know I can go in and change my own version, but I'm hoping to see this stuff in the official release.)

    Thanks Jan-Piet!

  24. April 17th, 2008 at 15:53

    @Scott, thanks. Whatmon works fine with 2.0.0.13 (at least, it does for me).

    As for additions, yes, I will look into the above comments, and I received a huge load of useful patches today, actually. As soon as I have some time, I'll release a new version, and that will be Firefox 3.0 compatible.

  25. April 17th, 2008 at 17:32

    When I look at my list of Firefox Add-ons, the entry for whatmon says "whatmon 2.0.5 Not compatible with Firefox 2.0.0.13."

  26. April 18th, 2008 at 20:23

    Whatmon 3.0.0 released (see Notes above). Thanks to all so far for ideas and code snippets!

  27. April 18th, 2008 at 20:44

    Scott, where do you see that? Both on Windows and Mac, when I choose Tools->Add-ons, I see whatmon 2.0.5 or higher and no such message….

    BTW, I've just released 3.0.0, so you may want to try that instead. You can download it on this page, above.

  28. April 21st, 2008 at 16:37

    Thanks Jan-Piet. I'm running WinXP SP2 with FF 2.0.0.13. That message showed when I selected Tools -> Add-ons.

    I just downloaded and installed v3.0.0 using the "local copy" link above (the other two links go to Mozilla's add-on site which still shows v2.0.5). It installed just fine in both FF v2.0.0.14 and TB v2.0.0.12. No more version issues.

    However, now the status bar just says "Loading…" but nothing else comes up. Each time I click it, I can see in my access log that it hits my CGI script, and full testing shows that my CGI script is putting out the proper code, but the status bar never changes from "Loading…" So, I can click it over and over again, and my CGI script runs each time, but no change to the status bar. This happens in both FF and TB. I've also got another guy here still running whatmon v2.0.5 hitting the exact same script and it's updating the status bar fine for him.

  29. April 21st, 2008 at 19:33

    Sorry Scott, something broke somewhere: please add a (non-empty) element called

    
    hello
    
    

    to the XML your CGI outputs; that should fix it. Its content shows up as a tooltip when you hover over the whatmon status area. I've also just uploaded 3.0.1

    Does that work for you?

  30. April 21st, 2008 at 20:07

    Yep, I added the element to the XML code and now it's updating just fine. That element will actually be quite handy, as I can use it to provide additional data that supplements what shows in the status bar.

    Thanks again. This add-on is quite useful!

  31. April 21st, 2008 at 20:20

    Any idea how to indicate that hover text be on multiple lines? I've tried inserting various characters (LF, CR) with no luck.

  32. April 21st, 2008 at 20:27

    No, I've never tried that. If you do find out, I'd be interested.

  33. June 17th, 2008 at 21:48

    Any plans for Firefox 3 support?

  34. June 18th, 2008 at 09:27

    @Royce: yes, of course. Support for Firefox 3.0 is now available. Download the local copy (above), or wait a bit until the storm on the Mozilla addons site has settled, and they publish the new 3.0.4 version of whatmon.

  35. Radius Kuntoro
    June 27th, 2008 at 01:44

    Very nice extension. I haven't done any XUL development before. Is it possible to insert HTML into the hover tooltip?

  36. June 27th, 2008 at 08:54

    @Radius, I don't really know, as I use plain text only. If you do manage to do so, come back and tell us how you solved it.

  37. August 15th, 2008 at 08:45

    Thanks for this great Addon!
    Now I´m gonna be the first one to realize when the MySQL-Database is down again : )

  38. February 14th, 2009 at 01:12

    Hi Jan-Piet,

    awesome plugin. I readout some one wire temperatures around the house.

    One Think would be very nice to have is to read out several xml files. So I can feed the temperature xml and a separate xml file for my internet usage.

    Best Regards

    Stefan

  39. Jaimi Passos
    May 14th, 2009 at 18:07

    HI,,,
    this is very usefull plugin.
    CONGRATULATIONS and build continuous play,,, tks

  40. Fritz Grossmugler
    July 10th, 2009 at 22:18

    Hi !
    I find this plugin very useful, but cannot use it anymore since my Firefox is Version 3.5 now.
    Any plans to make this plugin working again with 3.5 ?

  41. July 20th, 2009 at 15:52

    @Fritz: I'll be working on the upgrade shortly. Hope to have it complete within two weeks.

  42. July 27th, 2009 at 17:29

    New version works with Firefox 3.5. Download it above, or wait a bit until the Mozilla Add-ons site has it for you.

  43. ted williams
    August 14th, 2009 at 03:09

    please tell me how to delete fupps / whatmon. It may be a great program but the pop-up and clock are extremely annoying to my family. If I cant get rid of this we'll have to switch back to Internet Explorer from Mozilla. Ted

  44. August 14th, 2009 at 09:31

    Whatmon has to be customized to your application; installing it without doing so is useless. ;-)
    Simply remove the add-on from Firefox' add-on manager.

  45. ted williams
    August 15th, 2009 at 04:05

    That was too easy. Thank you very kindly Jan

  46. Mike
    February 6th, 2010 at 08:44

    When I installed it, the default refresh was 60000, which made sense since if you click the options button in the extension list, the box that comes up says the number should be in mS. This should probably be updated to indicate the number should be in seconds, not mS. I was wondering why the display was not refreshing so I changed it to 5 and sure enough, it updated every 5 seconds. With a default of 60000, thats once every 41 hours…

    Great extension BTW. Use it to monitor my server load.

  47. Mike
    February 8th, 2010 at 17:09

    Anyone try it with FF 3.6? It installs, but when I go to add ons->whatmon->options, the add on window becomes unresponsive (beeps when you clicks) like there is a modal window open but cant see it. Also nothing in the status bar.

  48. February 9th, 2010 at 11:15

    @Mike thanks for your comments. I know about the millisecond setting — It'll be fixed next time I change the add-on. As to the unresponsiveness of the options window, I'm not able to reproduce that. If you really cannot get it going, there's a workaround: open about:config in the URL bar and search for "whatmon" — you'll be able to change settings directly there.

TOP