From de59e188d29584bdcb08d9ed1ef9a21fab21da12 Mon Sep 17 00:00:00 2001 From: shubhamDX Date: Tue, 9 Aug 2016 20:02:37 +0530 Subject: [PATCH] Cleaning the code and correcting the Makefile --- Makefile | 1 + plugins/inputs/spark/spark.go | 22 +++++++++------------- plugins/inputs/spark/spark_test.go | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index b5962e6a3..a1af92a7c 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,7 @@ prepare: # Use the windows godeps file to prepare dependencies prepare-windows: go get github.com/sparrc/gdm + gdm restore gdm restore -f Godeps_windows # Run all docker containers necessary for unit tests diff --git a/plugins/inputs/spark/spark.go b/plugins/inputs/spark/spark.go index fce11efe9..79a6cb20e 100644 --- a/plugins/inputs/spark/spark.go +++ b/plugins/inputs/spark/spark.go @@ -40,9 +40,9 @@ func (c YarnClientImpl) MakeRequest(req *http.Request) (*http.Response, error) { } type Spark struct { - jClient JolokiaClient - SparkServer []string - YarnServer string + jClient JolokiaClient + spark_servers []string + yarn_server string } type javaMetric struct { @@ -150,7 +150,6 @@ func addJavaMetric(class string, c javaMetric, } func (j javaMetric) addTagsFields(out map[string]interface{}) { - fmt.Println(out["request"]) request := out["request"].(map[string]interface{}) var mbean = request["mbean"].(string) var mbeansplit = strings.Split(mbean, "=") @@ -237,9 +236,9 @@ func (c yarnMetric) addTagsFields(out map[string]interface{}) { func (j *Spark) SampleConfig() string { return ` ## Spark server exposing jolokia read service - SparkServer = ["127.0.0.1:8778"] #optional + spark_servers = ["127.0.0.1:8778"] #optional ## Server running Yarn Resource Manager - YarnServer = "127.0.0.1:8088" #optional + yarn_server = "127.0.0.1:8088" #optional ` } @@ -344,7 +343,7 @@ func parseServerTokens(server string) map[string]string { func (c *Spark) GatherJolokia(acc telegraf.Accumulator, wg *sync.WaitGroup) error { context := "/jolokia/read" - servers := c.SparkServer + servers := c.spark_servers metrics := [...]string{"/metrics:*", "/java.lang:type=Memory/HeapMemoryUsage", "/java.lang:type=Threading"} if len(servers) == 0 { wg.Done() @@ -370,7 +369,6 @@ func (c *Spark) GatherJolokia(acc telegraf.Accumulator, wg *sync.WaitGroup) erro if err != nil { return err } - fmt.Println("Request url is ", requestUrl) out, err := c.getAttr(requestUrl) if len(out) == 0 { @@ -393,8 +391,6 @@ func (c *Yarn) GatherYarn(acc telegraf.Accumulator, wg *sync.WaitGroup) error { return nil } - fmt.Println("Going to collect data of server ", server) - serverTokens := parseServerTokens(server) for _, context := range contexts { var m = newYarnMetric(server, acc) @@ -419,14 +415,14 @@ func (c *Spark) Gather(acc telegraf.Accumulator) error { log.Println("Config is ", c) yarn := Yarn{ yClient: &YarnClientImpl{client: &http.Client{}}, - serverAddress: c.YarnServer, + serverAddress: c.yarn_server, } wg := sync.WaitGroup{} wg.Add(1) go yarn.GatherYarn(acc, &wg) spark := Spark{ - jClient: &JolokiaClientImpl{client: &http.Client{}}, - SparkServer: c.SparkServer, + jClient: &JolokiaClientImpl{client: &http.Client{}}, + spark_servers: c.spark_servers, } wg.Add(1) go spark.GatherJolokia(acc, &wg) diff --git a/plugins/inputs/spark/spark_test.go b/plugins/inputs/spark/spark_test.go index 8d4d221aa..f08deae0b 100644 --- a/plugins/inputs/spark/spark_test.go +++ b/plugins/inputs/spark/spark_test.go @@ -13,7 +13,7 @@ func TestSparkMeasurements(t *testing.T) { } a := &Spark{ - YarnServer: testutil.GetLocalHost() + ":8088", + yarn_server: testutil.GetLocalHost() + ":8088", } var acc testutil.Accumulator