Im trying to create a metrics endpoint as part of my web application using the Java_client project
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.
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.