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: CONTRIBUTING.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,15 +13,17 @@ Prometheus uses GitHub to manage reviews of pull requests.
13
13
14
14
## Formatting
15
15
16
-
This repository uses [Google Java Format](https://github.com/google/google-java-format) to format the code.
16
+
This repository uses [Google Java Format](https://github.com/google/google-java-format) to format
17
+
the code.
17
18
18
19
Run `./mvnw spotless:apply` to format the code (only changed files) before committing.
19
20
20
21
## Running Tests
21
22
22
23
If you're getting errors when running tests:
23
24
24
-
- Make sure that the IDE uses only the "Maven Shade" dependency of "prometheus-metrics-exposition-formats" and the "prometheus-metrics-tracer\*" dependencies.
25
+
- Make sure that the IDE uses only the "Maven Shade" dependency of "
26
+
prometheus-metrics-exposition-formats" and the "prometheus-metrics-tracer\*" dependencies.
25
27
26
28
### Avoid failures while running tests
27
29
@@ -30,7 +32,8 @@ If you're getting errors when running tests:
30
32
- Use `-Dcheckstyle.skip=true` to skip the checkstyle check during development.
31
33
- Use `-Dwarnings=-nowarn` to skip the warnings during development.
32
34
33
-
Combine all with `./mvnw test -DskipTests=true -Dspotless.check.skip=true -Dcoverage.skip=true -Dcheckstyle.skip=true -Dwarnings=-nowarn`.
35
+
Combine all with
36
+
`./mvnw test -DskipTests=true -Dspotless.check.skip=true -Dcoverage.skip=true -Dcheckstyle.skip=true -Dwarnings=-nowarn`.
Copy file name to clipboardExpand all lines: README.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,13 +8,17 @@
8
8
9
9
# Contributing and community
10
10
11
-
See [CONTRIBUTING.md](CONTRIBUTING.md) and the [community section](http://prometheus.io/community/) of the Prometheus homepage.
11
+
See [CONTRIBUTING.md](CONTRIBUTING.md) and the [community section](http://prometheus.io/community/)
12
+
of the Prometheus homepage.
12
13
13
-
The Prometheus Java community is present on the [CNCF Slack](https://cloud-native.slack.com) on `#prometheus-java`, and we have a fortnightly community call in the [Prometheus public calendar](https://prometheus.io/community/).
14
+
The Prometheus Java community is present on the [CNCF Slack](https://cloud-native.slack.com) on
15
+
`#prometheus-java`, and we have a fortnightly community call in
16
+
the [Prometheus public calendar](https://prometheus.io/community/).
14
17
15
18
# Previous Releases
16
19
17
-
The source code for 0.16.0 and older is on the [simpleclient](https://github.com/prometheus/client_java/tree/simpleclient) branch.
20
+
The source code for 0.16.0 and older is on
21
+
the [simpleclient](https://github.com/prometheus/client_java/tree/simpleclient) branch.
Copy file name to clipboardExpand all lines: docs/content/exporters/httpserver.md
+12-7Lines changed: 12 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,29 +4,34 @@ weight: 3
4
4
---
5
5
6
6
The `HTTPServer` is a standalone server for exposing a metric endpoint. A minimal example
7
-
application for `HTTPServer` can be found in the [examples](https://github.com/prometheus/client_java/tree/1.0.x/examples) directory.
7
+
application for `HTTPServer` can be found in
8
+
the [examples](https://github.com/prometheus/client_java/tree/1.0.x/examples) directory.
8
9
9
10
```java
10
11
HTTPServer server =HTTPServer.builder()
11
-
.port(9400)
12
-
.buildAndStart();
12
+
.port(9400)
13
+
.buildAndStart();
13
14
```
14
15
15
16
By default, `HTTPServer` binds to any IP address, you can change this with
16
-
[hostname()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#hostname(java.lang.String)>) or [inetAddress()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#inetAddress(java.net.InetAddress)>).
or [inetAddress()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#inetAddress(java.net.InetAddress)>).
17
19
18
20
`HTTPServer` is configured with three endpoints:
19
21
20
22
-`/metrics` for Prometheus scraping.
21
23
-`/-/healthy` for simple health checks.
22
24
-`/` the default handler is a static HTML page.
23
25
24
-
The default handler can be changed with [defaultHandler()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#defaultHandler(com.sun.net.httpserver.HttpHandler)>).
26
+
The default handler can be changed
27
+
with [defaultHandler()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#defaultHandler(com.sun.net.httpserver.HttpHandler)>).
25
28
26
29
## Authentication and HTTPS
27
30
28
-
-[authenticator()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#authenticator(com.sun.net.httpserver.Authenticator)>) is for configuring authentication.
29
-
-[httpsConfigurator()](</client_java/api/io/prometheus/metrics/exporter/httpserver/HTTPServer.Builder.html#httpsConfigurator(com.sun.net.httpserver.HttpsConfigurator)>) is for configuring HTTPS.
Copy file name to clipboardExpand all lines: docs/content/exporters/spring.md
+27-23Lines changed: 27 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,8 @@ weight: 5
5
5
6
6
## Alternative: Use Spring's Built-in Metrics Library
7
7
8
-
[Spring Boot](https://spring.io/projects/spring-boot) has a built-in metric library named [Micrometer](https://micrometer.io/), which supports Prometheus
8
+
[Spring Boot](https://spring.io/projects/spring-boot) has a built-in metric library named
9
+
[Micrometer](https://micrometer.io/), which supports Prometheus
9
10
exposition format and can be set up in three simple steps:
10
11
11
12
1. Add the `org.springframework.boot:spring-boot-starter-actuator` dependency.
@@ -25,7 +26,8 @@ Spring anyway. Maybe you want full support for all Prometheus metric types,
25
26
or you want to use the new Prometheus native histograms.
26
27
27
28
The easiest way to use the Prometheus metrics library in Spring is to configure the
28
-
[PrometheusMetricsServlet](/client_java/api/io/prometheus/metrics/exporter/servlet/jakarta/PrometheusMetricsServlet.html) to expose metrics.
The important part are the last three lines: They configure the
77
-
[PrometheusMetricsServlet](/client_java/api/io/prometheus/metrics/exporter/servlet/jakarta/PrometheusMetricsServlet.html) to expose metrics on `/metrics`:
Copy file name to clipboardExpand all lines: docs/content/migration/simpleclient.md
+61-26Lines changed: 61 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,14 +3,21 @@ title: Simpleclient
3
3
weight: 1
4
4
---
5
5
6
-
The Prometheus Java client library 1.0.0 is a complete rewrite of the underlying data model, and is not backwards compatible with releases 0.16.0 and older for a variety of reasons:
6
+
The Prometheus Java client library 1.0.0 is a complete rewrite of the underlying data model, and is not backwards
7
+
compatible with releases 0.16.0 and older for a variety of reasons:
7
8
8
-
- The old data model was based on [OpenMetrics](https://openmetrics.io). Native histograms don't fit with the OpenMetrics model because they don't follow the "every sample has exactly one double value" paradigm. It was a lot cleaner to implement a dedicated `prometheus-metrics-model` than trying to fit native histograms into the existing OpenMetrics-based model.
9
-
- Version 0.16.0 and older has multiple Maven modules sharing the same Java package name. This is not supported by the Java module system. To support users of Java modules, we renamed all packages and made sure no package is reused across multiple Maven modules.
9
+
- The old data model was based on [OpenMetrics](https://openmetrics.io). Native histograms don't fit with the
10
+
OpenMetrics model because they don't follow the "every sample has exactly one double value" paradigm. It was a lot
11
+
cleaner to implement a dedicated `prometheus-metrics-model` than trying to fit native histograms into the existing
12
+
OpenMetrics-based model.
13
+
- Version 0.16.0 and older has multiple Maven modules sharing the same Java package name. This is not supported by the
14
+
Java module system. To support users of Java modules, we renamed all packages and made sure no package is reused
15
+
across multiple Maven modules.
10
16
11
17
## Migration using the Simpleclient Bridge
12
18
13
-
Good news: Users of version 0.16.0 and older do not need to refactor all their instrumentation code to get started with 1.0.0.
19
+
Good news: Users of version 0.16.0 and older do not need to refactor all their instrumentation code to get started with
20
+
1.0.0.
14
21
15
22
We provide a migration module for bridging the old simpleclient `CollectorRegistry` to the new `PrometheusRegistry`.
This will make all metrics registered with simpleclient's `CollectorRegistry.defaultRegistry` available in the new `PrometheusRegistry.defaultRegistry`.
56
+
This will make all metrics registered with simpleclient's `CollectorRegistry.defaultRegistry` available in the new
57
+
`PrometheusRegistry.defaultRegistry`.
47
58
48
59
If you are using custom registries, you can specify them like this:
As long as you are using high-level metric API like `Counter`, `Gauge`, `Histogram`, and `Summary` converting code to the new API is relatively straightforward. You will need to adapt the package name and apply some minor changes like using `builder()` instead of `build()` or using `labelValues()` instead of `labels()`.
87
+
As long as you are using high-level metric API like `Counter`, `Gauge`, `Histogram`, and `Summary` converting code to
88
+
the new API is relatively straightforward. You will need to adapt the package name and apply some minor changes like
89
+
using `builder()` instead of `build()` or using `labelValues()` instead of `labels()`.
71
90
72
91
Example of the old 0.16.0 API:
73
92
74
93
```java
75
94
importio.prometheus.client.Counter;
76
95
77
96
Counter counter =Counter.build()
78
-
.name("test")
79
-
.help("test counter")
80
-
.labelNames("path")
81
-
.register();
97
+
.name("test")
98
+
.help("test counter")
99
+
.labelNames("path")
100
+
.register();
82
101
83
-
counter.labels("/hello-world").inc();
102
+
counter.
103
+
104
+
labels("/hello-world").
105
+
106
+
inc();
84
107
```
85
108
86
109
Example of the new 1.0.0 API:
@@ -89,17 +112,27 @@ Example of the new 1.0.0 API:
89
112
importio.prometheus.metrics.core.metrics.Counter;
90
113
91
114
Counter counter =Counter.builder()
92
-
.name("test")
93
-
.help("test counter")
94
-
.labelNames("path")
95
-
.register();
115
+
.name("test")
116
+
.help("test counter")
117
+
.labelNames("path")
118
+
.register();
119
+
120
+
counter.
96
121
97
-
counter.labelValues("/hello-world").inc();
122
+
labelValues("/hello-world").
123
+
124
+
inc();
98
125
```
99
126
100
-
Reasons why we changed the API: Changing the package names was a necessity because the previous package names were incompatible with the Java module system. However, renaming packages requires changing code anyway, so we decided to clean up some things. For example, the name `builder()` for a builder method is very common in the Java ecosystem, it's used in Spring, Lombok, and so on. So naming the method `builder()` makes the Prometheus library more aligned with the broader Java ecosystem.
127
+
Reasons why we changed the API: Changing the package names was a necessity because the previous package names were
128
+
incompatible with the Java module system. However, renaming packages requires changing code anyway, so we decided to
129
+
clean up some things. For example, the name `builder()` for a builder method is very common in the Java ecosystem, it's
130
+
used in Spring, Lombok, and so on. So naming the method `builder()` makes the Prometheus library more aligned with the
131
+
broader Java ecosystem.
101
132
102
-
If you are using the low level `Collector` API directly, you should have a look at the new callback metric types, see [/getting-started/callbacks/](../../getting-started/callbacks/). Chances are good that the new callback metrics have an easier way to achieve what you need than the old 0.16.0 code.
133
+
If you are using the low level `Collector` API directly, you should have a look at the new callback metric types,
134
+
see [/getting-started/callbacks/](../../getting-started/callbacks/). Chances are good that the new callback metrics have
135
+
an easier way to achieve what you need than the old 0.16.0 code.
103
136
104
137
## JVM Metrics
105
138
@@ -113,7 +146,9 @@ With version 1.0.0 these metrics moved to the `prometheus-metrics-instrumentatio
113
146
are initialized as follows:
114
147
115
148
```java
116
-
JvmMetrics.builder().register();
149
+
JvmMetrics.builder().
150
+
151
+
register();
117
152
```
118
153
119
154
A full list of the available JVM metrics can be found
0 commit comments