<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>4.1.16</version>
</dependency>
yaml
metrics:
reporters:
- type: console
frequency: 1 minute
Counter counter = new Counter();
counter.inc();
Histogram histogram = new Histogram(new ExponentiallyDecayingReservoir());
histogram.update(100);
Timer timer = new Timer();
try (Timer.Context context = timer.time()) {
}
MetricRegistry registry = new MetricRegistry();
registry.register("myCounter", counter);
registry.register("myHistogram", histogram);
registry.register("myTimer", timer);
ConsoleReporter reporter = ConsoleReporter.forRegistry(registry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build();
reporter.start(1, TimeUnit.MINUTES);