whatmon: Mozilla Extension for Monitoring Whatever

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 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. 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.
<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:

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

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.
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.
# 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.
<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
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?
Aidan wrote on 03-Oct-06 at 6:03 pm
In the monitor panel in Firefox I get a small yellow question mark before the text. What is this?
Jan-Piet Mens wrote on 03-Oct-06 at 7:21 pm
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.
Jan-Piet Mens / Why is my BES 404? wrote on 12-Oct-06 at 8:47 am
[...] Got a little worried, when whatmon showed this on my status bar this morning: [...]
Petr wrote on 13-Oct-06 at 10:44 am
It would be nice, if e.g. doubleclick on whatmon info on toolbar would execute instant re-load of the information.
David wrote on 05-Nov-06 at 12:46 am
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.
David wrote on 05-Nov-06 at 1:17 am
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.
Jan-Piet Mens wrote on 05-Nov-06 at 10:57 am
@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.
Frangi wrote on 07-Mar-07 at 4:38 pm
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.
Jan-Piet Mens wrote on 08-Mar-07 at 12:01 pm
@Frangi: thanks for your comments. I've implemented your idea in 2.0.4, so go ahead!
Eric Walker wrote on 30-Apr-07 at 12:38 pm
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.
Jan-Piet Mens wrote on 30-Apr-07 at 2:26 pm
@Eric: some good points you make; I'll keep them in mind.
LewS wrote on 19-Jul-07 at 5:38 pm
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
LewS wrote on 19-Jul-07 at 6:09 pm
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
Jan-Piet Mens wrote on 30-Jul-07 at 10:49 am
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.
Fred wrote on 07-Aug-07 at 10:11 pm
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
Jan-Piet Mens wrote on 08-Aug-07 at 10:28 am
@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.
Uwe Pries wrote on 26-Sep-07 at 1:53 pm
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_DIRMozillaFirefoxProfiles…...extensions{bc5e7c90-f53d-11da-974d-0800200c9a66}chromewhatmoncontentwhatmon)
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
Jan-Piet Mens wrote on 26-Sep-07 at 2:02 pm
@Uwe, very sweet!
Scott Carpenter wrote on 20-Nov-07 at 6:22 pm
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!
Jan-Piet Mens wrote on 21-Nov-07 at 1:41 pm
@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.
Bernd Glasstetter wrote on 13-Jan-08 at 1:54 am
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.
Jan-Piet Mens wrote on 13-Jan-08 at 11:13 am
@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.
bitbyte wrote on 21-Feb-08 at 4:08 pm
#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
Scott Crevier wrote on 17-Apr-08 at 2:52 pm
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!
Jan-Piet Mens wrote on 17-Apr-08 at 3:53 pm
@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.
Scott Crevier wrote on 17-Apr-08 at 5:32 pm
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."
Jan-Piet Mens wrote on 18-Apr-08 at 8:23 pm
Whatmon 3.0.0 released (see Notes above). Thanks to all so far for ideas and code snippets!
Jan-Piet Mens wrote on 18-Apr-08 at 8:44 pm
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.
Scott Crevier wrote on 21-Apr-08 at 4:37 pm
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.
Jan-Piet Mens wrote on 21-Apr-08 at 7:33 pm
Sorry Scott, something broke somewhere: please add a (non-empty) element called
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?
Scott Crevier wrote on 21-Apr-08 at 8:07 pm
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!
Scott Crevier wrote on 21-Apr-08 at 8:20 pm
Any idea how to indicate that hover text be on multiple lines? I've tried inserting various characters (LF, CR) with no luck.
Jan-Piet Mens wrote on 21-Apr-08 at 8:27 pm
No, I've never tried that. If you do find out, I'd be interested.
Royce Williams wrote on 17-Jun-08 at 9:48 pm
Any plans for Firefox 3 support?
Jan-Piet Mens wrote on 18-Jun-08 at 9:27 am
@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.
Radius Kuntoro wrote on 27-Jun-08 at 1:44 am
Very nice extension. I haven't done any XUL development before. Is it possible to insert HTML into the hover tooltip?
Jan-Piet Mens wrote on 27-Jun-08 at 8:54 am
@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.
whatmon monitorea lo que quieras | Zona Firefox wrote on 12-Jul-08 at 1:05 am
[...] whatmon es un monitor versátil que puedes usar para estar al tanto de diversos comportamientos de tu servidor, como cantidad de usuarios logueados, promedio de carga y otras. Puedes determinar la frecuencia de su actualización en segundos. Para funcionar debes usar la extensión en combinación con scripts escritos en Perl, C, PHP u otro lenguaje y que puedas ejecutar en tu servidor. whatmon te mostrará los datos que esté monitoreando en un espacio de la barra de estado. [...]
Andreas Barth wrote on 15-Aug-08 at 8:45 am
Thanks for this great Addon!
Now I´m gonna be the first one to realize when the MySQL-Database is down again : )