Do a measure manually using a StopWatch

final Counter counter = Repository.INSTANCE.getCounter(new Counter.Key(Role.PERFORMANCES, "my counter"));
final StopWatch stopWatch = Repository.INSTANCE.start(counter);
// do something

Create a custom Gauge

public class MyRandomGauge implements Gauge {
    public static final Role MY_RANDOM_ROLE = new Role("Random", Unit.UNARY);

    public Role role() {
        return MY_RANDOM_ROLE;

    public double value() {
        return new Random(System.currentTimeMillis()).nextDouble();

    public long period() { // millisecond
        return 4000;

The role identifies the gauge specifying its unit (Unit.UNARY means “value” - absolute, percent…).

The value method is the one called to get the measure.

Period method defines when to do a measure using the gauge (it implicitly defines a a timer).

Get a gauge values

Gauges values are retrieved by interval:

Map<Long, Double> sortedValueByIncreasingDate = Repository.INSTANCE.getGaugeValues(start, end, gaugeRole);

Monitor JDBC

To monitor JDBC just configure your DataSource replacing its java.sql.Driver by org.apache.commons.monitoring.jdbc.MonitoringDriver and updating its jdbc url from jdbc:foo:bar to jdbc:monitoring:foo:bar?delegateDriver=xxxxx.

Note: delegateDriver needs to be the last parameter (if there are several).