{"action":"created","comment":{"url":"https://api.github.com/repos/Yelp/fullerite/pulls/comments/43966974","id":43966974,"diff_hunk":"@@ -0,0 +1,194 @@\n+package collector\n+\n+import (\n+\t\"fullerite/metric\"\n+\n+\t\"strings\"\n+\n+\t\"time\"\n+\n+\tl \"github.com/Sirupsen/logrus\"\n+\n+\t\"github.com/fsouza/go-dockerclient\"\n+)\n+\n+const (\n+\tmesosTaskID    = \"MESOS_TASK_ID\"\n+\tendpoint       = \"unix:///var/run/docker.sock\"\n+\ttimeoutChannel = 7\n+)\n+\n+// DockerStats collector type.\n+// previousCPUValues contains the last cpu-usage values per container.\n+// dockerClient is the client for the Docker remote API.\n+type DockerStats struct {\n+\tbaseCollector\n+\tpreviousCPUValues map[string]*CPUValues\n+\tdockerClient      *docker.Client\n+}\n+\n+// CPUValues struct contains the last cpu-usage values in order to compute properly the current values.\n+// (see calculateCPUPercent() for more details)\n+type CPUValues struct {\n+\ttotCPU, systemCPU float64\n+}\n+\n+// NewDockerStats creates a new Test collector.\n+func NewDockerStats(channel chan metric.Metric, initialInterval int, log *l.Entry) *DockerStats {\n+\td := new(DockerStats)\n+\n+\td.log = log\n+\td.channel = channel\n+\td.interval = initialInterval\n+\td.name = \"DockerStats\"\n+\td.previousCPUValues = make(map[string]*CPUValues)\n+\td.dockerClient, _ = docker.NewClient(endpoint)\n+\n+\treturn d\n+}\n+\n+// Configure takes a dictionary of values with which the handler can configure itself.\n+func (d *DockerStats) Configure(configMap map[string]interface{}) {\n+\td.configureCommonParams(configMap)\n+}\n+\n+// Collect iterates on all the docker containers alive and, if possible, collects the correspondent\n+// memory and cpu statistics.\n+// For each container a gorutine is started to spin up the collection process.\n+func (d DockerStats) Collect() {\n+\tcontainerArray, err := d.dockerClient.ListContainers(docker.ListContainersOptions{All: false})\n+\tif err != nil {\n+\t\td.log.Error(\"Impossible reach the docker client\", err)\n+\t\treturn\n+\t}\n+\tresults := make(chan int, len(containerArray))\n+\tfor _, APIContainer := range containerArray {\n+\t\tcontainer, err := d.dockerClient.InspectContainer(APIContainer.ID)\n+\t\tif err != nil {\n+\t\t\td.log.Error(\"Not possible inspect container\", err)\n+\t\t\tresults <- 0\n+\t\t\tcontinue\n+\t\t}\n+\t\tif _, ok := d.previousCPUValues[container.ID]; !ok {\n+\t\t\td.previousCPUValues[container.ID] = new(CPUValues)\n+\t\t}\n+\t\tgo d.GetDockerContainerInfo(container, results)\n+\t}\n+\tfor i := 0; i < len(containerArray); i++ {\n+\t\t<-results\n+\t}\n+\tclose(results)\n+}\n+\n+// GetDockerContainerInfo gets container statistics for the given container.\n+// results is a channel to make possible the synchronization between the main process and the gorutines (wait-notify pattern).\n+func (d DockerStats) GetDockerContainerInfo(container *docker.Container, results chan<- int) {\n+\terrC := make(chan error, 1)\n+\tstatsC := make(chan *docker.Stats, 1)\n+\tdone := make(chan bool)\n+\n+\tgo func() {\n+\t\terrC <- d.dockerClient.Stats(docker.StatsOptions{container.ID, statsC, false, done, time.Second * 8})","path":"src/fullerite/collector/docker_stats.go","position":91,"original_position":91,"commit_id":"41e3994cdb5d52b7238da37fd57aa03230386e5c","original_commit_id":"41e3994cdb5d52b7238da37fd57aa03230386e5c","user":{"login":"dichiarafrancesco","id":10674587,"avatar_url":"https://avatars.githubusercontent.com/u/10674587?v=3","gravatar_id":"","url":"https://api.github.com/users/dichiarafrancesco","html_url":"https://github.com/dichiarafrancesco","followers_url":"https://api.github.com/users/dichiarafrancesco/followers","following_url":"https://api.github.com/users/dichiarafrancesco/following{/other_user}","gists_url":"https://api.github.com/users/dichiarafrancesco/gists{/gist_id}","starred_url":"https://api.github.com/users/dichiarafrancesco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dichiarafrancesco/subscriptions","organizations_url":"https://api.github.com/users/dichiarafrancesco/orgs","repos_url":"https://api.github.com/users/dichiarafrancesco/repos","events_url":"https://api.github.com/users/dichiarafrancesco/events{/privacy}","received_events_url":"https://api.github.com/users/dichiarafrancesco/received_events","type":"User","site_admin":false},"body":"it will be 0","created_at":"2015-11-05T01:34:20Z","updated_at":"2015-11-05T01:34:20Z","html_url":"https://github.com/Yelp/fullerite/pull/73#discussion_r43966974","pull_request_url":"https://api.github.com/repos/Yelp/fullerite/pulls/73","_links":{"self":{"href":"https://api.github.com/repos/Yelp/fullerite/pulls/comments/43966974"},"html":{"href":"https://github.com/Yelp/fullerite/pull/73#discussion_r43966974"},"pull_request":{"href":"https://api.github.com/repos/Yelp/fullerite/pulls/73"}}},"pull_request":{"url":"https://api.github.com/repos/Yelp/fullerite/pulls/73","id":49745721,"html_url":"https://github.com/Yelp/fullerite/pull/73","diff_url":"https://github.com/Yelp/fullerite/pull/73.diff","patch_url":"https://github.com/Yelp/fullerite/pull/73.patch","issue_url":"https://api.github.com/repos/Yelp/fullerite/issues/73","number":73,"state":"open","locked":false,"title":"Add docker containers' reource statistics collector","user":{"login":"dichiarafrancesco","id":10674587,"avatar_url":"https://avatars.githubusercontent.com/u/10674587?v=3","gravatar_id":"","url":"https://api.github.com/users/dichiarafrancesco","html_url":"https://github.com/dichiarafrancesco","followers_url":"https://api.github.com/users/dichiarafrancesco/followers","following_url":"https://api.github.com/users/dichiarafrancesco/following{/other_user}","gists_url":"https://api.github.com/users/dichiarafrancesco/gists{/gist_id}","starred_url":"https://api.github.com/users/dichiarafrancesco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dichiarafrancesco/subscriptions","organizations_url":"https://api.github.com/users/dichiarafrancesco/orgs","repos_url":"https://api.github.com/users/dichiarafrancesco/repos","events_url":"https://api.github.com/users/dichiarafrancesco/events{/privacy}","received_events_url":"https://api.github.com/users/dichiarafrancesco/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-04T21:09:17Z","updated_at":"2015-11-05T01:34:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1697c45a98852b2463a7a72c8198d95cfeb11646","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Yelp/fullerite/pulls/73/commits","review_comments_url":"https://api.github.com/repos/Yelp/fullerite/pulls/73/comments","review_comment_url":"https://api.github.com/repos/Yelp/fullerite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Yelp/fullerite/issues/73/comments","statuses_url":"https://api.github.com/repos/Yelp/fullerite/statuses/41e3994cdb5d52b7238da37fd57aa03230386e5c","head":{"label":"dichiarafrancesco:fdc_dockerStatsCollector","ref":"fdc_dockerStatsCollector","sha":"41e3994cdb5d52b7238da37fd57aa03230386e5c","user":{"login":"dichiarafrancesco","id":10674587,"avatar_url":"https://avatars.githubusercontent.com/u/10674587?v=3","gravatar_id":"","url":"https://api.github.com/users/dichiarafrancesco","html_url":"https://github.com/dichiarafrancesco","followers_url":"https://api.github.com/users/dichiarafrancesco/followers","following_url":"https://api.github.com/users/dichiarafrancesco/following{/other_user}","gists_url":"https://api.github.com/users/dichiarafrancesco/gists{/gist_id}","starred_url":"https://api.github.com/users/dichiarafrancesco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dichiarafrancesco/subscriptions","organizations_url":"https://api.github.com/users/dichiarafrancesco/orgs","repos_url":"https://api.github.com/users/dichiarafrancesco/repos","events_url":"https://api.github.com/users/dichiarafrancesco/events{/privacy}","received_events_url":"https://api.github.com/users/dichiarafrancesco/received_events","type":"User","site_admin":false},"repo":{"id":45135996,"name":"fullerite","full_name":"dichiarafrancesco/fullerite","owner":{"login":"dichiarafrancesco","id":10674587,"avatar_url":"https://avatars.githubusercontent.com/u/10674587?v=3","gravatar_id":"","url":"https://api.github.com/users/dichiarafrancesco","html_url":"https://github.com/dichiarafrancesco","followers_url":"https://api.github.com/users/dichiarafrancesco/followers","following_url":"https://api.github.com/users/dichiarafrancesco/following{/other_user}","gists_url":"https://api.github.com/users/dichiarafrancesco/gists{/gist_id}","starred_url":"https://api.github.com/users/dichiarafrancesco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dichiarafrancesco/subscriptions","organizations_url":"https://api.github.com/users/dichiarafrancesco/orgs","repos_url":"https://api.github.com/users/dichiarafrancesco/repos","events_url":"https://api.github.com/users/dichiarafrancesco/events{/privacy}","received_events_url":"https://api.github.com/users/dichiarafrancesco/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dichiarafrancesco/fullerite","description":"Fullerite is a daemon which collect metrics periodically from various sources and sends them to different metric stores. Fullerite's pluggable architecture allows the users to implement collectors and handlers as they wish.","fork":true,"url":"https://api.github.com/repos/dichiarafrancesco/fullerite","forks_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/forks","keys_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/teams","hooks_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/hooks","issue_events_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/issues/events{/number}","events_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/events","assignees_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/assignees{/user}","branches_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/branches{/branch}","tags_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/tags","blobs_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/git/refs{/sha}","trees_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/statuses/{sha}","languages_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/languages","stargazers_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/stargazers","contributors_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/contributors","subscribers_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/subscribers","subscription_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/subscription","commits_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/commits{/sha}","git_commits_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/git/commits{/sha}","comments_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/comments{/number}","issue_comment_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/issues/comments{/number}","contents_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/contents/{+path}","compare_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/merges","archive_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/downloads","issues_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/issues{/number}","pulls_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/pulls{/number}","milestones_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/milestones{/number}","notifications_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/labels{/name}","releases_url":"https://api.github.com/repos/dichiarafrancesco/fullerite/releases{/id}","created_at":"2015-10-28T19:12:21Z","updated_at":"2015-10-28T19:12:23Z","pushed_at":"2015-11-04T21:05:15Z","git_url":"git://github.com/dichiarafrancesco/fullerite.git","ssh_url":"git@github.com:dichiarafrancesco/fullerite.git","clone_url":"https://github.com/dichiarafrancesco/fullerite.git","svn_url":"https://github.com/dichiarafrancesco/fullerite","homepage":"","size":1020,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"Yelp:master","ref":"master","sha":"6ece98a9b94e721f9ce98f96289108773bbdf956","user":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"repo":{"id":39368384,"name":"fullerite","full_name":"Yelp/fullerite","owner":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yelp/fullerite","description":"Fullerite is a daemon which collect metrics periodically from various sources and sends them to different metric stores. Fullerite's pluggable architecture allows the users to implement collectors and handlers as they wish.","fork":false,"url":"https://api.github.com/repos/Yelp/fullerite","forks_url":"https://api.github.com/repos/Yelp/fullerite/forks","keys_url":"https://api.github.com/repos/Yelp/fullerite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yelp/fullerite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yelp/fullerite/teams","hooks_url":"https://api.github.com/repos/Yelp/fullerite/hooks","issue_events_url":"https://api.github.com/repos/Yelp/fullerite/issues/events{/number}","events_url":"https://api.github.com/repos/Yelp/fullerite/events","assignees_url":"https://api.github.com/repos/Yelp/fullerite/assignees{/user}","branches_url":"https://api.github.com/repos/Yelp/fullerite/branches{/branch}","tags_url":"https://api.github.com/repos/Yelp/fullerite/tags","blobs_url":"https://api.github.com/repos/Yelp/fullerite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yelp/fullerite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yelp/fullerite/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yelp/fullerite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yelp/fullerite/statuses/{sha}","languages_url":"https://api.github.com/repos/Yelp/fullerite/languages","stargazers_url":"https://api.github.com/repos/Yelp/fullerite/stargazers","contributors_url":"https://api.github.com/repos/Yelp/fullerite/contributors","subscribers_url":"https://api.github.com/repos/Yelp/fullerite/subscribers","subscription_url":"https://api.github.com/repos/Yelp/fullerite/subscription","commits_url":"https://api.github.com/repos/Yelp/fullerite/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yelp/fullerite/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yelp/fullerite/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yelp/fullerite/issues/comments{/number}","contents_url":"https://api.github.com/repos/Yelp/fullerite/contents/{+path}","compare_url":"https://api.github.com/repos/Yelp/fullerite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yelp/fullerite/merges","archive_url":"https://api.github.com/repos/Yelp/fullerite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yelp/fullerite/downloads","issues_url":"https://api.github.com/repos/Yelp/fullerite/issues{/number}","pulls_url":"https://api.github.com/repos/Yelp/fullerite/pulls{/number}","milestones_url":"https://api.github.com/repos/Yelp/fullerite/milestones{/number}","notifications_url":"https://api.github.com/repos/Yelp/fullerite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yelp/fullerite/labels{/name}","releases_url":"https://api.github.com/repos/Yelp/fullerite/releases{/id}","created_at":"2015-07-20T07:01:49Z","updated_at":"2015-11-04T18:17:07Z","pushed_at":"2015-11-04T21:09:18Z","git_url":"git://github.com/Yelp/fullerite.git","ssh_url":"git@github.com:Yelp/fullerite.git","clone_url":"https://github.com/Yelp/fullerite.git","svn_url":"https://github.com/Yelp/fullerite","homepage":"","size":1800,"stargazers_count":81,"watchers_count":81,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":16,"forks":19,"open_issues":16,"watchers":81,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Yelp/fullerite/pulls/73"},"html":{"href":"https://github.com/Yelp/fullerite/pull/73"},"issue":{"href":"https://api.github.com/repos/Yelp/fullerite/issues/73"},"comments":{"href":"https://api.github.com/repos/Yelp/fullerite/issues/73/comments"},"review_comments":{"href":"https://api.github.com/repos/Yelp/fullerite/pulls/73/comments"},"review_comment":{"href":"https://api.github.com/repos/Yelp/fullerite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Yelp/fullerite/pulls/73/commits"},"statuses":{"href":"https://api.github.com/repos/Yelp/fullerite/statuses/41e3994cdb5d52b7238da37fd57aa03230386e5c"}}}}