-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...s/client_java_samples/src/main/java/io/prometheus/client/sample/metrics/GaugeExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.prometheus.client.sample.metrics; | ||
|
||
import io.prometheus.client.Gauge; | ||
|
||
public class GaugeExample { | ||
|
||
static final Gauge inprogressRequests = Gauge.build() | ||
.name("inprogress_requests").help("Inprogress requests.").register(); | ||
|
||
void processRequest() { | ||
inprogressRequests.inc(); | ||
// Your code here. | ||
inprogressRequests.dec(); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...ient_java_samples/src/main/java/io/prometheus/client/sample/metrics/HistogramExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.prometheus.client.sample.metrics; | ||
|
||
import io.prometheus.client.Histogram; | ||
import io.prometheus.client.sample.mock.Request; | ||
|
||
public class HistogramExample { | ||
static final Histogram requestLatency = Histogram.build() | ||
.name("requests_latency_seconds").help("Request latency in seconds.") | ||
.buckets(0.1, 0.2, 0.4, 0.8) | ||
.register(); | ||
|
||
static final Histogram receivedBytes = Histogram.build() | ||
.name("requests_size_bytes").help("Request size in bytes.").register(); | ||
|
||
|
||
void processRequest(Request req) { | ||
Histogram.Timer requestTimer = requestLatency.startTimer(); | ||
try { | ||
// Your code here. | ||
} finally { | ||
receivedBytes.observe(req.size()); | ||
requestTimer.observeDuration(); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...client_java_samples/src/main/java/io/prometheus/client/sample/metrics/SummaryExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.prometheus.client.sample.metrics; | ||
|
||
import io.prometheus.client.Summary; | ||
import io.prometheus.client.sample.mock.Request; | ||
|
||
public class SummaryExample { | ||
|
||
static final Summary receivedBytes = Summary.build() | ||
.name("requests_size_bytes").help("Request size in bytes.").register(); | ||
|
||
static final Summary requestLatency = Summary.build() | ||
.name("requests_latency_seconds").help("Request latency in seconds.").register(); | ||
|
||
void processRequest(Request req) { | ||
Summary.Timer requestTimer = requestLatency.startTimer(); | ||
try { | ||
// Your code here. | ||
} finally { | ||
receivedBytes.observe(req.size()); | ||
requestTimer.observeDuration(); | ||
} | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
samples/client_java_samples/src/main/java/io/prometheus/client/sample/mock/Request.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.prometheus.client.sample.mock; | ||
|
||
/** | ||
* Created by zhengyunlong on 7/5/18. | ||
*/ | ||
public class Request { | ||
public double size() { | ||
return 0; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...t_java_samples/src/main/java/io/prometheus/client/sample/push/PushGatewayIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.prometheus.client.sample.push; | ||
|
||
import io.prometheus.client.CollectorRegistry; | ||
import io.prometheus.client.exporter.PushGateway; | ||
|
||
import java.io.IOException; | ||
|
||
public class PushGatewayIntegration { | ||
|
||
public void push() throws IOException { | ||
CollectorRegistry registry = CollectorRegistry.defaultRegistry; | ||
PushGateway pg = new PushGateway("127.0.0.1:9091"); | ||
pg.pushAdd(registry, "my_batch_job"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters