{"action":"created","comment":{"url":"https://api.github.com/repos/prometheus/docs/pulls/comments/22855342","id":22855342,"diff_hunk":"@@ -0,0 +1,113 @@\n+---\n+title: Template examples\n+sort_rank: 4\n+---\n+\n+# Template examples\n+\n+Prometheus supports templating in the summary and description fields of\n+alerts, as well as in served console pages. Templates have the ability to run\n+queries against the local database, iterate over data, use conditionals, format\n+data, etc. This Prometheus templating language is based on the \n+[Go templating](http://golang.org/pkg/text/template/) system.\n+\n+## Simple alert field templates\n+\n+    ALERT InstanceDown\n+      IF up == 0\n+      FOR 5m\n+      WITH {\n+        severity=\"page\"\n+      }\n+      SUMMARY \"Instance {{$labels.instance}} down\"\n+      DESCRIPTION \"{{$labels.instance}} of job {{$labels.job}} has been down for more than 5 minutes.\"\n+\n+\n+Alert field templates will be executed during every rule iteration for each\n+alert that fires, so keep any queries and templates lightweight. If you have a\n+need for more complicated templates for alerts, it is recommended to link to a\n+console instead.\n+\n+## Simple iteration\n+\n+This displays a list of hosts, and whether they are up:\n+\n+```\n+{{ range query \"up\" }}\n+  {{ .Labels.instance }} {{ .Labels.Value }}\n+{{ end }}\n+```\n+\n+The special `.` variable contains the value of the current sample for each loop iteration.\n+\n+## Display one value\n+\n+```\n+{{ with query \"some_metric{instance='someinstance'}\" }}\n+{{ . | first | value | humanize }}","path":"content/docs/visualization/template_examples.md","position":47,"original_position":47,"commit_id":"878557216e600dc97acf848d3f4ff4723f5c1f30","original_commit_id":"878557216e600dc97acf848d3f4ff4723f5c1f30","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":"Done, and below.","created_at":"2015-01-13T11:03:25Z","updated_at":"2015-01-13T11:03:25Z","html_url":"https://github.com/prometheus/docs/pull/5#discussion_r22855342","pull_request_url":"https://api.github.com/repos/prometheus/docs/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/prometheus/docs/pulls/comments/22855342"},"html":{"href":"https://github.com/prometheus/docs/pull/5#discussion_r22855342"},"pull_request":{"href":"https://api.github.com/repos/prometheus/docs/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/prometheus/docs/pulls/5","id":27042357,"html_url":"https://github.com/prometheus/docs/pull/5","diff_url":"https://github.com/prometheus/docs/pull/5.diff","patch_url":"https://github.com/prometheus/docs/pull/5.patch","issue_url":"https://api.github.com/repos/prometheus/docs/issues/5","number":5,"state":"open","locked":false,"title":"Copy template docs over from the wiki.","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":"Add links to client code for the pushgateway.\r\n\r\nMake getting started link on frontpage go to Getting started section.\r\n\r\nPut exposition formats at the end of instrumenting, as it's the least relevant\r\nto normal users.","created_at":"2015-01-08T16:58:29Z","updated_at":"2015-01-13T11:03:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4304cea834c614ffcacd04a790a3503833335be6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/prometheus/docs/pulls/5/commits","review_comments_url":"https://api.github.com/repos/prometheus/docs/pulls/5/comments","review_comment_url":"https://api.github.com/repos/prometheus/docs/pulls/comments/{number}","comments_url":"https://api.github.com/repos/prometheus/docs/issues/5/comments","statuses_url":"https://api.github.com/repos/prometheus/docs/statuses/878557216e600dc97acf848d3f4ff4723f5c1f30","head":{"label":"brian-brazil:improv","ref":"improv","sha":"878557216e600dc97acf848d3f4ff4723f5c1f30","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-09T15:22:19Z","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":949,"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":"c5d8365c69e686dd833340983bae90f9730e468f","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-12T12:39:34Z","pushed_at":"2015-01-12T12:39:34Z","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":1456,"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/5"},"html":{"href":"https://github.com/prometheus/docs/pull/5"},"issue":{"href":"https://api.github.com/repos/prometheus/docs/issues/5"},"comments":{"href":"https://api.github.com/repos/prometheus/docs/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/prometheus/docs/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/prometheus/docs/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/prometheus/docs/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/prometheus/docs/statuses/878557216e600dc97acf848d3f4ff4723f5c1f30"}}}}