Add url tag only if not already set
This commit is contained in:
parent
2ee270f274
commit
6c656d92a0
|
@ -20,9 +20,6 @@ The HTTP input plugin collects metrics from one or more HTTP(S) endpoints. The
|
||||||
# username = "username"
|
# username = "username"
|
||||||
# password = "pa$$word"
|
# password = "pa$$word"
|
||||||
|
|
||||||
## Tag all metrics with the url
|
|
||||||
# tag_url = true
|
|
||||||
|
|
||||||
## Optional SSL Config
|
## Optional SSL Config
|
||||||
# ssl_ca = "/etc/telegraf/ca.pem"
|
# ssl_ca = "/etc/telegraf/ca.pem"
|
||||||
# ssl_cert = "/etc/telegraf/cert.pem"
|
# ssl_cert = "/etc/telegraf/cert.pem"
|
||||||
|
|
|
@ -24,9 +24,6 @@ type HTTP struct {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
|
|
||||||
// Option to add "url" tag to each metric
|
|
||||||
TagURL bool `toml:"tag_url"`
|
|
||||||
|
|
||||||
// Path to CA file
|
// Path to CA file
|
||||||
SSLCA string `toml:"ssl_ca"`
|
SSLCA string `toml:"ssl_ca"`
|
||||||
// Path to host cert file
|
// Path to host cert file
|
||||||
|
@ -183,7 +180,7 @@ func (h *HTTP) gatherURL(
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range metrics {
|
for _, metric := range metrics {
|
||||||
if h.TagURL {
|
if !metric.HasTag("url") {
|
||||||
metric.AddTag("url", url)
|
metric.AddTag("url", url)
|
||||||
}
|
}
|
||||||
acc.AddFields(metric.Name(), metric.Fields(), metric.Tags(), metric.Time())
|
acc.AddFields(metric.Name(), metric.Fields(), metric.Tags(), metric.Time())
|
||||||
|
|
|
@ -23,8 +23,7 @@ func TestHTTPwithJSONFormat(t *testing.T) {
|
||||||
|
|
||||||
url := fakeServer.URL + "/endpoint"
|
url := fakeServer.URL + "/endpoint"
|
||||||
plugin := &plugin.HTTP{
|
plugin := &plugin.HTTP{
|
||||||
URLs: []string{url},
|
URLs: []string{url},
|
||||||
TagURL: true,
|
|
||||||
}
|
}
|
||||||
metricName := "metricName"
|
metricName := "metricName"
|
||||||
p, _ := parsers.NewJSONParser(metricName, nil, nil)
|
p, _ := parsers.NewJSONParser(metricName, nil, nil)
|
||||||
|
|
Loading…
Reference in New Issue