{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/comments/77817262","id":77817262,"diff_hunk":"@@ -0,0 +1,148 @@\n+// Copyright 2014 The Prometheus Authors\n+// Copyright 2016 PingCAP, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+use std::str::{self, FromStr};\n+use std::collections::HashMap;\n+\n+use libc::{self, gethostname};\n+use hyper::client::Client;\n+use hyper::client::pool::Config;\n+use hyper::method::Method;\n+use hyper::status::StatusCode;\n+use hyper::header::ContentType;\n+\n+use proto;\n+use errors::{Result, Error};\n+use encoder::{Encoder, TextEncoder};\n+\n+lazy_static!{\n+    static ref HTTP_CLIENT: Client = Client::with_pool_config(\n+            Config{\n+                max_idle: 1,\n+            }\n+        );\n+}\n+\n+/// `push_from_gather` triggers a metric collection by the provided Gatherer (which is\n+/// usually implemented by a prometheus.Registry) and pushes all gathered metrics\n+/// to the Pushgateway specified by url, using the provided job name and the\n+/// (optional) further grouping labels (the grouping map may be nil). See the\n+/// Pushgateway documentation for detailed implications of the job and other\n+/// grouping labels. Neither the job name nor any grouping label value may\n+/// contain a \"/\". The metrics pushed must not contain a job label of their own\n+/// nor any of the grouping labels.\n+///\n+/// You can use just host:port or ip:port as url, in which case 'http://' is\n+/// added automatically. You can also include the schema in the URL. However, do\n+/// not include the '/metrics/jobs/...' part.\n+///\n+/// Note that all previously pushed metrics with the same job and other grouping\n+/// labels will be replaced with the metrics pushed by this call. (It uses HTTP\n+/// method 'PUT' to push to the Pushgateway.)\n+pub fn push_from_gather(job: &str,\n+                        grouping: HashMap<String, String>,\n+                        url: &str,\n+                        mfs: Vec<proto::MetricFamily>)\n+                        -> Result<()> {\n+    push(job, grouping, url, mfs, \"PUT\")\n+}\n+\n+fn push(job: &str,\n+        grouping: HashMap<String, String>,\n+        url: &str,\n+        mfs: Vec<proto::MetricFamily>,\n+        method: &str)\n+        -> Result<()> {\n+\n+    let mut push_url = if url.contains(\"://\") {\n+        url.to_owned()\n+    } else {\n+        \"http://\".to_owned() + url","path":"src/push.rs","position":71,"original_position":71,"commit_id":"cedb07290d1f384d78d21f6431f38d16bc52908d","original_commit_id":"cedb07290d1f384d78d21f6431f38d16bc52908d","user":{"login":"siddontang","id":1080370,"avatar_url":"https://avatars.githubusercontent.com/u/1080370?v=3","gravatar_id":"","url":"https://api.github.com/users/siddontang","html_url":"https://github.com/siddontang","followers_url":"https://api.github.com/users/siddontang/followers","following_url":"https://api.github.com/users/siddontang/following{/other_user}","gists_url":"https://api.github.com/users/siddontang/gists{/gist_id}","starred_url":"https://api.github.com/users/siddontang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siddontang/subscriptions","organizations_url":"https://api.github.com/users/siddontang/orgs","repos_url":"https://api.github.com/users/siddontang/repos","events_url":"https://api.github.com/users/siddontang/events{/privacy}","received_events_url":"https://api.github.com/users/siddontang/received_events","type":"User","site_admin":false},"body":"use format","created_at":"2016-09-07T13:05:58Z","updated_at":"2016-09-07T13:05:58Z","html_url":"https://github.com/pingcap/rust-prometheus/pull/53#discussion_r77817262","pull_request_url":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/53","_links":{"self":{"href":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/comments/77817262"},"html":{"href":"https://github.com/pingcap/rust-prometheus/pull/53#discussion_r77817262"},"pull_request":{"href":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/53"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/53","id":84291672,"html_url":"https://github.com/pingcap/rust-prometheus/pull/53","diff_url":"https://github.com/pingcap/rust-prometheus/pull/53.diff","patch_url":"https://github.com/pingcap/rust-prometheus/pull/53.patch","issue_url":"https://api.github.com/repos/pingcap/rust-prometheus/issues/53","number":53,"state":"open","locked":false,"title":"Support push","user":{"login":"overvenus","id":2150711,"avatar_url":"https://avatars.githubusercontent.com/u/2150711?v=3","gravatar_id":"","url":"https://api.github.com/users/overvenus","html_url":"https://github.com/overvenus","followers_url":"https://api.github.com/users/overvenus/followers","following_url":"https://api.github.com/users/overvenus/following{/other_user}","gists_url":"https://api.github.com/users/overvenus/gists{/gist_id}","starred_url":"https://api.github.com/users/overvenus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overvenus/subscriptions","organizations_url":"https://api.github.com/users/overvenus/orgs","repos_url":"https://api.github.com/users/overvenus/repos","events_url":"https://api.github.com/users/overvenus/events{/privacy}","received_events_url":"https://api.github.com/users/overvenus/received_events","type":"User","site_admin":false},"body":"Resolved #34 \r\n\r\nPTAL @siddontang @disksing ","created_at":"2016-09-07T12:34:21Z","updated_at":"2016-09-07T13:05:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6188c5f550d2338e973e4ae0eca6fd6b8bd9a634","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/53/commits","review_comments_url":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/53/comments","review_comment_url":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/rust-prometheus/issues/53/comments","statuses_url":"https://api.github.com/repos/pingcap/rust-prometheus/statuses/cedb07290d1f384d78d21f6431f38d16bc52908d","head":{"label":"overvenus:support-push","ref":"support-push","sha":"cedb07290d1f384d78d21f6431f38d16bc52908d","user":{"login":"overvenus","id":2150711,"avatar_url":"https://avatars.githubusercontent.com/u/2150711?v=3","gravatar_id":"","url":"https://api.github.com/users/overvenus","html_url":"https://github.com/overvenus","followers_url":"https://api.github.com/users/overvenus/followers","following_url":"https://api.github.com/users/overvenus/following{/other_user}","gists_url":"https://api.github.com/users/overvenus/gists{/gist_id}","starred_url":"https://api.github.com/users/overvenus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overvenus/subscriptions","organizations_url":"https://api.github.com/users/overvenus/orgs","repos_url":"https://api.github.com/users/overvenus/repos","events_url":"https://api.github.com/users/overvenus/events{/privacy}","received_events_url":"https://api.github.com/users/overvenus/received_events","type":"User","site_admin":false},"repo":{"id":66003047,"name":"rust-prometheus","full_name":"overvenus/rust-prometheus","owner":{"login":"overvenus","id":2150711,"avatar_url":"https://avatars.githubusercontent.com/u/2150711?v=3","gravatar_id":"","url":"https://api.github.com/users/overvenus","html_url":"https://github.com/overvenus","followers_url":"https://api.github.com/users/overvenus/followers","following_url":"https://api.github.com/users/overvenus/following{/other_user}","gists_url":"https://api.github.com/users/overvenus/gists{/gist_id}","starred_url":"https://api.github.com/users/overvenus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overvenus/subscriptions","organizations_url":"https://api.github.com/users/overvenus/orgs","repos_url":"https://api.github.com/users/overvenus/repos","events_url":"https://api.github.com/users/overvenus/events{/privacy}","received_events_url":"https://api.github.com/users/overvenus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/overvenus/rust-prometheus","description":"Prometheus instrumentation library for Rust applications","fork":true,"url":"https://api.github.com/repos/overvenus/rust-prometheus","forks_url":"https://api.github.com/repos/overvenus/rust-prometheus/forks","keys_url":"https://api.github.com/repos/overvenus/rust-prometheus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/overvenus/rust-prometheus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/overvenus/rust-prometheus/teams","hooks_url":"https://api.github.com/repos/overvenus/rust-prometheus/hooks","issue_events_url":"https://api.github.com/repos/overvenus/rust-prometheus/issues/events{/number}","events_url":"https://api.github.com/repos/overvenus/rust-prometheus/events","assignees_url":"https://api.github.com/repos/overvenus/rust-prometheus/assignees{/user}","branches_url":"https://api.github.com/repos/overvenus/rust-prometheus/branches{/branch}","tags_url":"https://api.github.com/repos/overvenus/rust-prometheus/tags","blobs_url":"https://api.github.com/repos/overvenus/rust-prometheus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/overvenus/rust-prometheus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/overvenus/rust-prometheus/git/refs{/sha}","trees_url":"https://api.github.com/repos/overvenus/rust-prometheus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/overvenus/rust-prometheus/statuses/{sha}","languages_url":"https://api.github.com/repos/overvenus/rust-prometheus/languages","stargazers_url":"https://api.github.com/repos/overvenus/rust-prometheus/stargazers","contributors_url":"https://api.github.com/repos/overvenus/rust-prometheus/contributors","subscribers_url":"https://api.github.com/repos/overvenus/rust-prometheus/subscribers","subscription_url":"https://api.github.com/repos/overvenus/rust-prometheus/subscription","commits_url":"https://api.github.com/repos/overvenus/rust-prometheus/commits{/sha}","git_commits_url":"https://api.github.com/repos/overvenus/rust-prometheus/git/commits{/sha}","comments_url":"https://api.github.com/repos/overvenus/rust-prometheus/comments{/number}","issue_comment_url":"https://api.github.com/repos/overvenus/rust-prometheus/issues/comments{/number}","contents_url":"https://api.github.com/repos/overvenus/rust-prometheus/contents/{+path}","compare_url":"https://api.github.com/repos/overvenus/rust-prometheus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/overvenus/rust-prometheus/merges","archive_url":"https://api.github.com/repos/overvenus/rust-prometheus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/overvenus/rust-prometheus/downloads","issues_url":"https://api.github.com/repos/overvenus/rust-prometheus/issues{/number}","pulls_url":"https://api.github.com/repos/overvenus/rust-prometheus/pulls{/number}","milestones_url":"https://api.github.com/repos/overvenus/rust-prometheus/milestones{/number}","notifications_url":"https://api.github.com/repos/overvenus/rust-prometheus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/overvenus/rust-prometheus/labels{/name}","releases_url":"https://api.github.com/repos/overvenus/rust-prometheus/releases{/id}","deployments_url":"https://api.github.com/repos/overvenus/rust-prometheus/deployments","created_at":"2016-08-18T14:17:28Z","updated_at":"2016-08-18T14:17:30Z","pushed_at":"2016-09-07T12:32:58Z","git_url":"git://github.com/overvenus/rust-prometheus.git","ssh_url":"git@github.com:overvenus/rust-prometheus.git","clone_url":"https://github.com/overvenus/rust-prometheus.git","svn_url":"https://github.com/overvenus/rust-prometheus","homepage":null,"size":156,"stargazers_count":0,"watchers_count":0,"language":"Rust","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":"pingcap:master","ref":"master","sha":"37caafad505547b391633d6f24bd7e4e0528ac2a","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":65430363,"name":"rust-prometheus","full_name":"pingcap/rust-prometheus","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/rust-prometheus","description":"Prometheus instrumentation library for Rust applications","fork":false,"url":"https://api.github.com/repos/pingcap/rust-prometheus","forks_url":"https://api.github.com/repos/pingcap/rust-prometheus/forks","keys_url":"https://api.github.com/repos/pingcap/rust-prometheus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/rust-prometheus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/rust-prometheus/teams","hooks_url":"https://api.github.com/repos/pingcap/rust-prometheus/hooks","issue_events_url":"https://api.github.com/repos/pingcap/rust-prometheus/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/rust-prometheus/events","assignees_url":"https://api.github.com/repos/pingcap/rust-prometheus/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/rust-prometheus/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/rust-prometheus/tags","blobs_url":"https://api.github.com/repos/pingcap/rust-prometheus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/rust-prometheus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/rust-prometheus/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/rust-prometheus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/rust-prometheus/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/rust-prometheus/languages","stargazers_url":"https://api.github.com/repos/pingcap/rust-prometheus/stargazers","contributors_url":"https://api.github.com/repos/pingcap/rust-prometheus/contributors","subscribers_url":"https://api.github.com/repos/pingcap/rust-prometheus/subscribers","subscription_url":"https://api.github.com/repos/pingcap/rust-prometheus/subscription","commits_url":"https://api.github.com/repos/pingcap/rust-prometheus/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/rust-prometheus/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/rust-prometheus/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/rust-prometheus/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/rust-prometheus/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/rust-prometheus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/rust-prometheus/merges","archive_url":"https://api.github.com/repos/pingcap/rust-prometheus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/rust-prometheus/downloads","issues_url":"https://api.github.com/repos/pingcap/rust-prometheus/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/rust-prometheus/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/rust-prometheus/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/rust-prometheus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/rust-prometheus/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/rust-prometheus/releases{/id}","deployments_url":"https://api.github.com/repos/pingcap/rust-prometheus/deployments","created_at":"2016-08-11T02:06:25Z","updated_at":"2016-09-07T10:06:33Z","pushed_at":"2016-09-07T12:34:21Z","git_url":"git://github.com/pingcap/rust-prometheus.git","ssh_url":"git@github.com:pingcap/rust-prometheus.git","clone_url":"https://github.com/pingcap/rust-prometheus.git","svn_url":"https://github.com/pingcap/rust-prometheus","homepage":null,"size":176,"stargazers_count":9,"watchers_count":9,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":12,"forks":1,"open_issues":12,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/53"},"html":{"href":"https://github.com/pingcap/rust-prometheus/pull/53"},"issue":{"href":"https://api.github.com/repos/pingcap/rust-prometheus/issues/53"},"comments":{"href":"https://api.github.com/repos/pingcap/rust-prometheus/issues/53/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/53/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/rust-prometheus/pulls/53/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/rust-prometheus/statuses/cedb07290d1f384d78d21f6431f38d16bc52908d"}}}}
{"actor":{"display_login":"siddontang"}}