Reputation: 11991
I got a simple java web application running on Tomcat which I would like to monitor using Prometheus. I added some counters and gauges to my java app using the official client, I installed Prometheus on another server and not would like to pull the metrics from my java app using Prometheus.
Prometheus got tons of exporters but I'm not clear about which one fits my use case. I considered using Prometheus push gateway but according to the documentation the only valid use case for the Pushgateway is for capturing the outcome of a service-level batch job, which is not my case. What should I do in order to pull the metrics from my java app?
Upvotes: 4
Views: 5454
Reputation: 11991
In order to register MetricsServlet:
If you are using spring-boot register a bean to represent the end-point:
@Bean
ServletRegistrationBean registerPrometheusExporterServlet(CollectorRegistry metricRegistry) {
ServletRegistrationBean srb = new ServletRegistrationBean();
srb.setServlet(new MetricsServlet(metricRegistry));
srb.setUrlMappings(Arrays.asList("/prometheus"));
return srb;
}
In case of a non-spring app add the servlet in web.xml:
<servlet>
<servlet-name>metrics</servlet-name>
<servlet-class>io.prometheus.client.exporter.MetricsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>metrics</servlet-name>
<url-pattern>/metrics/</url-pattern>
</servlet-mapping>
Upvotes: 7
Reputation: 34112
You should have your application expose the metrics over HTTP. You probably want to hook the servlet into your existing webserver.
Upvotes: 3