Best way to return data from a webappliacation servlet

18 views
Skip to first unread message

De Clamps

unread,
Feb 11, 2022, 6:39:10 PM2/11/22
to Prometheus Users
Im trying to create a metrics endpoint as part of my web application using the Java_client project https://github.com/prometheus/client_java as a proof of concept.
I have the hibernatestatisticscollector created and been used in other sessions. 
I want an endpoint that I can query these metrics in another session.
I am accessing the registry and getting results like so

CollectorRegistry collector = CollectorRegistry.defaultRegistry;
Enumeration<Collector.MetricFamilySamples> metricSample = collector.metricFamilySamples();
StringBuilder sb =new StringBuilder();
for (Enumeration<Collector.MetricFamilySamples> e = metricSample; e.hasMoreElements();){
sb.append(e.nextElement());
}
return sb.toString();

This seems to me to be a bit of a hack. 

 CollectorRegistry.defaultRegistry; can contain many registries, but these objects dont give me a public way to find a registry by the name I use to create it.

Also, I dont like the loop I need to pass each line to a string builder, is there some way I can just dump the contents to a return type, like a string?

Im pretty sure Im doing something wrong here, but I'm finding the examples a little confusing so any help will be appreciated.
Reply all
Reply to author
Forward
0 new messages