Jolokia-Cubism Integration

Cubism is a fine Javascript library for plotting timeseries data based on d3.js. It provides support for various backend sources like Graphite or Cube and also for Jolokia. It is easy to use and provides innovative chart types like a horizon chart. The Jolokia integration polls the Jolokia agent periodically and remembers the values locally. It uses the scheduling facility of the Jolokia Javascript library by sending a single bulk request for fetching the data for all charts and is hence very efficient.

The following sections show some simple real time demos of this integration. After that, some concepts are explained. The full Javascript source can be downloaded here.


The following demo directly queries Jolokia's CI which is a plain Tomcat 7. The memory charts show the heap memory usage as a fraction of the maximum available heap. Note that different colors indicate different value ranges in this horizon chart. The activity of the two garbage collectors for the young and old generation are shown below. Feel free to trigger a garbage collection on your own by pressing the button and look how the chart is changing.

Requests (per 10 seconds)

The second demo visualizes the number of requests served by this Tomcat instance. The requests are grouped by 10s, so the values are the number of requests received in the last 10 seconds. The green charts show the requests for the Jolokia agent and the Jenkins CI server. Since this demo queries the Jolokia agent every second, the first chart should show up at least 10 request per 10 seconds. Finally the number of requests served by all deployed servlets is drawn in blue.


Plotting the result of a single Jolokia request is simple and follows the general pattern used by Cubism. You first create a Jolokia source from the Cubism context and create metrics from this source. When a metric is created, it registers one or more Jolokia request for the Jolokia scheduler

  // Create a top-level Cubism Context
  var context = cubism.context();
  // Create a source for Jolokia metrics pointing to the agent 
  // at ''
  var jolokia = context.jolokia("");

  // Create a metric for the absolute Heap memory usage
  var memoryAbs = jolokia.metric({
                      type: 'read', 
                      mbean: 'java.lang:type=Memory',
                      attribute: 'HeapMemoryUsage',
                      path: 'used'
                  },"HeapMemory Usage");
   // Use d3 to attach the metrics with a specific graph type 
   // ('horizon' in this case) to the document"#charts").call(function(div) {

The following example present an advanced concept if more flexibility is required. When the first argument to jolokia.metric() is a function, this function is feed periodically with Jolokia response objects resulting from the requests object given as second argument. The final argument can be an options object, which in this case indicates the label of the chart and the type to be a delta chart, measuring only the increase rate for ten seconds.

This sample also shows how to use wildcard patterns in a read request to fetch multiple values at once in a generic fashion. Wildcard reading is explained in detail in the reference manual.

  var allRequestsMetric = jolokia.metric(
    function (resp) {
        var attrs = resp.value;
        var sum = 0;
        for (var key in attrs) {
            sum += attrs[key].requestCount;
        return sum;
       type: "read", 
       mbean: "Catalina:j2eeType=Servlet,*",
       attribute: "requestCount"
       name: "All Requests", 
       delta: 10 * 1000