final Counter counter = Repository.INSTANCE.getCounter(new Counter.Key(Role.PERFORMANCES, "my counter")); final StopWatch stopWatch = Repository.INSTANCE.start(counter); // do something stopwatch.stop();
public class MyRandomGauge implements Gauge {
public static final Role MY_RANDOM_ROLE = new Role("Random", Unit.UNARY);
@Override
public Role role() {
return MY_RANDOM_ROLE;
}
@Override
public double value() {
return new Random(System.currentTimeMillis()).nextDouble();
}
@Override
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).
Gauges values are retrieved by interval:
Map<Long, Double> sortedValueByIncreasingDate = Repository.INSTANCE.getGaugeValues(start, end, gaugeRole);
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).