Don't allow inputs to overwrite host tag

closes #1054

This affects tags in the following plugins:

- cassandra
- disque
- rethinkdb
This commit is contained in:
Cameron Sparr
2016-04-18 18:12:58 -06:00
parent 46aaaa9b70
commit 9aec58c6b8
7 changed files with 38 additions and 51 deletions

View File

@@ -9,17 +9,9 @@ import (
"io/ioutil"
"net/http"
"net/url"
//"reflect"
"strings"
)
/*type Server struct {
Host string
Username string
Password string
Port string
}*/
type JolokiaClient interface {
MakeRequest(req *http.Request) (*http.Response, error)
}
@@ -55,12 +47,6 @@ type jmxMetric interface {
addTagsFields(out map[string]interface{})
}
func addServerTags(host string, tags map[string]string) {
if host != "" && host != "localhost" && host != "127.0.0.1" {
tags["host"] = host
}
}
func newJavaMetric(host string, metric string,
acc telegraf.Accumulator) *javaMetric {
return &javaMetric{host: host, metric: metric, acc: acc}
@@ -120,7 +106,7 @@ func (j javaMetric) addTagsFields(out map[string]interface{}) {
tokens := parseJmxMetricRequest(mbean)
addTokensToTags(tokens, tags)
addServerTags(j.host, tags)
tags["cassandra_host"] = j.host
if _, ok := tags["mname"]; !ok {
//Queries for a single value will not return a "name" tag in the response.
@@ -148,7 +134,7 @@ func addCassandraMetric(mbean string, c cassandraMetric,
fields := make(map[string]interface{})
tokens := parseJmxMetricRequest(mbean)
addTokensToTags(tokens, tags)
addServerTags(c.host, tags)
tags["cassandra_host"] = c.host
addValuesAsFields(values, fields, tags["mname"])
c.acc.AddFields(tokens["class"]+tokens["type"], fields, tags)
@@ -192,7 +178,7 @@ func (j *Cassandra) SampleConfig() string {
servers = ["myuser:mypassword@10.10.10.1:8778","10.10.10.2:8778",":8778"]
## List of metrics collected on above servers
## Each metric consists of a jmx path.
## This will collect all heap memory usage metrics from the jvm and
## This will collect all heap memory usage metrics from the jvm and
## ReadLatency metrics for all keyspaces and tables.
## "type=Table" in the query works with Cassandra3.0. Older versions might
## need to use "type=ColumnFamily"