From 6c839a33a42437596b329914979466b608f9bfde Mon Sep 17 00:00:00 2001 From: Mark Fletcher Date: Wed, 12 Feb 2020 20:53:11 -0800 Subject: [PATCH] Fix pgbouncer input when used with newer pgbouncer versions (#6820) --- plugins/inputs/pgbouncer/pgbouncer.go | 9 ++++++++- plugins/inputs/postgresql/service.go | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/pgbouncer/pgbouncer.go b/plugins/inputs/pgbouncer/pgbouncer.go index edff10509..db010e5c1 100644 --- a/plugins/inputs/pgbouncer/pgbouncer.go +++ b/plugins/inputs/pgbouncer/pgbouncer.go @@ -2,6 +2,7 @@ package pgbouncer import ( "bytes" + "strconv" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal" @@ -70,12 +71,18 @@ func (p *PgBouncer) Gather(acc telegraf.Accumulator) error { for col, val := range columnMap { _, ignore := ignoredColumns[col] if !ignore { - fields[col] = *val + // these values are returned by pgbouncer as strings, which we need to convert. + fields[col], _ = strconv.ParseUint((*val).(string), 10, 64) } } acc.AddFields("pgbouncer", fields, tags) } + err = rows.Err() + if err != nil { + return err + } + query = `SHOW POOLS` poolRows, err := p.DB.Query(query) diff --git a/plugins/inputs/postgresql/service.go b/plugins/inputs/postgresql/service.go index 9d3ab3963..96a9a6317 100644 --- a/plugins/inputs/postgresql/service.go +++ b/plugins/inputs/postgresql/service.go @@ -122,6 +122,13 @@ func (p *Service) Start(telegraf.Accumulator) (err error) { Name: "int8OID", OID: pgtype.Int8OID, }) + // Newer versions of pgbouncer need this defined. See the discussion here: + // https://github.com/jackc/pgx/issues/649 + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "numericOID", + OID: pgtype.NumericOID, + }) return info, nil },