{"action":"created","comment":{"url":"https://api.github.com/repos/prometheus/docs/pulls/comments/23235226","id":23235226,"diff_hunk":"@@ -21,3 +21,68 @@ For use from Java see the\n class.\n \n For use from Go see the [Push](http://godoc.org/github.com/prometheus/client_golang/prometheus#Push) and [PushAdd](http://godoc.org/github.com/prometheus/client_golang/prometheus#PushAdd) functions.\n+\n+## Java Batch Job Example\n+\n+This example illustrates how to instrument a batch job and alert on it not having succeeded recently.\n+\n+If using Maven, add the following to `pom.xml`:\n+\n+```\n+        <dependency>\n+            <groupId>io.prometheus</groupId>\n+            <artifactId>simpleclient</artifactId>\n+            <version>0.0.6</version>\n+        </dependency>\n+        <dependency>\n+            <groupId>io.prometheus</groupId>\n+            <artifactId>simpleclient_pushgateway</artifactId>\n+            <version>0.0.6</version>\n+        </dependency>\n+```\n+\n+\n+Instrument to track duration and last success:\n+\n+```java\n+import io.prometheus.client.CollectorRegistry;\n+import io.prometheus.client.Gauge;\n+import io.prometheus.client.exporter.PushGateway;\n+\n+void executeBatchJob() throws Exception {\n+ CollectorRegistry registry = new CollectorRegistry();\n+ Gauge duration = Gauge.build()\n+     .name(\"my_batch_job_duration_seconds\")\n+     .help(\"Duration of my batch job in seconds.\")\n+     .register(registry);\n+ Gauge.Timer durationTimer = duration.startTimer();\n+ try {\n+   // Your code here.\n+\n+   // This is only added to the registry after success,\n+   // so that a previous success in the Pushgateway is not overwritten on failure.\n+   Gauge lastSuccess = Gauge.build()\n+       .name(\"my_batch_job_last_success\")\n+       .help(\"Last time my batch job succeeded, in unixtime.\")\n+       .register(registry);\n+   lastSuccess.setToCurrentTime();\n+ } finally {\n+   durationTimer.setDuration();\n+   PushGateway pg = new PushGateway(\"127.0.0.1:9091\");\n+   pg.pushAdd(registry, \"my_batch_job\", \"my_batch_job\");\n+ }\n+}\n+```\n+\n+Setup a Pushgateway, update the host and port in the above code if needed.\n+\n+Setup an alert to fire if the job has not run recently. Add the following to\n+the rules of a Prometheus server that's scraping the Pushgateway:","path":"content/docs/instrumenting/pushing.md","position":75,"original_position":75,"commit_id":"177ac9002ec6d2ecc220c490e6023cc4cf61e8e7","original_commit_id":"177ac9002ec6d2ecc220c490e6023cc4cf61e8e7","user":{"login":"juliusv","id":538008,"avatar_url":"https://avatars.githubusercontent.com/u/538008?v=3","gravatar_id":"","url":"https://api.github.com/users/juliusv","html_url":"https://github.com/juliusv","followers_url":"https://api.github.com/users/juliusv/followers","following_url":"https://api.github.com/users/juliusv/following{/other_user}","gists_url":"https://api.github.com/users/juliusv/gists{/gist_id}","starred_url":"https://api.github.com/users/juliusv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliusv/subscriptions","organizations_url":"https://api.github.com/users/juliusv/orgs","repos_url":"https://api.github.com/users/juliusv/repos","events_url":"https://api.github.com/users/juliusv/events{/privacy}","received_events_url":"https://api.github.com/users/juliusv/received_events","type":"User","site_admin":false},"body":"that is","created_at":"2015-01-20T16:42:44Z","updated_at":"2015-01-20T16:42:44Z","html_url":"https://github.com/prometheus/docs/pull/7#discussion_r23235226","pull_request_url":"https://api.github.com/repos/prometheus/docs/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/prometheus/docs/pulls/comments/23235226"},"html":{"href":"https://github.com/prometheus/docs/pull/7#discussion_r23235226"},"pull_request":{"href":"https://api.github.com/repos/prometheus/docs/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/prometheus/docs/pulls/7","id":27691776,"html_url":"https://github.com/prometheus/docs/pull/7","diff_url":"https://github.com/prometheus/docs/pull/7.diff","patch_url":"https://github.com/prometheus/docs/pull/7.patch","issue_url":"https://api.github.com/repos/prometheus/docs/issues/7","number":7,"state":"open","locked":false,"title":"Expand Pushgateway docs with Java example.","user":{"login":"brian-brazil","id":7115638,"avatar_url":"https://avatars.githubusercontent.com/u/7115638?v=3","gravatar_id":"","url":"https://api.github.com/users/brian-brazil","html_url":"https://github.com/brian-brazil","followers_url":"https://api.github.com/users/brian-brazil/followers","following_url":"https://api.github.com/users/brian-brazil/following{/other_user}","gists_url":"https://api.github.com/users/brian-brazil/gists{/gist_id}","starred_url":"https://api.github.com/users/brian-brazil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brian-brazil/subscriptions","organizations_url":"https://api.github.com/users/brian-brazil/orgs","repos_url":"https://api.github.com/users/brian-brazil/repos","events_url":"https://api.github.com/users/brian-brazil/events{/privacy}","received_events_url":"https://api.github.com/users/brian-brazil/received_events","type":"User","site_admin":false},"body":"Be consistent in saying 'Pushgateway, that's what's in the README.md of the project itself.","created_at":"2015-01-20T16:39:30Z","updated_at":"2015-01-20T16:42:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d974c391534e165a8d55c6895f5dd921f2319e5b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/prometheus/docs/pulls/7/commits","review_comments_url":"https://api.github.com/repos/prometheus/docs/pulls/7/comments","review_comment_url":"https://api.github.com/repos/prometheus/docs/pulls/comments/{number}","comments_url":"https://api.github.com/repos/prometheus/docs/issues/7/comments","statuses_url":"https://api.github.com/repos/prometheus/docs/statuses/177ac9002ec6d2ecc220c490e6023cc4cf61e8e7","head":{"label":"brian-brazil:pushgateway","ref":"pushgateway","sha":"177ac9002ec6d2ecc220c490e6023cc4cf61e8e7","user":{"login":"brian-brazil","id":7115638,"avatar_url":"https://avatars.githubusercontent.com/u/7115638?v=3","gravatar_id":"","url":"https://api.github.com/users/brian-brazil","html_url":"https://github.com/brian-brazil","followers_url":"https://api.github.com/users/brian-brazil/followers","following_url":"https://api.github.com/users/brian-brazil/following{/other_user}","gists_url":"https://api.github.com/users/brian-brazil/gists{/gist_id}","starred_url":"https://api.github.com/users/brian-brazil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brian-brazil/subscriptions","organizations_url":"https://api.github.com/users/brian-brazil/orgs","repos_url":"https://api.github.com/users/brian-brazil/repos","events_url":"https://api.github.com/users/brian-brazil/events{/privacy}","received_events_url":"https://api.github.com/users/brian-brazil/received_events","type":"User","site_admin":false},"repo":{"id":28494454,"name":"docs","full_name":"brian-brazil/docs","owner":{"login":"brian-brazil","id":7115638,"avatar_url":"https://avatars.githubusercontent.com/u/7115638?v=3","gravatar_id":"","url":"https://api.github.com/users/brian-brazil","html_url":"https://github.com/brian-brazil","followers_url":"https://api.github.com/users/brian-brazil/followers","following_url":"https://api.github.com/users/brian-brazil/following{/other_user}","gists_url":"https://api.github.com/users/brian-brazil/gists{/gist_id}","starred_url":"https://api.github.com/users/brian-brazil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brian-brazil/subscriptions","organizations_url":"https://api.github.com/users/brian-brazil/orgs","repos_url":"https://api.github.com/users/brian-brazil/repos","events_url":"https://api.github.com/users/brian-brazil/events{/privacy}","received_events_url":"https://api.github.com/users/brian-brazil/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brian-brazil/docs","description":"Prometheus documentation: content and static site generator","fork":true,"url":"https://api.github.com/repos/brian-brazil/docs","forks_url":"https://api.github.com/repos/brian-brazil/docs/forks","keys_url":"https://api.github.com/repos/brian-brazil/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brian-brazil/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brian-brazil/docs/teams","hooks_url":"https://api.github.com/repos/brian-brazil/docs/hooks","issue_events_url":"https://api.github.com/repos/brian-brazil/docs/issues/events{/number}","events_url":"https://api.github.com/repos/brian-brazil/docs/events","assignees_url":"https://api.github.com/repos/brian-brazil/docs/assignees{/user}","branches_url":"https://api.github.com/repos/brian-brazil/docs/branches{/branch}","tags_url":"https://api.github.com/repos/brian-brazil/docs/tags","blobs_url":"https://api.github.com/repos/brian-brazil/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brian-brazil/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brian-brazil/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/brian-brazil/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brian-brazil/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/brian-brazil/docs/languages","stargazers_url":"https://api.github.com/repos/brian-brazil/docs/stargazers","contributors_url":"https://api.github.com/repos/brian-brazil/docs/contributors","subscribers_url":"https://api.github.com/repos/brian-brazil/docs/subscribers","subscription_url":"https://api.github.com/repos/brian-brazil/docs/subscription","commits_url":"https://api.github.com/repos/brian-brazil/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/brian-brazil/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/brian-brazil/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/brian-brazil/docs/issues/comments/{number}","contents_url":"https://api.github.com/repos/brian-brazil/docs/contents/{+path}","compare_url":"https://api.github.com/repos/brian-brazil/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brian-brazil/docs/merges","archive_url":"https://api.github.com/repos/brian-brazil/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brian-brazil/docs/downloads","issues_url":"https://api.github.com/repos/brian-brazil/docs/issues{/number}","pulls_url":"https://api.github.com/repos/brian-brazil/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/brian-brazil/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/brian-brazil/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brian-brazil/docs/labels{/name}","releases_url":"https://api.github.com/repos/brian-brazil/docs/releases{/id}","created_at":"2014-12-26T00:18:22Z","updated_at":"2015-01-02T10:46:22Z","pushed_at":"2015-01-20T16:39:02Z","git_url":"git://github.com/brian-brazil/docs.git","ssh_url":"git@github.com:brian-brazil/docs.git","clone_url":"https://github.com/brian-brazil/docs.git","svn_url":"https://github.com/brian-brazil/docs","homepage":null,"size":933,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"prometheus:master","ref":"master","sha":"f98da7de90152e38187c8a0bed8cb5402d5923d9","user":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars.githubusercontent.com/u/3380462?v=3","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"repo":{"id":28233924,"name":"docs","full_name":"prometheus/docs","owner":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars.githubusercontent.com/u/3380462?v=3","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/prometheus/docs","description":"Prometheus documentation: content and static site generator","fork":false,"url":"https://api.github.com/repos/prometheus/docs","forks_url":"https://api.github.com/repos/prometheus/docs/forks","keys_url":"https://api.github.com/repos/prometheus/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prometheus/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prometheus/docs/teams","hooks_url":"https://api.github.com/repos/prometheus/docs/hooks","issue_events_url":"https://api.github.com/repos/prometheus/docs/issues/events{/number}","events_url":"https://api.github.com/repos/prometheus/docs/events","assignees_url":"https://api.github.com/repos/prometheus/docs/assignees{/user}","branches_url":"https://api.github.com/repos/prometheus/docs/branches{/branch}","tags_url":"https://api.github.com/repos/prometheus/docs/tags","blobs_url":"https://api.github.com/repos/prometheus/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prometheus/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prometheus/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/prometheus/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prometheus/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/prometheus/docs/languages","stargazers_url":"https://api.github.com/repos/prometheus/docs/stargazers","contributors_url":"https://api.github.com/repos/prometheus/docs/contributors","subscribers_url":"https://api.github.com/repos/prometheus/docs/subscribers","subscription_url":"https://api.github.com/repos/prometheus/docs/subscription","commits_url":"https://api.github.com/repos/prometheus/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/prometheus/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/prometheus/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/prometheus/docs/issues/comments/{number}","contents_url":"https://api.github.com/repos/prometheus/docs/contents/{+path}","compare_url":"https://api.github.com/repos/prometheus/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prometheus/docs/merges","archive_url":"https://api.github.com/repos/prometheus/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prometheus/docs/downloads","issues_url":"https://api.github.com/repos/prometheus/docs/issues{/number}","pulls_url":"https://api.github.com/repos/prometheus/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/prometheus/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/prometheus/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prometheus/docs/labels{/name}","releases_url":"https://api.github.com/repos/prometheus/docs/releases{/id}","created_at":"2014-12-19T15:06:35Z","updated_at":"2015-01-19T17:47:59Z","pushed_at":"2015-01-19T17:47:59Z","git_url":"git://github.com/prometheus/docs.git","ssh_url":"git@github.com:prometheus/docs.git","clone_url":"https://github.com/prometheus/docs.git","svn_url":"https://github.com/prometheus/docs","homepage":null,"size":1227,"stargazers_count":1,"watchers_count":1,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/prometheus/docs/pulls/7"},"html":{"href":"https://github.com/prometheus/docs/pull/7"},"issue":{"href":"https://api.github.com/repos/prometheus/docs/issues/7"},"comments":{"href":"https://api.github.com/repos/prometheus/docs/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/prometheus/docs/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/prometheus/docs/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/prometheus/docs/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/prometheus/docs/statuses/177ac9002ec6d2ecc220c490e6023cc4cf61e8e7"}}}}