Skip to content

Commit 5fe7e6e

Browse files
committed
influxdb input: Use non-panicking type assertion
closes #1268
1 parent 58f2ba1 commit 5fe7e6e

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ time before a new metric is included by the plugin.
2727
- [#1252](https://github.com/influxdata/telegraf/pull/1252): Fix systemd service. Thanks @zbindenren!
2828
- [#1221](https://github.com/influxdata/telegraf/pull/1221): Fix influxdb n_shards counter.
2929
- [#1258](https://github.com/influxdata/telegraf/pull/1258): Fix potential kernel plugin integer parse error.
30+
- [#1268](https://github.com/influxdata/telegraf/pull/1268): Fix potential influxdb input type assertion panic.
3031

3132
## v0.13.1 [2016-05-24]
3233

plugins/inputs/influxdb/influxdb.go

+38-36
Original file line numberDiff line numberDiff line change
@@ -157,43 +157,45 @@ func (i *InfluxDB) gatherURL(
157157
return err
158158
}
159159

160-
if key.(string) == "memstats" {
161-
var m memstats
162-
if err := dec.Decode(&m); err != nil {
163-
continue
160+
if keyStr, ok := key.(string); ok {
161+
if keyStr == "memstats" {
162+
var m memstats
163+
if err := dec.Decode(&m); err != nil {
164+
continue
165+
}
166+
acc.AddFields("influxdb_memstats",
167+
map[string]interface{}{
168+
"alloc": m.Alloc,
169+
"total_alloc": m.TotalAlloc,
170+
"sys": m.Sys,
171+
"lookups": m.Lookups,
172+
"mallocs": m.Mallocs,
173+
"frees": m.Frees,
174+
"heap_alloc": m.HeapAlloc,
175+
"heap_sys": m.HeapSys,
176+
"heap_idle": m.HeapIdle,
177+
"heap_inuse": m.HeapInuse,
178+
"heap_released": m.HeapReleased,
179+
"heap_objects": m.HeapObjects,
180+
"stack_inuse": m.StackInuse,
181+
"stack_sys": m.StackSys,
182+
"mspan_inuse": m.MSpanInuse,
183+
"mspan_sys": m.MSpanSys,
184+
"mcache_inuse": m.MCacheInuse,
185+
"mcache_sys": m.MCacheSys,
186+
"buck_hash_sys": m.BuckHashSys,
187+
"gc_sys": m.GCSys,
188+
"other_sys": m.OtherSys,
189+
"next_gc": m.NextGC,
190+
"last_gc": m.LastGC,
191+
"pause_total_ns": m.PauseTotalNs,
192+
"num_gc": m.NumGC,
193+
"gcc_pu_fraction": m.GCCPUFraction,
194+
},
195+
map[string]string{
196+
"url": url,
197+
})
164198
}
165-
acc.AddFields("influxdb_memstats",
166-
map[string]interface{}{
167-
"alloc": m.Alloc,
168-
"total_alloc": m.TotalAlloc,
169-
"sys": m.Sys,
170-
"lookups": m.Lookups,
171-
"mallocs": m.Mallocs,
172-
"frees": m.Frees,
173-
"heap_alloc": m.HeapAlloc,
174-
"heap_sys": m.HeapSys,
175-
"heap_idle": m.HeapIdle,
176-
"heap_inuse": m.HeapInuse,
177-
"heap_released": m.HeapReleased,
178-
"heap_objects": m.HeapObjects,
179-
"stack_inuse": m.StackInuse,
180-
"stack_sys": m.StackSys,
181-
"mspan_inuse": m.MSpanInuse,
182-
"mspan_sys": m.MSpanSys,
183-
"mcache_inuse": m.MCacheInuse,
184-
"mcache_sys": m.MCacheSys,
185-
"buck_hash_sys": m.BuckHashSys,
186-
"gc_sys": m.GCSys,
187-
"other_sys": m.OtherSys,
188-
"next_gc": m.NextGC,
189-
"last_gc": m.LastGC,
190-
"pause_total_ns": m.PauseTotalNs,
191-
"num_gc": m.NumGC,
192-
"gcc_pu_fraction": m.GCCPUFraction,
193-
},
194-
map[string]string{
195-
"url": url,
196-
})
197199
}
198200

199201
// Attempt to parse a whole object into a point.

0 commit comments

Comments
 (0)