Write your own gauge

simply implement a org.apache.commons.monitoring.gauges.Gauge and register it using ServiceLoader mecanism (META-INF/services/org.apache.commons.monitoring.gauges.Gauge)

implement a org.apache.commons.monitoring.gauges.GaugeFactory which is registered it using ServiceLoader mecanism (META-INF/services/org.apache.commons.monitoring.gauges.GaugeFactory) and return the gauges you want to register

What is GaugeFactory designed for? Imagine a custom gauge is parameterized. You’ll surely want to register it several times with different parameters. If you use Gauge SPI you’ll need to do N implementations (which makes the parameters useless). With GaugeFactory you just need to return the built instances:

A plugin has basically a name (what will identify it in the webapp and in the GUI - it will be the name of the plugin tab), a mapping, ie which base subcontext it will use for its own pages (for instance /jmx, /myplugin …) and a class representing endpoints.

To make it more concrete we’ll use a sample (the standard Hello World).

The first home method uses a template. The GUI relies on velocity and html templates needs to be in the classloader in templates directory.

So basically the home method will search for templates/hello/home.vm velocity template. It is only the “main” part of the GUI (the tabs are automatically added). Twitter bootstrap (2.3.2) and JQuery are available.

Here is a sample:

<h1>Hello</h1>
<div>
Welcome to $name
</div>

If you need resources put them in the classloader too in “resources” folder.

Note: if you want to do links in the template you can use $mapping variable as base context of your link. For instance: >a href=“$mapping/foo”<Foo>/a<.