Skip to content

Commit 6947ba3

Browse files
committed
Add PushGateway docs
Signed-off-by: Fabian Stäber <[email protected]>
1 parent 350be3d commit 6947ba3

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

docs/content/config/config.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,13 @@ Exporter OpenTelemetry Properties
137137
(3) Format: `key1=value1,key2=value2`
138138

139139
Many of these attributes can alternatively be configured via OpenTelemetry environment variables, like `OTEL_EXPORTER_OTLP_ENDPOINT`. The Prometheus metrics library has support for OpenTelemetry environment variables. See Javadoc for details.
140+
141+
Exporter PushGateway Properties
142+
-------------------------------
143+
144+
| Name | Javadoc | Note |
145+
|--------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|------|
146+
| io.prometheus.exporter.pushgateway.address | [PushGateway.Builder.address()](/client_java/api/io/prometheus/metrics/exporter/pushgateway/PushGateway.Builder.html#address(java.lang.String)) | |
147+
| io.prometheus.exporter.pushgateway.scheme | [PushGateway.Builder.scheme()](/client_java/api/io/prometheus/metrics/exporter/pushgateway/PushGateway.Builder.html#scheme(java.lang.String)) | |
148+
| io.prometheus.exporter.pushgateway.job | [PushGateway.Builder.job()](/client_java/api/io/prometheus/metrics/exporter/pushgateway/PushGateway.Builder.html#job(java.lang.String)) | |
149+

docs/content/exporters/pushgateway.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: Pushgateway
3+
weight: 5
4+
---
5+
6+
The [Prometheus Pushgateway](https://github.com/prometheus/pushgateway) exists to allow ephemeral and batch jobs to expose their metrics to Prometheus.
7+
Since these kinds of jobs may not exist long enough to be scraped, they can instead push their metrics to a Pushgateway.
8+
The Pushgateway then exposes these metrics to Prometheus.
9+
10+
The [PushGateway](/client_java/api/io/prometheus/metrics/exporter/pushgateway/PushGateway.html) Java class allows you to push metrics to a Prometheus Pushgateway.
11+
12+
Example
13+
-------
14+
15+
{{< tabs "uniqueid" >}}
16+
{{< tab "Gradle" >}}
17+
```
18+
implementation 'io.prometheus:prometheus-metrics-core:1.3.0'
19+
implementation 'io.prometheus:prometheus-metrics-exporter-pushgateway:1.3.0'
20+
```
21+
{{< /tab >}}
22+
{{< tab "Maven" >}}
23+
```xml
24+
<dependency>
25+
<groupId>io.prometheus</groupId>
26+
<artifactId>prometheus-metrics-core</artifactId>
27+
<version>1.3.0</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>io.prometheus</groupId>
31+
<artifactId>prometheus-metrics-exporter-pushgateway</artifactId>
32+
<version>1.3.0</version>
33+
</dependency>
34+
```
35+
{{< /tab >}}
36+
{{< /tabs >}}
37+
38+
```java
39+
public class ExampleBatchJob {
40+
41+
private static PushGateway pushGateway = PushGateway.builder()
42+
.address("localhost:9091") // not needed as localhost:9091 is the default
43+
.job("example")
44+
.build();
45+
46+
private static Gauge dataProcessedInBytes = Gauge.builder()
47+
.name("data_processed")
48+
.help("data processed in the last batch job run")
49+
.unit(Unit.BYTES)
50+
.register();
51+
52+
public static void main(String[] args) throws Exception {
53+
try {
54+
long bytesProcessed = processData();
55+
dataProcessedInBytes.set(bytesProcessed);
56+
} finally {
57+
pushGateway.push();
58+
}
59+
}
60+
61+
public static long processData() {
62+
// Imagine a batch job here that processes data
63+
// and returns the number of Bytes processed.
64+
return 42;
65+
}
66+
}
67+
```
68+
69+
Basic Auth
70+
----------
71+
72+
The [PushGateway](/client_java/api/io/prometheus/metrics/exporter/pushgateway/PushGateway.html) supports basic authentication.
73+
74+
```java
75+
PushGateway pushGateway = PushGateway.builder()
76+
.job("example")
77+
.basicAuth("my_user", "my_password")
78+
.build();
79+
```
80+
81+
The `PushGatewayTestApp` in `integration-tests/it-pushgateway` has a complete example of this.
82+
83+
SSL
84+
---
85+
86+
The [PushGateway](/client_java/api/io/prometheus/metrics/exporter/pushgateway/PushGateway.html) supports SSL.
87+
88+
```java
89+
PushGateway pushGateway = PushGateway.builder()
90+
.job("example")
91+
.scheme(Scheme.HTTPS)
92+
.build();
93+
```
94+
95+
However, this requires that the JVM can validate the server certificate.
96+
97+
If you want to skip certificate verification, you need to provide your own [HttpConnectionFactory](/client_java/api/io/prometheus/metrics/exporter/pushgateway/HttpConnectionFactory.html).
98+
The `PushGatewayTestApp` in `integration-tests/it-pushgateway` has a complete example of this.
99+
100+
Configuration Properties
101+
------------------------
102+
103+
The [PushGateway](/client_java/api/io/prometheus/metrics/exporter/pushgateway/PushGateway.html) supports a couple of properties that can be configured at runtime. See [config](../../config/config).

0 commit comments

Comments
 (0)