Skip to content

Instantly share code, notes, and snippets.

@matzew
Created February 7, 2018 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matzew/4eddb4997de2f0ed0902d29b6608ddb2 to your computer and use it in GitHub Desktop.
Save matzew/4eddb4997de2f0ed0902d29b6608ddb2 to your computer and use it in GitHub Desktop.
@Path("/prometheus")
public class SimplePrometheusEndpoint {
{
// Initialize the default metrics for the hotspot VM
DefaultExports.initialize();
}
@GET
@Path("/metrics")
@Produces(MediaType.TEXT_PLAIN)
public StreamingOutput metrics() {
return output -> {
try (final Writer writer = new OutputStreamWriter(output)) {
TextFormat.write004(writer, CollectorRegistry.defaultRegistry.metricFamilySamples());
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment