From cb2c26a3324964d432bf83f535eca7b4d7879db3 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Wed, 12 Feb 2020 21:15:29 -0800 Subject: [PATCH] Fix support with pgbouncer <1.9 --- plugins/inputs/pgbouncer/pgbouncer.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/pgbouncer/pgbouncer.go b/plugins/inputs/pgbouncer/pgbouncer.go index db010e5c1..cbc38c869 100644 --- a/plugins/inputs/pgbouncer/pgbouncer.go +++ b/plugins/inputs/pgbouncer/pgbouncer.go @@ -70,9 +70,22 @@ func (p *PgBouncer) Gather(acc telegraf.Accumulator) error { fields := make(map[string]interface{}) for col, val := range columnMap { _, ignore := ignoredColumns[col] - if !ignore { - // these values are returned by pgbouncer as strings, which we need to convert. - fields[col], _ = strconv.ParseUint((*val).(string), 10, 64) + if ignore { + continue + } + + switch v := (*val).(type) { + case int64: + // Integer fields are returned in pgbouncer 1.5 through 1.9 + fields[col] = v + case string: + // Integer fields are returned in pgbouncer 1.12 + integer, err := strconv.ParseInt(v, 10, 64) + if err != nil { + return err + } + + fields[col] = integer } } acc.AddFields("pgbouncer", fields, tags)