I am following the Prometheus Java client library to expose metrics of my Jetty server. From here . But when I start the server I get the error -
Exception in thread "main" java.lang.RuntimeException: Unable to start jetty server
Caused by: java.lang.IllegalStateException: StatisticsHandler has no Wrapped Handler
To fix this I had to do -
StatisticsHandler stats = new StatisticsHandler();
stats.setServer(server.getServer());
HandlerWrapper hw = new HandlerWrapper();
stats.setHandler(hw);
new JettyStatisticsCollector(stats).register();
contextCollectionHandler.addHandler(stats);
server.setHandler(contextCollectionHandler);
try {
server.start();
}
catch (final Exception e) {
throw new RuntimeException("Unable to start jetty server", e);
}
But, I dont see the stats incrementing, when I make requests to my server through Postman. I get responses, 200, 404 etc. But none of the stats such as jetty_requests_total
or jetty_responses_total
are incrementing. They stay at 0. The only thing that changes is jetty_stats_seconds
. What am I doing wrong ?