Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
docs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
docs
Commits
56af998b
Commit
56af998b
authored
Aug 01, 2018
by
Luc Perkins
Committed by
Brian Brazil
Aug 01, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Java Pushgateway example (#1133)
Signed-off-by:
lucperkins
<
lucperkins@gmail.com
>
parent
0db52ae7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
69 deletions
+0
-69
pushing.md
content/docs/instrumenting/pushing.md
+0
-69
No files found.
content/docs/instrumenting/pushing.md
View file @
56af998b
...
...
@@ -24,72 +24,3 @@ class.
*
For use from Python see
[
Exporting to a Pushgateway
](
https://github.com/prometheus/client_python#exporting-to-a-pushgateway
)
.
*
For use from Ruby see the
[
Pushgateway documentation
](
https://github.com/prometheus/client_ruby#pushgateway
)
.
## Java batch job example
This example illustrates how to instrument a batch job and alert on it not having succeeded recently.
If using Maven, add the following to
`pom.xml`
:
```
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.0.10</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.0.10</version>
</dependency>
```
Instrument your batch job's code:
```
java
import
io.prometheus.client.CollectorRegistry
;
import
io.prometheus.client.Gauge
;
import
io.prometheus.client.exporter.PushGateway
;
void
executeBatchJob
()
throws
Exception
{
CollectorRegistry
registry
=
new
CollectorRegistry
();
Gauge
duration
=
Gauge
.
build
()
.
name
(
"my_batch_job_duration_seconds"
)
.
help
(
"Duration of my batch job in seconds."
)
.
register
(
registry
);
Gauge
.
Timer
durationTimer
=
duration
.
startTimer
();
try
{
// Your code here.
// This is only added to the registry after success,
// so that a previous success in the Pushgateway is not overwritten on failure.
Gauge
lastSuccess
=
Gauge
.
build
()
.
name
(
"my_batch_job_last_success_unixtime"
)
.
help
(
"Last time my batch job succeeded, in unixtime."
)
.
register
(
registry
);
lastSuccess
.
setToCurrentTime
();
}
finally
{
durationTimer
.
setDuration
();
PushGateway
pg
=
new
PushGateway
(
"127.0.0.1:9091"
);
pg
.
pushAdd
(
registry
,
"my_batch_job"
);
}
}
```
Set up a Pushgateway and update the host and port in the above code if needed.
Set up an alert to fire if the job has not run recently. Add the following to
the rules of a Prometheus server that is scraping the Pushgateway:
```
groups:
- name: MyBatchJob
rules:
- alert: MyBatchJobNotCompleted
expr: min(time() - my_batch_job_last_success_unixtime{job="my_batch_job"}) > 60 * 60
for: 5m
labels:
severity: page
annotations:
summary: MyBatchJob has not completed successfully in over an hour
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment