{"action":"created","comment":{"url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments/34201206","id":34201206,"diff_hunk":"@@ -179,6 +182,104 @@ func setHostName() error {\n \treturn nil\n }\n \n+type agMetric struct {\n+\tmetric string\n+\tts     opentsdb.TagSet\n+\tvalues []float64\n+}\n+\n+func AggregateMeta(metric string, desc string, rateType metadata.RateType, unit metadata.Unit) {\n+\tagStrings := []string{\"avg\", \"count\", \"min\", \"median\", \"max\", \"95\", \"99\"}\n+\tfor _, ag := range agStrings {\n+\t\tmetadata.AddMetricMeta(metric+\"_\"+ag, rateType, unit, desc)\n+\t}\n+}\n+\n+func (am *agMetric) Process(now int64) {\n+\tvar avg float64\n+\tfor _, v := range am.values {\n+\t\tavg += v\n+\t}\n+\tavg /= float64(len(am.values))\n+\textRoot := metricRoot + am.metric\n+\ttchan <- &opentsdb.DataPoint{\n+\t\tMetric:    extRoot + \"_avg\",\n+\t\tTimestamp: now,\n+\t\tValue:     avg,\n+\t\tTags:      am.ts,\n+\t}\n+\ttchan <- &opentsdb.DataPoint{\n+\t\tMetric:    extRoot + \"_count\",\n+\t\tTimestamp: now,\n+\t\tValue:     len(am.values),\n+\t\tTags:      am.ts,\n+\t}\n+\ttchan <- &opentsdb.DataPoint{\n+\t\tMetric:    extRoot + \"_min\",\n+\t\tTimestamp: now,\n+\t\tValue:     percentile(am.values, 0),\n+\t\tTags:      am.ts,\n+\t}\n+\ttchan <- &opentsdb.DataPoint{\n+\t\tMetric:    extRoot + \"_median\",\n+\t\tTimestamp: now,\n+\t\tValue:     percentile(am.values, .5),\n+\t\tTags:      am.ts,\n+\t}\n+\ttchan <- &opentsdb.DataPoint{\n+\t\tMetric:    extRoot + \"_max\",\n+\t\tTimestamp: now,\n+\t\tValue:     percentile(am.values, 1),\n+\t\tTags:      am.ts,\n+\t}\n+\ttchan <- &opentsdb.DataPoint{\n+\t\tMetric:    extRoot + \"_95\",\n+\t\tTimestamp: now,\n+\t\tValue:     percentile(am.values, .95),\n+\t\tTags:      am.ts,\n+\t}\n+\ttchan <- &opentsdb.DataPoint{\n+\t\tMetric:    extRoot + \"_99\",\n+\t\tTimestamp: now,\n+\t\tValue:     percentile(am.values, .99),\n+\t\tTags:      am.ts,\n+\t}\n+}\n+\n+func percentile(dps []float64, p float64) (a float64) {\n+\tvar x []float64\n+\tfor _, v := range dps {\n+\t\tx = append(x, v)\n+\t}\n+\tsort.Float64s(x)\n+\tif p <= 0 {\n+\t\treturn x[0]","path":"collect/collect.go","position":96,"original_position":96,"commit_id":"a44ad58708632c2f4392bac0e80b12f082f39d0c","original_commit_id":"a44ad58708632c2f4392bac0e80b12f082f39d0c","user":{"login":"captncraig","id":192540,"avatar_url":"https://avatars.githubusercontent.com/u/192540?v=3","gravatar_id":"","url":"https://api.github.com/users/captncraig","html_url":"https://github.com/captncraig","followers_url":"https://api.github.com/users/captncraig/followers","following_url":"https://api.github.com/users/captncraig/following{/other_user}","gists_url":"https://api.github.com/users/captncraig/gists{/gist_id}","starred_url":"https://api.github.com/users/captncraig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/captncraig/subscriptions","organizations_url":"https://api.github.com/users/captncraig/orgs","repos_url":"https://api.github.com/users/captncraig/repos","events_url":"https://api.github.com/users/captncraig/events{/privacy}","received_events_url":"https://api.github.com/users/captncraig/received_events","type":"User","site_admin":false},"body":"this could out of bounds if len == 0","created_at":"2015-07-08T21:30:52Z","updated_at":"2015-07-08T21:30:52Z","html_url":"https://github.com/bosun-monitor/bosun/pull/1148#discussion_r34201206","pull_request_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1148","_links":{"self":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments/34201206"},"html":{"href":"https://github.com/bosun-monitor/bosun/pull/1148#discussion_r34201206"},"pull_request":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1148"}}},"pull_request":{"url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1148","id":39511452,"html_url":"https://github.com/bosun-monitor/bosun/pull/1148","diff_url":"https://github.com/bosun-monitor/bosun/pull/1148.diff","patch_url":"https://github.com/bosun-monitor/bosun/pull/1148.patch","issue_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/1148","number":1148,"state":"open","locked":false,"title":"collect: Add aggregation support to collect","user":{"login":"kylebrandt","id":1692624,"avatar_url":"https://avatars.githubusercontent.com/u/1692624?v=3","gravatar_id":"","url":"https://api.github.com/users/kylebrandt","html_url":"https://github.com/kylebrandt","followers_url":"https://api.github.com/users/kylebrandt/followers","following_url":"https://api.github.com/users/kylebrandt/following{/other_user}","gists_url":"https://api.github.com/users/kylebrandt/gists{/gist_id}","starred_url":"https://api.github.com/users/kylebrandt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kylebrandt/subscriptions","organizations_url":"https://api.github.com/users/kylebrandt/orgs","repos_url":"https://api.github.com/users/kylebrandt/repos","events_url":"https://api.github.com/users/kylebrandt/events{/privacy}","received_events_url":"https://api.github.com/users/kylebrandt/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-08T19:03:53Z","updated_at":"2015-07-08T21:30:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e133cc1432363cdc688e4a569df756667dab30a4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1148/commits","review_comments_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1148/comments","review_comment_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/1148/comments","statuses_url":"https://api.github.com/repos/bosun-monitor/bosun/statuses/a44ad58708632c2f4392bac0e80b12f082f39d0c","head":{"label":"bosun-monitor:collectAgg","ref":"collectAgg","sha":"a44ad58708632c2f4392bac0e80b12f082f39d0c","user":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"repo":{"id":14410778,"name":"bosun","full_name":"bosun-monitor/bosun","owner":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bosun-monitor/bosun","description":"Time Series Alerting Framework","fork":false,"url":"https://api.github.com/repos/bosun-monitor/bosun","forks_url":"https://api.github.com/repos/bosun-monitor/bosun/forks","keys_url":"https://api.github.com/repos/bosun-monitor/bosun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bosun-monitor/bosun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bosun-monitor/bosun/teams","hooks_url":"https://api.github.com/repos/bosun-monitor/bosun/hooks","issue_events_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/events{/number}","events_url":"https://api.github.com/repos/bosun-monitor/bosun/events","assignees_url":"https://api.github.com/repos/bosun-monitor/bosun/assignees{/user}","branches_url":"https://api.github.com/repos/bosun-monitor/bosun/branches{/branch}","tags_url":"https://api.github.com/repos/bosun-monitor/bosun/tags","blobs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bosun-monitor/bosun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/refs{/sha}","trees_url":"https://api.github.com/repos/bosun-monitor/bosun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bosun-monitor/bosun/statuses/{sha}","languages_url":"https://api.github.com/repos/bosun-monitor/bosun/languages","stargazers_url":"https://api.github.com/repos/bosun-monitor/bosun/stargazers","contributors_url":"https://api.github.com/repos/bosun-monitor/bosun/contributors","subscribers_url":"https://api.github.com/repos/bosun-monitor/bosun/subscribers","subscription_url":"https://api.github.com/repos/bosun-monitor/bosun/subscription","commits_url":"https://api.github.com/repos/bosun-monitor/bosun/commits{/sha}","git_commits_url":"https://api.github.com/repos/bosun-monitor/bosun/git/commits{/sha}","comments_url":"https://api.github.com/repos/bosun-monitor/bosun/comments{/number}","issue_comment_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/comments{/number}","contents_url":"https://api.github.com/repos/bosun-monitor/bosun/contents/{+path}","compare_url":"https://api.github.com/repos/bosun-monitor/bosun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bosun-monitor/bosun/merges","archive_url":"https://api.github.com/repos/bosun-monitor/bosun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bosun-monitor/bosun/downloads","issues_url":"https://api.github.com/repos/bosun-monitor/bosun/issues{/number}","pulls_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls{/number}","milestones_url":"https://api.github.com/repos/bosun-monitor/bosun/milestones{/number}","notifications_url":"https://api.github.com/repos/bosun-monitor/bosun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bosun-monitor/bosun/labels{/name}","releases_url":"https://api.github.com/repos/bosun-monitor/bosun/releases{/id}","created_at":"2013-11-15T00:12:27Z","updated_at":"2015-07-08T10:29:00Z","pushed_at":"2015-07-08T19:25:14Z","git_url":"git://github.com/bosun-monitor/bosun.git","ssh_url":"git@github.com:bosun-monitor/bosun.git","clone_url":"https://github.com/bosun-monitor/bosun.git","svn_url":"https://github.com/bosun-monitor/bosun","homepage":"http://bosun.org","size":42088,"stargazers_count":985,"watchers_count":985,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":118,"mirror_url":null,"open_issues_count":188,"forks":118,"open_issues":188,"watchers":985,"default_branch":"master"}},"base":{"label":"bosun-monitor:master","ref":"master","sha":"8b19f3eb4591c7f3af9bae1fe9106566857bcc6d","user":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"repo":{"id":14410778,"name":"bosun","full_name":"bosun-monitor/bosun","owner":{"login":"bosun-monitor","id":9555242,"avatar_url":"https://avatars.githubusercontent.com/u/9555242?v=3","gravatar_id":"","url":"https://api.github.com/users/bosun-monitor","html_url":"https://github.com/bosun-monitor","followers_url":"https://api.github.com/users/bosun-monitor/followers","following_url":"https://api.github.com/users/bosun-monitor/following{/other_user}","gists_url":"https://api.github.com/users/bosun-monitor/gists{/gist_id}","starred_url":"https://api.github.com/users/bosun-monitor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bosun-monitor/subscriptions","organizations_url":"https://api.github.com/users/bosun-monitor/orgs","repos_url":"https://api.github.com/users/bosun-monitor/repos","events_url":"https://api.github.com/users/bosun-monitor/events{/privacy}","received_events_url":"https://api.github.com/users/bosun-monitor/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bosun-monitor/bosun","description":"Time Series Alerting Framework","fork":false,"url":"https://api.github.com/repos/bosun-monitor/bosun","forks_url":"https://api.github.com/repos/bosun-monitor/bosun/forks","keys_url":"https://api.github.com/repos/bosun-monitor/bosun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bosun-monitor/bosun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bosun-monitor/bosun/teams","hooks_url":"https://api.github.com/repos/bosun-monitor/bosun/hooks","issue_events_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/events{/number}","events_url":"https://api.github.com/repos/bosun-monitor/bosun/events","assignees_url":"https://api.github.com/repos/bosun-monitor/bosun/assignees{/user}","branches_url":"https://api.github.com/repos/bosun-monitor/bosun/branches{/branch}","tags_url":"https://api.github.com/repos/bosun-monitor/bosun/tags","blobs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bosun-monitor/bosun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bosun-monitor/bosun/git/refs{/sha}","trees_url":"https://api.github.com/repos/bosun-monitor/bosun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bosun-monitor/bosun/statuses/{sha}","languages_url":"https://api.github.com/repos/bosun-monitor/bosun/languages","stargazers_url":"https://api.github.com/repos/bosun-monitor/bosun/stargazers","contributors_url":"https://api.github.com/repos/bosun-monitor/bosun/contributors","subscribers_url":"https://api.github.com/repos/bosun-monitor/bosun/subscribers","subscription_url":"https://api.github.com/repos/bosun-monitor/bosun/subscription","commits_url":"https://api.github.com/repos/bosun-monitor/bosun/commits{/sha}","git_commits_url":"https://api.github.com/repos/bosun-monitor/bosun/git/commits{/sha}","comments_url":"https://api.github.com/repos/bosun-monitor/bosun/comments{/number}","issue_comment_url":"https://api.github.com/repos/bosun-monitor/bosun/issues/comments{/number}","contents_url":"https://api.github.com/repos/bosun-monitor/bosun/contents/{+path}","compare_url":"https://api.github.com/repos/bosun-monitor/bosun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bosun-monitor/bosun/merges","archive_url":"https://api.github.com/repos/bosun-monitor/bosun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bosun-monitor/bosun/downloads","issues_url":"https://api.github.com/repos/bosun-monitor/bosun/issues{/number}","pulls_url":"https://api.github.com/repos/bosun-monitor/bosun/pulls{/number}","milestones_url":"https://api.github.com/repos/bosun-monitor/bosun/milestones{/number}","notifications_url":"https://api.github.com/repos/bosun-monitor/bosun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bosun-monitor/bosun/labels{/name}","releases_url":"https://api.github.com/repos/bosun-monitor/bosun/releases{/id}","created_at":"2013-11-15T00:12:27Z","updated_at":"2015-07-08T10:29:00Z","pushed_at":"2015-07-08T19:25:14Z","git_url":"git://github.com/bosun-monitor/bosun.git","ssh_url":"git@github.com:bosun-monitor/bosun.git","clone_url":"https://github.com/bosun-monitor/bosun.git","svn_url":"https://github.com/bosun-monitor/bosun","homepage":"http://bosun.org","size":42088,"stargazers_count":985,"watchers_count":985,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":118,"mirror_url":null,"open_issues_count":188,"forks":118,"open_issues":188,"watchers":985,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1148"},"html":{"href":"https://github.com/bosun-monitor/bosun/pull/1148"},"issue":{"href":"https://api.github.com/repos/bosun-monitor/bosun/issues/1148"},"comments":{"href":"https://api.github.com/repos/bosun-monitor/bosun/issues/1148/comments"},"review_comments":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1148/comments"},"review_comment":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bosun-monitor/bosun/pulls/1148/commits"},"statuses":{"href":"https://api.github.com/repos/bosun-monitor/bosun/statuses/a44ad58708632c2f4392bac0e80b12f082f39d0c"}}}}