diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f34d495b..2aedd7bb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ time before a new metric is included by the plugin. - [#1252](https://github.com/influxdata/telegraf/pull/1252): Fix systemd service. Thanks @zbindenren! - [#1221](https://github.com/influxdata/telegraf/pull/1221): Fix influxdb n_shards counter. - [#1258](https://github.com/influxdata/telegraf/pull/1258): Fix potential kernel plugin integer parse error. +- [#1268](https://github.com/influxdata/telegraf/pull/1268): Fix potential influxdb input type assertion panic. ## v0.13.1 [2016-05-24] diff --git a/plugins/inputs/influxdb/influxdb.go b/plugins/inputs/influxdb/influxdb.go index 53dd34a81..6a53ecdcb 100644 --- a/plugins/inputs/influxdb/influxdb.go +++ b/plugins/inputs/influxdb/influxdb.go @@ -157,43 +157,45 @@ func (i *InfluxDB) gatherURL( return err } - if key.(string) == "memstats" { - var m memstats - if err := dec.Decode(&m); err != nil { - continue + if keyStr, ok := key.(string); ok { + if keyStr == "memstats" { + var m memstats + if err := dec.Decode(&m); err != nil { + continue + } + acc.AddFields("influxdb_memstats", + map[string]interface{}{ + "alloc": m.Alloc, + "total_alloc": m.TotalAlloc, + "sys": m.Sys, + "lookups": m.Lookups, + "mallocs": m.Mallocs, + "frees": m.Frees, + "heap_alloc": m.HeapAlloc, + "heap_sys": m.HeapSys, + "heap_idle": m.HeapIdle, + "heap_inuse": m.HeapInuse, + "heap_released": m.HeapReleased, + "heap_objects": m.HeapObjects, + "stack_inuse": m.StackInuse, + "stack_sys": m.StackSys, + "mspan_inuse": m.MSpanInuse, + "mspan_sys": m.MSpanSys, + "mcache_inuse": m.MCacheInuse, + "mcache_sys": m.MCacheSys, + "buck_hash_sys": m.BuckHashSys, + "gc_sys": m.GCSys, + "other_sys": m.OtherSys, + "next_gc": m.NextGC, + "last_gc": m.LastGC, + "pause_total_ns": m.PauseTotalNs, + "num_gc": m.NumGC, + "gcc_pu_fraction": m.GCCPUFraction, + }, + map[string]string{ + "url": url, + }) } - acc.AddFields("influxdb_memstats", - map[string]interface{}{ - "alloc": m.Alloc, - "total_alloc": m.TotalAlloc, - "sys": m.Sys, - "lookups": m.Lookups, - "mallocs": m.Mallocs, - "frees": m.Frees, - "heap_alloc": m.HeapAlloc, - "heap_sys": m.HeapSys, - "heap_idle": m.HeapIdle, - "heap_inuse": m.HeapInuse, - "heap_released": m.HeapReleased, - "heap_objects": m.HeapObjects, - "stack_inuse": m.StackInuse, - "stack_sys": m.StackSys, - "mspan_inuse": m.MSpanInuse, - "mspan_sys": m.MSpanSys, - "mcache_inuse": m.MCacheInuse, - "mcache_sys": m.MCacheSys, - "buck_hash_sys": m.BuckHashSys, - "gc_sys": m.GCSys, - "other_sys": m.OtherSys, - "next_gc": m.NextGC, - "last_gc": m.LastGC, - "pause_total_ns": m.PauseTotalNs, - "num_gc": m.NumGC, - "gcc_pu_fraction": m.GCCPUFraction, - }, - map[string]string{ - "url": url, - }) } // Attempt to parse a whole object into a point.