This question is related to the one I ask here.
I'm trying to log the number of active requests being made to my Dropwizard application every 10 minutes. The idea is to track usage of the app so it can get the proper support. In doing this, I'm trying to expose the dropwizard metrics to the logs. For testing purposes, I've made the following code:
@GET
@Path("/metrics")
public MetricRegistry provideMetrics() {
MetricRegistry metrics = new MetricRegistry();
metrics.register("io.dropwizard.jetty.MutableServletContextHandler.active-dispatches", new Counter());
logger.info("Total Requests: {}",
metrics.counter("io.dropwizard.jetty.MutableServletContextHandler.active-requests"));
logger.info("Active Requests: {}",
metrics.counter("io.dropwizard.jetty.MutableServletContextHandler.active-dispatches"));
logger.info("Suspended Requests: {}",
metrics.counter("io.dropwizard.jetty.MutableServletContextHandler.active-suspended"));
return metrics;
}
In theory, when I run the following GET request, the number of active requests and dispatched requests should be equal to 1:
@GET
@Path("all")
public List<String> getAll() {
List<String> list = dao.getAllExamples();
TimeUnit.SECONDS.sleep(10);
return list;
}
However, the output from the metics path I made remains at 0. I've checked the metrics at the Dropwizard admin port on 8081, and it shows:
counters: {
io.dropwizard.jetty.MutableServletContextHandler.active-dispatches: {
count: 1
},
io.dropwizard.jetty.MutableServletContextHandler.active-requests: {
count: 1
},
io.dropwizard.jetty.MutableServletContextHandler.active-suspended: {
count: 0
},
}