client_java
client_java copied to clipboard
Spring Boot 2.x example missing
Hi,
I have an existing Spring Boot 2.7.14 application where metrics are collected with Dropwizard.
I don't plan to migrate to MicroMeter in the short term so I cannot use io.micrometer:micrometer-registry-prometheus to enable the Spring provided Prometheus endpoint.
So I've been trying to use:
io.prometheus:simpleclient_dropwizard:0.16.0io.prometheus:simpleclient_spring_boot:0.16.0
it looks like simpleclient_spring_boot is not compatible with Spring boot 2 because it relies on class PublicMetrics that has been deprecated in Spring Boot 2.
Am I looking at the wrong place? Is it possible to enable the Prometheus Endpoint with Spring Boot 2 in other ways?
Thanks
Hi,
Yes, it is possible to enable the Prometheus endpoint with Spring Boot 2. I think the easiest way is to use the Prometheus MetricsServlet (or PrometheusMetricsServlet in 1.0.x) and register it with your Spring application, something like this:
@Bean
public ServletRegistrationBean createPrometheusServlet() {
return new ServletRegistrationBean(new MetricsServlet(),"/metrics/*");
}
We are currently working on the preview version of the 1.0.0 releases, so you have two options which MetricsServlet to use:
This is the current release with io.prometheus.client.servlet.jakarta.exporter.MetricsServlet.
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet_jakarta</artifactId>
<version>0.16.0</version>
</dependency>
This is the alpha preview of the upcoming 1.0.0 release with io.prometheus.metrics.exporter.servlet.jakarta.PrometheusMetricsServlet:
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>prometheus-metrics-exporter-servlet-jakarta</artifactId>
<version>1.0.0-alpha-2</version>
</dependency>
The source code of the 1.0.0 version is on the 1.0.x branch.
Here's some context of the current status with Prometheus and Micrometer: I think it would be great if Micrometer used the new Prometheus 1.0.0 library directly. I created a PR for that: https://github.com/micrometer-metrics/micrometer/pull/3987. The PR description has links to a modified Spring Boot version and an example application. If the PR gets accepted we would have the following:
- For most users: Micrometer would automatically support new Prometheus features like Prometheus native histograms. This happens under the hood, no code change required.
- For niche users who need to use Prometheus API directly: If you make the Prometheus registry a compile time dependency rather than a runtime dependency you can use the Prometheus api directly.
Anyway, whether this will happen or not depends on what the Micrometer folks think of this. I will eventually add Spring Boot 2 and Spring Boot 3 examples, but I'll wait a couple of weeks to see what's coming out of the PR discussion, because the examples will depend on whether Micrometer will have direct support for Prometheus Metrics 1.0.0 or not.
In case you are wondering: The goal is to have the 1.0.0 release out before PromCon, which will be 28/29 September 2023.
That's amazing! Thanks for sharing @fstab. I'll give it a try immediately