I need to provide custom metrics for a web application. The thing is that I cannot use Spring but I have to use a jax-rs endpoint instead. The requirements are very simple. Imagine you have a map with key value pairs where the key is the metric name and the value is a simple integer which is a counter. The code would be something like this:
public static Map<String, Integer> metrics = Map.of(
"logged_in_users_today", 123
);
@GET
@Path("/metrics/{metricId}")
public Integer getMetric(@PathParam("metricId") String metricId) {
int count = metrics.get(metricId);
return count;
}
But now I need to use some API to publish those metrics. I looked up some tutorials but I could only find Spring based demos that are using micrometer annotations to export metrics. How can I do that in a programmatic way?
/metrics
? – Matthew Darton/metrics
, all the counters, gauges etc are posted to this endpoint and then the server does the necessary aggregations to show you the resulting values of metrics over periods of time – Gaurav Kumar