{"action":"created","comment":{"url":"https://api.github.com/repos/google/cadvisor/pulls/comments/25508504","id":25508504,"diff_hunk":"@@ -0,0 +1,455 @@\n+package exporter\n+\n+import (\n+\t\"fmt\"\n+\t\"strings\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"github.com/golang/glog\"\n+\t\"github.com/google/cadvisor/info\"\n+\t\"github.com/google/cadvisor/manager\"\n+\t\"github.com/prometheus/client_golang/prometheus\"\n+)\n+\n+const namespace = \"container\"\n+\n+// Just a small interface for easier housekeeping\n+type vector interface {\n+\tReset()\n+\tDescribe(ch chan<- *prometheus.Desc)\n+\tCollect(ch chan<- prometheus.Metric)\n+}\n+\n+type PrometheusCollector struct {\n+\tmutex   sync.RWMutex\n+\tmanager manager.Manager\n+\n+\terrors   prometheus.Counter\n+\tlastSeen *prometheus.CounterVec\n+\n+\tcpuUsageSeconds       *prometheus.CounterVec\n+\tcpuUsageSecondsPerCPU *prometheus.CounterVec\n+\n+\tmemoryUsageBytes *prometheus.GaugeVec\n+\tmemoryWorkingSet *prometheus.GaugeVec\n+\tmemoryFailures   *prometheus.CounterVec\n+\n+\tfsLimit        *prometheus.GaugeVec\n+\tfsUsage        *prometheus.GaugeVec\n+\tfsReads        *prometheus.CounterVec\n+\tfsReadsSectors *prometheus.CounterVec\n+\tfsReadsMerged  *prometheus.CounterVec\n+\tfsReadTime     *prometheus.CounterVec\n+\n+\tfsWrites        *prometheus.CounterVec\n+\tfsWritesSectors *prometheus.CounterVec\n+\tfsWritesMerged  *prometheus.CounterVec\n+\tfsWriteTime     *prometheus.CounterVec\n+\n+\tfsIoInProgress *prometheus.GaugeVec\n+\tfsIoTime       *prometheus.CounterVec\n+\n+\tfsWeightedIoTime *prometheus.CounterVec\n+\n+\tnetworkRxBytes   *prometheus.CounterVec\n+\tnetworkRxPackets *prometheus.CounterVec\n+\tnetworkRxErrors  *prometheus.CounterVec\n+\tnetworkRxDropped *prometheus.CounterVec\n+\tnetworkTxBytes   *prometheus.CounterVec\n+\tnetworkTxPackets *prometheus.CounterVec\n+\tnetworkTxErrors  *prometheus.CounterVec\n+\tnetworkTxDropped *prometheus.CounterVec\n+\n+\ttasksSleeping        *prometheus.GaugeVec\n+\ttasksRunning         *prometheus.GaugeVec\n+\ttasksStopped         *prometheus.GaugeVec\n+\ttasksUninterruptible *prometheus.GaugeVec\n+\ttasksIoWait          *prometheus.GaugeVec\n+\n+\tvectors []vector\n+}\n+\n+// New returns a new PrometheusCollector\n+func NewPrometheusCollector(manager manager.Manager) *PrometheusCollector {\n+\tc := &PrometheusCollector{\n+\t\tmanager: manager,\n+\t\terrors: prometheus.NewCounter(prometheus.CounterOpts{\n+\t\t\tNamespace: namespace,\n+\t\t\tName:      \"errors_total\",\n+\t\t\tHelp:      \"Errors while exporting container metrics.\",\n+\t\t}),\n+\t\tlastSeen: prometheus.NewCounterVec(prometheus.CounterOpts{\n+\t\t\tNamespace: namespace,\n+\t\t\tName:      \"last_seen\",\n+\t\t\tHelp:      \"Last time a container was seen by the exporter\",\n+\t\t},\n+\t\t\t[]string{\"name\", \"id\", \"image\"},\n+\t\t),\n+\t\tcpuUsageSeconds: prometheus.NewCounterVec(prometheus.CounterOpts{\n+\t\t\tNamespace: namespace,\n+\t\t\tName:      \"cpu_usage_seconds_total\",\n+\t\t\tHelp:      \"Total seconds of cpu time consumed.\",\n+\t\t},\n+\t\t\t[]string{\"name\", \"id\", \"image\", \"type\"},\n+\t\t),\n+\t\tcpuUsageSecondsPerCPU: prometheus.NewCounterVec(prometheus.CounterOpts{\n+\t\t\tNamespace: namespace,\n+\t\t\tName:      \"cpu_usage_per_cpu_seconds_total\",\n+\t\t\tHelp:      \"Total seconds of cpu time consumed per cpu.\",\n+\t\t},\n+\t\t\t[]string{\"name\", \"id\", \"image\", \"cpu\"},\n+\t\t),\n+\n+\t\tmemoryUsageBytes: prometheus.NewGaugeVec(prometheus.GaugeOpts{\n+\t\t\tNamespace: namespace,\n+\t\t\tName:      \"memory_usage_bytes\",\n+\t\t\tHelp:      \"Current memory usage in bytes.\",\n+\t\t},\n+\t\t\t[]string{\"name\", \"id\", \"image\"},\n+\t\t),\n+\t\tmemoryWorkingSet: prometheus.NewGaugeVec(prometheus.GaugeOpts{\n+\t\t\tNamespace: namespace,\n+\t\t\tName:      \"memory_working_set_bytes\",\n+\t\t\tHelp:      \"Current working set in bytes.\",\n+\t\t},\n+\t\t\t[]string{\"name\", \"id\", \"image\"},\n+\t\t),\n+\t\tmemoryFailures: prometheus.NewCounterVec(prometheus.CounterOpts{\n+\t\t\tNamespace: namespace,\n+\t\t\tName:      \"memory_failures_total\",\n+\t\t\tHelp:      \"Number of times memory usage hits limits.\",","path":"exporter/prometheus.go","position":121,"original_position":121,"commit_id":"aa2e3c7bbb8663ae8a703bf09e541f6c7828bed3","original_commit_id":"aa2e3c7bbb8663ae8a703bf09e541f6c7828bed3","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":"s/hits/hit/","created_at":"2015-02-27T14:17:52Z","updated_at":"2015-02-27T14:17:52Z","html_url":"https://github.com/google/cadvisor/pull/545#discussion_r25508504","pull_request_url":"https://api.github.com/repos/google/cadvisor/pulls/545","_links":{"self":{"href":"https://api.github.com/repos/google/cadvisor/pulls/comments/25508504"},"html":{"href":"https://github.com/google/cadvisor/pull/545#discussion_r25508504"},"pull_request":{"href":"https://api.github.com/repos/google/cadvisor/pulls/545"}}},"pull_request":{"url":"https://api.github.com/repos/google/cadvisor/pulls/545","id":30168598,"html_url":"https://github.com/google/cadvisor/pull/545","diff_url":"https://github.com/google/cadvisor/pull/545.diff","patch_url":"https://github.com/google/cadvisor/pull/545.patch","issue_url":"https://api.github.com/repos/google/cadvisor/issues/545","number":545,"state":"open","locked":false,"title":"[WIP] Provide cadvisor stats as prometheus metrics","user":{"login":"discordianfish","id":275966,"avatar_url":"https://avatars.githubusercontent.com/u/275966?v=3","gravatar_id":"","url":"https://api.github.com/users/discordianfish","html_url":"https://github.com/discordianfish","followers_url":"https://api.github.com/users/discordianfish/followers","following_url":"https://api.github.com/users/discordianfish/following{/other_user}","gists_url":"https://api.github.com/users/discordianfish/gists{/gist_id}","starred_url":"https://api.github.com/users/discordianfish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/discordianfish/subscriptions","organizations_url":"https://api.github.com/users/discordianfish/orgs","repos_url":"https://api.github.com/users/discordianfish/repos","events_url":"https://api.github.com/users/discordianfish/events{/privacy}","received_events_url":"https://api.github.com/users/discordianfish/received_events","type":"User","site_admin":false},"body":"This is WIP and provided for discussion:\r\n\r\n- name is aliases joined by , and definitely not what we want: Ideas to solve that? We can:\r\n  - either set the same metric multiple times for each alias\r\n  - or have explicit notion of 'docker name' vs 'docker id' instead of the aliases list\r\n- It doesn't support image name as metric dimension since I'm not sure how to get this\r\n- Unsure about package structure: I didn't use prometheus/ but exporter/ because a) it might not be the only exporter? b) the import path in main would clash with client_golang/prometheus\r\n- No tests; Will look into that once we agreed on the general form\r\n- Usage is in seconds, not percent. Not sure what's better\r\n\r\nImplements #502 ","created_at":"2015-02-27T14:13:21Z","updated_at":"2015-02-27T14:17:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"799666c26c7788a7cf9c4941eee452cdf125bf91","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/google/cadvisor/pulls/545/commits","review_comments_url":"https://api.github.com/repos/google/cadvisor/pulls/545/comments","review_comment_url":"https://api.github.com/repos/google/cadvisor/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/cadvisor/issues/545/comments","statuses_url":"https://api.github.com/repos/google/cadvisor/statuses/aa2e3c7bbb8663ae8a703bf09e541f6c7828bed3","head":{"label":"discordianfish:export-prometheus","ref":"export-prometheus","sha":"aa2e3c7bbb8663ae8a703bf09e541f6c7828bed3","user":{"login":"discordianfish","id":275966,"avatar_url":"https://avatars.githubusercontent.com/u/275966?v=3","gravatar_id":"","url":"https://api.github.com/users/discordianfish","html_url":"https://github.com/discordianfish","followers_url":"https://api.github.com/users/discordianfish/followers","following_url":"https://api.github.com/users/discordianfish/following{/other_user}","gists_url":"https://api.github.com/users/discordianfish/gists{/gist_id}","starred_url":"https://api.github.com/users/discordianfish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/discordianfish/subscriptions","organizations_url":"https://api.github.com/users/discordianfish/orgs","repos_url":"https://api.github.com/users/discordianfish/repos","events_url":"https://api.github.com/users/discordianfish/events{/privacy}","received_events_url":"https://api.github.com/users/discordianfish/received_events","type":"User","site_admin":false},"repo":{"id":31421576,"name":"cadvisor","full_name":"discordianfish/cadvisor","owner":{"login":"discordianfish","id":275966,"avatar_url":"https://avatars.githubusercontent.com/u/275966?v=3","gravatar_id":"","url":"https://api.github.com/users/discordianfish","html_url":"https://github.com/discordianfish","followers_url":"https://api.github.com/users/discordianfish/followers","following_url":"https://api.github.com/users/discordianfish/following{/other_user}","gists_url":"https://api.github.com/users/discordianfish/gists{/gist_id}","starred_url":"https://api.github.com/users/discordianfish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/discordianfish/subscriptions","organizations_url":"https://api.github.com/users/discordianfish/orgs","repos_url":"https://api.github.com/users/discordianfish/repos","events_url":"https://api.github.com/users/discordianfish/events{/privacy}","received_events_url":"https://api.github.com/users/discordianfish/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/discordianfish/cadvisor","description":"Analyzes resource usage and performance characteristics of running containers.","fork":true,"url":"https://api.github.com/repos/discordianfish/cadvisor","forks_url":"https://api.github.com/repos/discordianfish/cadvisor/forks","keys_url":"https://api.github.com/repos/discordianfish/cadvisor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/discordianfish/cadvisor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/discordianfish/cadvisor/teams","hooks_url":"https://api.github.com/repos/discordianfish/cadvisor/hooks","issue_events_url":"https://api.github.com/repos/discordianfish/cadvisor/issues/events{/number}","events_url":"https://api.github.com/repos/discordianfish/cadvisor/events","assignees_url":"https://api.github.com/repos/discordianfish/cadvisor/assignees{/user}","branches_url":"https://api.github.com/repos/discordianfish/cadvisor/branches{/branch}","tags_url":"https://api.github.com/repos/discordianfish/cadvisor/tags","blobs_url":"https://api.github.com/repos/discordianfish/cadvisor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/discordianfish/cadvisor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/discordianfish/cadvisor/git/refs{/sha}","trees_url":"https://api.github.com/repos/discordianfish/cadvisor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/discordianfish/cadvisor/statuses/{sha}","languages_url":"https://api.github.com/repos/discordianfish/cadvisor/languages","stargazers_url":"https://api.github.com/repos/discordianfish/cadvisor/stargazers","contributors_url":"https://api.github.com/repos/discordianfish/cadvisor/contributors","subscribers_url":"https://api.github.com/repos/discordianfish/cadvisor/subscribers","subscription_url":"https://api.github.com/repos/discordianfish/cadvisor/subscription","commits_url":"https://api.github.com/repos/discordianfish/cadvisor/commits{/sha}","git_commits_url":"https://api.github.com/repos/discordianfish/cadvisor/git/commits{/sha}","comments_url":"https://api.github.com/repos/discordianfish/cadvisor/comments{/number}","issue_comment_url":"https://api.github.com/repos/discordianfish/cadvisor/issues/comments{/number}","contents_url":"https://api.github.com/repos/discordianfish/cadvisor/contents/{+path}","compare_url":"https://api.github.com/repos/discordianfish/cadvisor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/discordianfish/cadvisor/merges","archive_url":"https://api.github.com/repos/discordianfish/cadvisor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/discordianfish/cadvisor/downloads","issues_url":"https://api.github.com/repos/discordianfish/cadvisor/issues{/number}","pulls_url":"https://api.github.com/repos/discordianfish/cadvisor/pulls{/number}","milestones_url":"https://api.github.com/repos/discordianfish/cadvisor/milestones{/number}","notifications_url":"https://api.github.com/repos/discordianfish/cadvisor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/discordianfish/cadvisor/labels{/name}","releases_url":"https://api.github.com/repos/discordianfish/cadvisor/releases{/id}","created_at":"2015-02-27T13:58:01Z","updated_at":"2015-02-27T13:58:02Z","pushed_at":"2015-02-27T14:05:08Z","git_url":"git://github.com/discordianfish/cadvisor.git","ssh_url":"git@github.com:discordianfish/cadvisor.git","clone_url":"https://github.com/discordianfish/cadvisor.git","svn_url":"https://github.com/discordianfish/cadvisor","homepage":"","size":20283,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"google:master","ref":"master","sha":"e89739e05a1af5256ceab3993119c2409b830a4d","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":20653934,"name":"cadvisor","full_name":"google/cadvisor","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/cadvisor","description":"Analyzes resource usage and performance characteristics of running containers.","fork":false,"url":"https://api.github.com/repos/google/cadvisor","forks_url":"https://api.github.com/repos/google/cadvisor/forks","keys_url":"https://api.github.com/repos/google/cadvisor/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/cadvisor/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/cadvisor/teams","hooks_url":"https://api.github.com/repos/google/cadvisor/hooks","issue_events_url":"https://api.github.com/repos/google/cadvisor/issues/events{/number}","events_url":"https://api.github.com/repos/google/cadvisor/events","assignees_url":"https://api.github.com/repos/google/cadvisor/assignees{/user}","branches_url":"https://api.github.com/repos/google/cadvisor/branches{/branch}","tags_url":"https://api.github.com/repos/google/cadvisor/tags","blobs_url":"https://api.github.com/repos/google/cadvisor/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/cadvisor/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/cadvisor/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/cadvisor/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/cadvisor/statuses/{sha}","languages_url":"https://api.github.com/repos/google/cadvisor/languages","stargazers_url":"https://api.github.com/repos/google/cadvisor/stargazers","contributors_url":"https://api.github.com/repos/google/cadvisor/contributors","subscribers_url":"https://api.github.com/repos/google/cadvisor/subscribers","subscription_url":"https://api.github.com/repos/google/cadvisor/subscription","commits_url":"https://api.github.com/repos/google/cadvisor/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/cadvisor/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/cadvisor/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/cadvisor/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/cadvisor/contents/{+path}","compare_url":"https://api.github.com/repos/google/cadvisor/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/cadvisor/merges","archive_url":"https://api.github.com/repos/google/cadvisor/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/cadvisor/downloads","issues_url":"https://api.github.com/repos/google/cadvisor/issues{/number}","pulls_url":"https://api.github.com/repos/google/cadvisor/pulls{/number}","milestones_url":"https://api.github.com/repos/google/cadvisor/milestones{/number}","notifications_url":"https://api.github.com/repos/google/cadvisor/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/cadvisor/labels{/name}","releases_url":"https://api.github.com/repos/google/cadvisor/releases{/id}","created_at":"2014-06-09T16:36:33Z","updated_at":"2015-02-27T09:27:26Z","pushed_at":"2015-02-27T03:24:22Z","git_url":"git://github.com/google/cadvisor.git","ssh_url":"git@github.com:google/cadvisor.git","clone_url":"https://github.com/google/cadvisor.git","svn_url":"https://github.com/google/cadvisor","homepage":"","size":20283,"stargazers_count":1916,"watchers_count":1916,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":188,"mirror_url":null,"open_issues_count":35,"forks":188,"open_issues":35,"watchers":1916,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/cadvisor/pulls/545"},"html":{"href":"https://github.com/google/cadvisor/pull/545"},"issue":{"href":"https://api.github.com/repos/google/cadvisor/issues/545"},"comments":{"href":"https://api.github.com/repos/google/cadvisor/issues/545/comments"},"review_comments":{"href":"https://api.github.com/repos/google/cadvisor/pulls/545/comments"},"review_comment":{"href":"https://api.github.com/repos/google/cadvisor/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/cadvisor/pulls/545/commits"},"statuses":{"href":"https://api.github.com/repos/google/cadvisor/statuses/aa2e3c7bbb8663ae8a703bf09e541f6c7828bed3"}}}}