From 015261a524e8f335f844e7e3ffdd75ea3b4f2b57 Mon Sep 17 00:00:00 2001 From: G-regL Date: Thu, 28 Apr 2016 13:12:04 -0400 Subject: [PATCH] Sanitize Field name Replace '/[sS]ec' for '_persec' and spaces with underscores. closes #1118 --- CHANGELOG.md | 3 +++ plugins/inputs/win_perf_counters/win_perf_counters.go | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d66e4dd3a..eadbed925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ based on _prefix_ in addition to globs. This means that a filter like - cassandra: `host -> cassandra_host` - disque: `host -> disque_host` - rethinkdb: `host -> rethinkdb_host` + +- **Breaking Change**: The `win_perf_counters` input has been changed to sanitize field names, replacing `/Sec` and `/sec` with `_persec`, as well as spaces with underscores. This is needed because Graphite doesn't like slashes and spaces, and was failing to accept metrics that had them. The `/[sS]ec` -> `_persec` is just to make things clearer and uniform. ### Features @@ -65,6 +67,7 @@ based on _prefix_ in addition to globs. This means that a filter like - [#967](https://github.com/influxdata/telegraf/issues/967): Buffer logging improvements. - [#1107](https://github.com/influxdata/telegraf/issues/1107): Support lustre2 job stats. Thanks @hanleyja! - [#1110](https://github.com/influxdata/telegraf/pull/1110): Sanitize * to - in graphite serializer. Thanks @goodeggs! +- [#1118] (https://github.com/influxdata/telegraf/pull/1118): Sanitize Counter names for `win_perf_counters` input. ### Bugfixes diff --git a/plugins/inputs/win_perf_counters/win_perf_counters.go b/plugins/inputs/win_perf_counters/win_perf_counters.go index 8279f1c7a..4684289ee 100644 --- a/plugins/inputs/win_perf_counters/win_perf_counters.go +++ b/plugins/inputs/win_perf_counters/win_perf_counters.go @@ -107,6 +107,8 @@ type item struct { counterHandle win.PDH_HCOUNTER } +var sanitizedChars = strings.NewReplacer("/sec", "_persec", "/Sec", "_persec", " ", "_") + func (m *Win_PerfCounters) AddItem(metrics *itemList, query string, objectName string, counter string, instance string, measurement string, include_total bool) { @@ -297,7 +299,7 @@ func (m *Win_PerfCounters) Gather(acc telegraf.Accumulator) error { tags["instance"] = s } tags["objectname"] = metric.objectName - fields[string(metric.counter)] = float32(c.FmtValue.DoubleValue) + fields[sanitizedChars.Replace(string(metric.counter))] = float32(c.FmtValue.DoubleValue) var measurement string if metric.measurement == "" {