Ears and eyes

A JMX dashboard with ICanHaz, Jolokia and HAML

“You got no eyes, you got no ears, you got nothing but assumptions!”

The Negotiator, 1998

On the plus side, a lot of Java-based software has been instrumented using JMX. On the con side, it's easily so much that it becomes impossible to navigate. Because of the sheer number of MBeans, attributes and operations, it becomes really hard to find the things you need; it's probably tucked away somewhere, but since it's burried deep under loads of stuff you don't need, it's impossible to locate it quickly.

That's when you build your own dashboard, displaying just the things you really want to display. The other week, I played a little with different approaches to put something together quickly. It turns out creating a web dashboard can actually be done with just a couple of lines, so I figured I'd share it here.

  • Jolokia — It assumes the target system has Jolokia bundled. Jolokia is a HTTP-JMX bridge, that exposes all MBeans as restful(ish) resources.

  • ICanHaz — ICanHaz is a marvelous JavaScript library that allows you include mustache template snippets inside script tags, and then bind the variables inside these templates to data you pass in with just a single line of code.

  • HAML — A lot of people seem to hate XML-based markup languages. I'm not one of them. But I am totally in love with HAML and Jade. It's just so much better than HTML, especially as a template language: it's way more compact, and much easier to parse for humans.

So, behold, the JMX console, currently displaying heap attributes only:

    %title JMX Console
    %script(src="js/ICanHaz.min.js" language="javascript")
    %script(src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" language="javascript")
    %script(src="js/json2.js" language="javascript")
    %script(src="js/jolokia-min.js" language="javascript")
    %script(src="js/jolokia-simple-min.js" language="javascript")
    %link(href="css/style.css" rel="stylesheet" type="text/css")
      $(document).ready(function() {
        var j4p = new Jolokia({url: "http://tungsten.fritz.box:8778/jolokia/", method:"get", jsonp:true});
          { type: "read", mbean: "java.lang:type=Memory", attribute: "HeapMemoryUsage" },
            success: function(response) {
              var data = ich.heap(response.value);
    %script(id="heap" type="text/html")
        %li {{used}}
        %li {{committed}}
        %li {{max}}

In my case, I used Monkeyman to turn HAML into HTML, but I'm pretty sure it will work just as well if you use the haml gem.