{"action":"created","comment":{"url":"https://api.github.com/repos/influxdata/telegraf/pulls/comments/74055374","id":74055374,"diff_hunk":"@@ -0,0 +1,441 @@\n+package spark\n+\n+import (\n+\t\"encoding/json\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"io/ioutil\"\n+\t\"log\"\n+\t\"net/http\"\n+\t\"net/url\"\n+\t\"strings\"\n+\t\"sync\"\n+\n+\t\"github.com/influxdata/telegraf\"\n+\t\"github.com/influxdata/telegraf/plugins/inputs\"\n+)\n+\n+type JolokiaClient interface {\n+\tMakeRequest(req *http.Request) (*http.Response, error)\n+}\n+\n+type JolokiaClientImpl struct {\n+\tclient *http.Client\n+}\n+\n+func (c JolokiaClientImpl) MakeRequest(req *http.Request) (*http.Response, error) {\n+\treturn c.client.Do(req)\n+}\n+\n+type YarnClient interface {\n+\tMakeRequest(req *http.Request) (*http.Response, error)\n+}\n+\n+type YarnClientImpl struct {\n+\tclient *http.Client\n+}\n+\n+func (c YarnClientImpl) MakeRequest(req *http.Request) (*http.Response, error) {\n+\treturn c.client.Do(req)\n+}\n+\n+type Spark struct {\n+\tjClient     JolokiaClient\n+\tSparkServer []string\n+\tYarnServer  string\n+}\n+\n+type javaMetric struct {\n+\thost   string\n+\tmetric string\n+\tacc    telegraf.Accumulator\n+}\n+\n+type sparkMetric struct {\n+\thost   string\n+\tmetric string\n+\tacc    telegraf.Accumulator\n+}\n+\n+type Yarn struct {\n+\tyClient       YarnClient\n+\tserverAddress string\n+}\n+\n+type yarnMetric struct {\n+\thost string\n+\tacc  telegraf.Accumulator\n+}\n+\n+type jmxMetric interface {\n+\taddTagsFields(out map[string]interface{})\n+}\n+\n+func newJavaMetric(host string, metric string,\n+\tacc telegraf.Accumulator) *javaMetric {\n+\treturn &javaMetric{host: host, metric: metric, acc: acc}\n+}\n+\n+func newSparkMetric(host string, metric string,\n+\tacc telegraf.Accumulator) *sparkMetric {\n+\treturn &sparkMetric{host: host, metric: metric, acc: acc}\n+}\n+\n+func newYarnMetric(host string, acc telegraf.Accumulator) *yarnMetric {\n+\treturn &yarnMetric{host: host, acc: acc}\n+}\n+\n+func addValuesAsFields(values map[string]interface{}, fields map[string]interface{},\n+\tmname string) {\n+\tfor k, v := range values {\n+\t\tif v != nil {\n+\t\t\tfields[mname+\"_\"+k] = v\n+\t\t}\n+\t}\n+}\n+\n+func parseJmxMetricRequest(mbean string) map[string]string {\n+\ttokens := make(map[string]string)\n+\tclassAndPairs := strings.Split(mbean, \":\")\n+\tif classAndPairs[0] == \"metrics\" {\n+\t\ttokens[\"class\"] = \"spark_jolokiaMetrics\"\n+\t} else if classAndPairs[0] == \"java.lang\" {\n+\t\ttokens[\"class\"] = \"java\"\n+\t} else {\n+\t\treturn tokens\n+\t}\n+\n+\tpair := strings.Split(classAndPairs[1], \"=\")\n+\ttokens[pair[0]] = pair[1]\n+\n+\treturn tokens\n+}\n+\n+func addTokensToTags(tokens map[string]string, tags map[string]string) {\n+\tfor k, v := range tokens {\n+\t\tif k == \"name\" {\n+\t\t\ttags[\"mname\"] = v // name seems to a reserved word in influxdb\n+\t\t} else if k == \"class\" || k == \"type\" {\n+\t\t\tcontinue // class and type are used in the metric name\n+\t\t} else {\n+\t\t\ttags[k] = v\n+\t\t}\n+\t}\n+}\n+\n+func addJavaMetric(class string, c javaMetric,\n+\tvalues map[string]interface{}) {\n+\n+\ttags := make(map[string]string)\n+\tfields := make(map[string]interface{})\n+\ttags[\"spark_host\"] = c.host\n+\ttags[\"spark_class\"] = class\n+\n+\tif class == \"spark_Threading\" {\n+\t\tlist := []string{\"PeakThreadCount\", \"CurrentThreadCpuTime\", \"DaemonThreadCount\", \"TotalStartedThreadCount\", \"CurrentThreadUserTime\", \"ThreadCount\"}\n+\t\tfor _, value := range list {\n+\t\t\tif values[value] != nil {\n+\t\t\t\tfields[value] = values[value]\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\tfor k, v := range values {\n+\t\t\tif v != nil {\n+\t\t\t\tfields[k] = v\n+\t\t\t}\n+\t\t}\n+\t}\n+\tc.acc.AddFields(class, fields, tags)\n+\n+}\n+\n+func (j javaMetric) addTagsFields(out map[string]interface{}) {\n+\tfmt.Println(out[\"request\"])\n+\trequest := out[\"request\"].(map[string]interface{})\n+\tvar mbean = request[\"mbean\"].(string)\n+\tvar mbeansplit = strings.Split(mbean, \"=\")\n+\tvar class = mbeansplit[1]\n+\n+\tif valuesMap, ok := out[\"value\"]; ok {\n+\t\tif class == \"Memory\" {\n+\t\t\taddJavaMetric(\"spark_HeapMemoryUsage\", j, valuesMap.(map[string]interface{}))\n+\t\t} else if class == \"Threading\" {\n+\t\t\taddJavaMetric(\"spark_Threading\", j, valuesMap.(map[string]interface{}))\n+\t\t} else {\n+\t\t\tfmt.Printf(\"Missing key in '%s' output response\\n%v\\n\",\n+\t\t\t\tj.metric, out)\n+\t\t\treturn\n+\t\t}\n+\n+\t}\n+}\n+\n+func addSparkMetric(mbean string, c sparkMetric,\n+\tvalues map[string]interface{}) {\n+\n+\ttags := make(map[string]string)\n+\tfields := make(map[string]interface{})\n+\n+\ttokens := parseJmxMetricRequest(mbean)\n+\taddTokensToTags(tokens, tags)\n+\ttags[\"spark_host\"] = c.host\n+\n+\taddValuesAsFields(values, fields, tags[\"mname\"])\n+\tc.acc.AddFields(tokens[\"class\"]+tokens[\"type\"], fields, tags)\n+\n+}\n+\n+func (c sparkMetric) addTagsFields(out map[string]interface{}) {","path":"plugins/inputs/spark/spark.go","position":188,"original_position":188,"commit_id":"cc781e560c1c51b08ac06c667ef7e8f1c3ab9e5c","original_commit_id":"cc781e560c1c51b08ac06c667ef7e8f1c3ab9e5c","user":{"login":"sparrc","id":7155926,"avatar_url":"https://avatars.githubusercontent.com/u/7155926?v=3","gravatar_id":"","url":"https://api.github.com/users/sparrc","html_url":"https://github.com/sparrc","followers_url":"https://api.github.com/users/sparrc/followers","following_url":"https://api.github.com/users/sparrc/following{/other_user}","gists_url":"https://api.github.com/users/sparrc/gists{/gist_id}","starred_url":"https://api.github.com/users/sparrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sparrc/subscriptions","organizations_url":"https://api.github.com/users/sparrc/orgs","repos_url":"https://api.github.com/users/sparrc/repos","events_url":"https://api.github.com/users/sparrc/events{/privacy}","received_events_url":"https://api.github.com/users/sparrc/received_events","type":"User","site_admin":false},"body":"why is this a value receiver?","created_at":"2016-08-09T13:18:27Z","updated_at":"2016-08-09T13:18:27Z","html_url":"https://github.com/influxdata/telegraf/pull/1611#discussion_r74055374","pull_request_url":"https://api.github.com/repos/influxdata/telegraf/pulls/1611","_links":{"self":{"href":"https://api.github.com/repos/influxdata/telegraf/pulls/comments/74055374"},"html":{"href":"https://github.com/influxdata/telegraf/pull/1611#discussion_r74055374"},"pull_request":{"href":"https://api.github.com/repos/influxdata/telegraf/pulls/1611"}}},"pull_request":{"url":"https://api.github.com/repos/influxdata/telegraf/pulls/1611","id":80603225,"html_url":"https://github.com/influxdata/telegraf/pull/1611","diff_url":"https://github.com/influxdata/telegraf/pull/1611.diff","patch_url":"https://github.com/influxdata/telegraf/pull/1611.patch","issue_url":"https://api.github.com/repos/influxdata/telegraf/issues/1611","number":1611,"state":"open","locked":false,"title":"Spark plugin","user":{"login":"ShubhamDX","id":8580600,"avatar_url":"https://avatars.githubusercontent.com/u/8580600?v=3","gravatar_id":"","url":"https://api.github.com/users/ShubhamDX","html_url":"https://github.com/ShubhamDX","followers_url":"https://api.github.com/users/ShubhamDX/followers","following_url":"https://api.github.com/users/ShubhamDX/following{/other_user}","gists_url":"https://api.github.com/users/ShubhamDX/gists{/gist_id}","starred_url":"https://api.github.com/users/ShubhamDX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShubhamDX/subscriptions","organizations_url":"https://api.github.com/users/ShubhamDX/orgs","repos_url":"https://api.github.com/users/ShubhamDX/repos","events_url":"https://api.github.com/users/ShubhamDX/events{/privacy}","received_events_url":"https://api.github.com/users/ShubhamDX/received_events","type":"User","site_admin":false},"body":"### Required for all PRs:\r\n\r\n- [x] CHANGELOG.md updated\r\n- [x] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed)\r\n","created_at":"2016-08-09T11:22:14Z","updated_at":"2016-08-09T13:18:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"387f2a41756f08d7c5230a26a614ea15640a84f7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/influxdata/telegraf/pulls/1611/commits","review_comments_url":"https://api.github.com/repos/influxdata/telegraf/pulls/1611/comments","review_comment_url":"https://api.github.com/repos/influxdata/telegraf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/influxdata/telegraf/issues/1611/comments","statuses_url":"https://api.github.com/repos/influxdata/telegraf/statuses/cc781e560c1c51b08ac06c667ef7e8f1c3ab9e5c","head":{"label":"ShubhamDX:sparkPlugin","ref":"sparkPlugin","sha":"cc781e560c1c51b08ac06c667ef7e8f1c3ab9e5c","user":{"login":"ShubhamDX","id":8580600,"avatar_url":"https://avatars.githubusercontent.com/u/8580600?v=3","gravatar_id":"","url":"https://api.github.com/users/ShubhamDX","html_url":"https://github.com/ShubhamDX","followers_url":"https://api.github.com/users/ShubhamDX/followers","following_url":"https://api.github.com/users/ShubhamDX/following{/other_user}","gists_url":"https://api.github.com/users/ShubhamDX/gists{/gist_id}","starred_url":"https://api.github.com/users/ShubhamDX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShubhamDX/subscriptions","organizations_url":"https://api.github.com/users/ShubhamDX/orgs","repos_url":"https://api.github.com/users/ShubhamDX/repos","events_url":"https://api.github.com/users/ShubhamDX/events{/privacy}","received_events_url":"https://api.github.com/users/ShubhamDX/received_events","type":"User","site_admin":false},"repo":{"id":65283392,"name":"telegraf","full_name":"ShubhamDX/telegraf","owner":{"login":"ShubhamDX","id":8580600,"avatar_url":"https://avatars.githubusercontent.com/u/8580600?v=3","gravatar_id":"","url":"https://api.github.com/users/ShubhamDX","html_url":"https://github.com/ShubhamDX","followers_url":"https://api.github.com/users/ShubhamDX/followers","following_url":"https://api.github.com/users/ShubhamDX/following{/other_user}","gists_url":"https://api.github.com/users/ShubhamDX/gists{/gist_id}","starred_url":"https://api.github.com/users/ShubhamDX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShubhamDX/subscriptions","organizations_url":"https://api.github.com/users/ShubhamDX/orgs","repos_url":"https://api.github.com/users/ShubhamDX/repos","events_url":"https://api.github.com/users/ShubhamDX/events{/privacy}","received_events_url":"https://api.github.com/users/ShubhamDX/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ShubhamDX/telegraf","description":"The plugin-driven server agent for collecting & reporting metrics.","fork":true,"url":"https://api.github.com/repos/ShubhamDX/telegraf","forks_url":"https://api.github.com/repos/ShubhamDX/telegraf/forks","keys_url":"https://api.github.com/repos/ShubhamDX/telegraf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ShubhamDX/telegraf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ShubhamDX/telegraf/teams","hooks_url":"https://api.github.com/repos/ShubhamDX/telegraf/hooks","issue_events_url":"https://api.github.com/repos/ShubhamDX/telegraf/issues/events{/number}","events_url":"https://api.github.com/repos/ShubhamDX/telegraf/events","assignees_url":"https://api.github.com/repos/ShubhamDX/telegraf/assignees{/user}","branches_url":"https://api.github.com/repos/ShubhamDX/telegraf/branches{/branch}","tags_url":"https://api.github.com/repos/ShubhamDX/telegraf/tags","blobs_url":"https://api.github.com/repos/ShubhamDX/telegraf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ShubhamDX/telegraf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ShubhamDX/telegraf/git/refs{/sha}","trees_url":"https://api.github.com/repos/ShubhamDX/telegraf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ShubhamDX/telegraf/statuses/{sha}","languages_url":"https://api.github.com/repos/ShubhamDX/telegraf/languages","stargazers_url":"https://api.github.com/repos/ShubhamDX/telegraf/stargazers","contributors_url":"https://api.github.com/repos/ShubhamDX/telegraf/contributors","subscribers_url":"https://api.github.com/repos/ShubhamDX/telegraf/subscribers","subscription_url":"https://api.github.com/repos/ShubhamDX/telegraf/subscription","commits_url":"https://api.github.com/repos/ShubhamDX/telegraf/commits{/sha}","git_commits_url":"https://api.github.com/repos/ShubhamDX/telegraf/git/commits{/sha}","comments_url":"https://api.github.com/repos/ShubhamDX/telegraf/comments{/number}","issue_comment_url":"https://api.github.com/repos/ShubhamDX/telegraf/issues/comments{/number}","contents_url":"https://api.github.com/repos/ShubhamDX/telegraf/contents/{+path}","compare_url":"https://api.github.com/repos/ShubhamDX/telegraf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ShubhamDX/telegraf/merges","archive_url":"https://api.github.com/repos/ShubhamDX/telegraf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ShubhamDX/telegraf/downloads","issues_url":"https://api.github.com/repos/ShubhamDX/telegraf/issues{/number}","pulls_url":"https://api.github.com/repos/ShubhamDX/telegraf/pulls{/number}","milestones_url":"https://api.github.com/repos/ShubhamDX/telegraf/milestones{/number}","notifications_url":"https://api.github.com/repos/ShubhamDX/telegraf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ShubhamDX/telegraf/labels{/name}","releases_url":"https://api.github.com/repos/ShubhamDX/telegraf/releases{/id}","deployments_url":"https://api.github.com/repos/ShubhamDX/telegraf/deployments","created_at":"2016-08-09T09:45:45Z","updated_at":"2016-08-09T09:45:48Z","pushed_at":"2016-08-09T11:56:10Z","git_url":"git://github.com/ShubhamDX/telegraf.git","ssh_url":"git@github.com:ShubhamDX/telegraf.git","clone_url":"https://github.com/ShubhamDX/telegraf.git","svn_url":"https://github.com/ShubhamDX/telegraf","homepage":"","size":11010,"stargazers_count":0,"watchers_count":0,"language":"Go","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":"influxdata:master","ref":"master","sha":"1989a5855d3ce0603a77ac931ba1f2bdc77bd843","user":{"login":"influxdata","id":5713248,"avatar_url":"https://avatars.githubusercontent.com/u/5713248?v=3","gravatar_id":"","url":"https://api.github.com/users/influxdata","html_url":"https://github.com/influxdata","followers_url":"https://api.github.com/users/influxdata/followers","following_url":"https://api.github.com/users/influxdata/following{/other_user}","gists_url":"https://api.github.com/users/influxdata/gists{/gist_id}","starred_url":"https://api.github.com/users/influxdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/influxdata/subscriptions","organizations_url":"https://api.github.com/users/influxdata/orgs","repos_url":"https://api.github.com/users/influxdata/repos","events_url":"https://api.github.com/users/influxdata/events{/privacy}","received_events_url":"https://api.github.com/users/influxdata/received_events","type":"Organization","site_admin":false},"repo":{"id":33258973,"name":"telegraf","full_name":"influxdata/telegraf","owner":{"login":"influxdata","id":5713248,"avatar_url":"https://avatars.githubusercontent.com/u/5713248?v=3","gravatar_id":"","url":"https://api.github.com/users/influxdata","html_url":"https://github.com/influxdata","followers_url":"https://api.github.com/users/influxdata/followers","following_url":"https://api.github.com/users/influxdata/following{/other_user}","gists_url":"https://api.github.com/users/influxdata/gists{/gist_id}","starred_url":"https://api.github.com/users/influxdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/influxdata/subscriptions","organizations_url":"https://api.github.com/users/influxdata/orgs","repos_url":"https://api.github.com/users/influxdata/repos","events_url":"https://api.github.com/users/influxdata/events{/privacy}","received_events_url":"https://api.github.com/users/influxdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/influxdata/telegraf","description":"The plugin-driven server agent for collecting & reporting metrics.","fork":false,"url":"https://api.github.com/repos/influxdata/telegraf","forks_url":"https://api.github.com/repos/influxdata/telegraf/forks","keys_url":"https://api.github.com/repos/influxdata/telegraf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/influxdata/telegraf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/influxdata/telegraf/teams","hooks_url":"https://api.github.com/repos/influxdata/telegraf/hooks","issue_events_url":"https://api.github.com/repos/influxdata/telegraf/issues/events{/number}","events_url":"https://api.github.com/repos/influxdata/telegraf/events","assignees_url":"https://api.github.com/repos/influxdata/telegraf/assignees{/user}","branches_url":"https://api.github.com/repos/influxdata/telegraf/branches{/branch}","tags_url":"https://api.github.com/repos/influxdata/telegraf/tags","blobs_url":"https://api.github.com/repos/influxdata/telegraf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/influxdata/telegraf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/influxdata/telegraf/git/refs{/sha}","trees_url":"https://api.github.com/repos/influxdata/telegraf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/influxdata/telegraf/statuses/{sha}","languages_url":"https://api.github.com/repos/influxdata/telegraf/languages","stargazers_url":"https://api.github.com/repos/influxdata/telegraf/stargazers","contributors_url":"https://api.github.com/repos/influxdata/telegraf/contributors","subscribers_url":"https://api.github.com/repos/influxdata/telegraf/subscribers","subscription_url":"https://api.github.com/repos/influxdata/telegraf/subscription","commits_url":"https://api.github.com/repos/influxdata/telegraf/commits{/sha}","git_commits_url":"https://api.github.com/repos/influxdata/telegraf/git/commits{/sha}","comments_url":"https://api.github.com/repos/influxdata/telegraf/comments{/number}","issue_comment_url":"https://api.github.com/repos/influxdata/telegraf/issues/comments{/number}","contents_url":"https://api.github.com/repos/influxdata/telegraf/contents/{+path}","compare_url":"https://api.github.com/repos/influxdata/telegraf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/influxdata/telegraf/merges","archive_url":"https://api.github.com/repos/influxdata/telegraf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/influxdata/telegraf/downloads","issues_url":"https://api.github.com/repos/influxdata/telegraf/issues{/number}","pulls_url":"https://api.github.com/repos/influxdata/telegraf/pulls{/number}","milestones_url":"https://api.github.com/repos/influxdata/telegraf/milestones{/number}","notifications_url":"https://api.github.com/repos/influxdata/telegraf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/influxdata/telegraf/labels{/name}","releases_url":"https://api.github.com/repos/influxdata/telegraf/releases{/id}","deployments_url":"https://api.github.com/repos/influxdata/telegraf/deployments","created_at":"2015-04-01T16:28:44Z","updated_at":"2016-08-09T12:59:01Z","pushed_at":"2016-08-09T13:02:44Z","git_url":"git://github.com/influxdata/telegraf.git","ssh_url":"git@github.com:influxdata/telegraf.git","clone_url":"https://github.com/influxdata/telegraf.git","svn_url":"https://github.com/influxdata/telegraf","homepage":"","size":25811,"stargazers_count":1645,"watchers_count":1645,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":537,"mirror_url":null,"open_issues_count":190,"forks":537,"open_issues":190,"watchers":1645,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/influxdata/telegraf/pulls/1611"},"html":{"href":"https://github.com/influxdata/telegraf/pull/1611"},"issue":{"href":"https://api.github.com/repos/influxdata/telegraf/issues/1611"},"comments":{"href":"https://api.github.com/repos/influxdata/telegraf/issues/1611/comments"},"review_comments":{"href":"https://api.github.com/repos/influxdata/telegraf/pulls/1611/comments"},"review_comment":{"href":"https://api.github.com/repos/influxdata/telegraf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/influxdata/telegraf/pulls/1611/commits"},"statuses":{"href":"https://api.github.com/repos/influxdata/telegraf/statuses/cc781e560c1c51b08ac06c667ef7e8f1c3ab9e5c"}}}}
{"actor":{"display_login":"sparrc"}}