You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/implementations/prometheus.adoc
+55-9
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,15 @@
1
1
= Micrometer Prometheus
2
2
:sectnums:
3
-
:system: prometheus
4
3
5
4
Prometheus is a dimensional time series database with a built-in UI, a custom query language, and math operations.
6
5
Prometheus is designed to operate on a pull model, periodically scraping metrics from application instances, based on service discovery.
7
6
7
+
Micrometer uses the Prometheus Java Client under the hood; there are two versions of it and Micrometer supports both. If you want to use the "new" client (`1.x`), use `micrometer-registry-prometheus` but if you want to use the "legacy" client (`0.x`), use `micrometer-registry-prometheus-simpleclient`.
8
+
9
+
:system: prometheus
10
+
include::_install.adoc[]
11
+
12
+
:system: prometheus-simpleclient
8
13
include::_install.adoc[]
9
14
10
15
== Configuring
@@ -31,13 +36,25 @@ try {
31
36
});
32
37
33
38
new Thread(server::start).start();
34
-
} catch (IOException e) {
39
+
}
40
+
catch (IOException e) {
35
41
throw new RuntimeException(e);
36
42
}
37
43
----
38
44
<1> The `PrometheusMeterRegistry` has a `scrape()` function that knows how to supply the String data necessary for the scrape. All you have to do is wire it to an endpoint.
39
45
40
-
You can alternatively use `io.prometheus.client.exporter.HTTPServer`, which you can find in `io.prometheus:simpleclient_httpserver`:
46
+
If you use the "new" client (`micrometer-registry-prometheus`), you can alternatively use `io.prometheus.metrics.exporter.httpserver.HTTPServer`, which you can find in `io.prometheus:prometheus-metrics-exporter-httpserver`:
47
+
48
+
[source,java]
49
+
----
50
+
PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
If you use the "legacy" client (`micrometer-registry-prometheus-simpleclient`), you can alternatively use `io.prometheus.client.exporter.HTTPServer`, which you can find in `io.prometheus:simpleclient_httpserver`:
41
58
42
59
[source,java]
43
60
----
@@ -46,12 +63,20 @@ PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(Prometh
46
63
new HTTPServer(new InetSocketAddress(8080), prometheusRegistry.getPrometheusRegistry(), true);
47
64
----
48
65
49
-
Another alternative can be `io.prometheus.client.exporter.MetricsServlet`, which you can find in `io.prometheus:simpleclient_servlet` in case your app is running in a servlet container (such as Tomcat):
66
+
If you use the "new" client (`micrometer-registry-prometheus`), another alternative can be `io.prometheus.metrics.exporter.servlet.jakarta.PrometheusMetricsServlet`, which you can find in `io.prometheus:prometheus-metrics-exporter-servlet-jakarta` in case your app is running in a servlet container (such as Tomcat):
67
+
68
+
[source,java]
69
+
----
70
+
PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
71
+
HttpServlet servlet = new PrometheusMetricsServlet(prometheusRegistry.getPrometheusRegistry());
72
+
----
73
+
74
+
If you use the "legacy" client (`micrometer-registry-prometheus-simpleclient`), another alternative can be `io.prometheus.client.exporter.MetricsServlet`, which you can find in `io.prometheus:simpleclient_servlet` in case your app is running in a servlet container (such as Tomcat):
50
75
51
76
[source,java]
52
77
----
53
78
PrometheusMeterRegistry prometheusRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
54
-
HttpServlet metricsServlet = new MetricsServlet(prometheusRegistry.getPrometheusRegistry());
79
+
HttpServlet servlet = new MetricsServlet(prometheusRegistry.getPrometheusRegistry());
55
80
----
56
81
57
82
=== Scrape Format
@@ -60,7 +85,14 @@ By default, the `PrometheusMeterRegistry` `scrape()` method returns the https://
60
85
61
86
The https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md[OpenMetrics] format can also be produced.
62
87
To specify the format to be returned, you can pass a content type to the `scrape` method.
63
-
For example, to get the OpenMetrics 1.0.0 format scrape, you could use the Prometheus Java client constant for it, as follows:
88
+
For example, to get the OpenMetrics 1.0.0 format scrape, you could use the Prometheus Java client constant for it, as follows in case of the "new" client (`micrometer-registry-prometheus`):
Exemplars are metadata that you can attach to the value of your time series. They can reference data outside of your metrics. A common use case is storing tracing information (`traceId`, `spanId`). Exemplars are not tags/dimensions (labels in Prometheus terminology), they will not increase cardinality since they belong to the values of the time series.
212
+
Exemplars are metadata that you can attach to the value of your time series. They can reference reference data outside of your metrics. A common use case is storing tracing information (`traceId`, `spanId`). Exemplars are not tags/dimensions (labels in Prometheus terminology), they will not increase cardinality since they belong to the values of the time series.
213
+
214
+
In order to setup Exemplars for `PrometheusMeterRegistry`, you will need a component that provides you the tracing information. If you use the "new" client (`micrometer-registry-prometheus`), this component is the `io.prometheus.metrics.tracer.common.SpanContext` while if you use the "legacy" client (`micrometer-registry-prometheus-simpleclient`), it is the `SpanContextSupplier`.
181
215
182
-
In order to setup Exemplars for `PrometheusMeterRegistry`, you will need a component that provides you the tracing information: `SpanContextSupplier`.
216
+
Setting them up are somewhat similar, if you use the "new" client (`micrometer-registry-prometheus`):
217
+
[source,java]
218
+
----
219
+
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(
0 commit comments