From c4094ac5ca1babb285b89e972ee9fcc555850f7a Mon Sep 17 00:00:00 2001 From: Eugene Tetenchuk Date: Tue, 18 Jun 2019 21:45:41 +0300 Subject: [PATCH 1/3] Enhance postgres data types --- plugins/inputs/postgresql/service.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/inputs/postgresql/service.go b/plugins/inputs/postgresql/service.go index 9d3ab396317a1..18724b430d98c 100644 --- a/plugins/inputs/postgresql/service.go +++ b/plugins/inputs/postgresql/service.go @@ -122,6 +122,26 @@ func (p *Service) Start(telegraf.Accumulator) (err error) { Name: "int8OID", OID: pgtype.Int8OID, }) + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "zerroTypeOID", + OID: 0, + }) + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "numericTypeOID", + OID: pgtype.NumericOID, + }) + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "float8TypeOID", + OID: pgtype.Float8OID, + }) + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "timestamptzTypeOID", + OID: pgtype.TimestamptzOID, + }) return info, nil }, From 4e32d7d3304834ac25af260a8bb95fc6c5e5004b Mon Sep 17 00:00:00 2001 From: Eugene Tetenchuk Date: Thu, 20 Jun 2019 11:46:24 +0300 Subject: [PATCH 2/3] Remove pgbounce specific --- plugins/inputs/pgbouncer/README.md | 25 ++++++ plugins/inputs/pgbouncer/pgbouncer.go | 1 - plugins/inputs/pgbouncer/pgbouncer_test.go | 1 - plugins/inputs/postgresql/postgresql.go | 1 - plugins/inputs/postgresql/postgresql_test.go | 1 - plugins/inputs/postgresql/service.go | 83 +++++++++---------- .../postgresql_extensible.go | 1 - .../postgresql_extensible_test.go | 1 - 8 files changed, 64 insertions(+), 50 deletions(-) diff --git a/plugins/inputs/pgbouncer/README.md b/plugins/inputs/pgbouncer/README.md index dd8224e3eb194..0eb7dbc0c98e3 100644 --- a/plugins/inputs/pgbouncer/README.md +++ b/plugins/inputs/pgbouncer/README.md @@ -4,6 +4,31 @@ This PgBouncer plugin provides metrics for your PgBouncer load balancer. More information about the meaning of these metrics can be found in the [PgBouncer Documentation](https://pgbouncer.github.io/usage.html) +Deprecated (_NEXT_VERSION_): use the [postgresql_extensible](../postgresql_extensible) input. + +## Migration to the postgresql_extensible input + +``` +[[inputs.postgresql_extensible]] + address = "host=localhost port=6432 user=postgres password=postgres sslmode=disable dbname=pgbouncer" + [[inputs.postgresql_extensible.query]] + measurement = "pgbouncer" + sqlquery = "show stats;" + withdbname = false + [[inputs.postgresql_extensible.query]] + measurement = "pgbouncer_pools" + sqlquery = "show pools;" + withdbname = false +``` + +Output metrics will be the same. Also you can use any of this queries to expose internal data: +``` +SHOW STATS; +SHOW SERVERS; +SHOW CLIENTS; +SHOW POOLS; +``` + ## Configuration Specify address via a postgresql connection string: diff --git a/plugins/inputs/pgbouncer/pgbouncer.go b/plugins/inputs/pgbouncer/pgbouncer.go index 722648c48edc1..dfa3820d5cf00 100644 --- a/plugins/inputs/pgbouncer/pgbouncer.go +++ b/plugins/inputs/pgbouncer/pgbouncer.go @@ -172,7 +172,6 @@ func init() { MaxLifetime: internal.Duration{ Duration: 0, }, - IsPgBouncer: true, }, } }) diff --git a/plugins/inputs/pgbouncer/pgbouncer_test.go b/plugins/inputs/pgbouncer/pgbouncer_test.go index 44e28c7f3335e..ed5582ab5f78a 100644 --- a/plugins/inputs/pgbouncer/pgbouncer_test.go +++ b/plugins/inputs/pgbouncer/pgbouncer_test.go @@ -20,7 +20,6 @@ func TestPgBouncerGeneratesMetrics(t *testing.T) { "host=%s user=pgbouncer password=pgbouncer dbname=pgbouncer port=6432 sslmode=disable", testutil.GetLocalHost(), ), - IsPgBouncer: true, }, } diff --git a/plugins/inputs/postgresql/postgresql.go b/plugins/inputs/postgresql/postgresql.go index e136098f4f304..19c9db9ce0f3c 100644 --- a/plugins/inputs/postgresql/postgresql.go +++ b/plugins/inputs/postgresql/postgresql.go @@ -189,7 +189,6 @@ func init() { MaxLifetime: internal.Duration{ Duration: 0, }, - IsPgBouncer: false, }, } }) diff --git a/plugins/inputs/postgresql/postgresql_test.go b/plugins/inputs/postgresql/postgresql_test.go index b23321019f5f8..306dca3b6b6ef 100644 --- a/plugins/inputs/postgresql/postgresql_test.go +++ b/plugins/inputs/postgresql/postgresql_test.go @@ -20,7 +20,6 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) { "host=%s user=postgres sslmode=disable", testutil.GetLocalHost(), ), - IsPgBouncer: false, }, Databases: []string{"postgres"}, } diff --git a/plugins/inputs/postgresql/service.go b/plugins/inputs/postgresql/service.go index 18724b430d98c..9bfb7c55b37b4 100644 --- a/plugins/inputs/postgresql/service.go +++ b/plugins/inputs/postgresql/service.go @@ -93,7 +93,6 @@ type Service struct { MaxOpen int MaxLifetime internal.Duration DB *sql.DB - IsPgBouncer bool } // Start starts the ServiceInput's service, whatever that may be @@ -104,54 +103,50 @@ func (p *Service) Start(telegraf.Accumulator) (err error) { p.Address = localhost } - connectionString := p.Address - // Specific support to make it work with PgBouncer too // See https://github.com/influxdata/telegraf/issues/3253#issuecomment-357505343 - if p.IsPgBouncer { - d := &stdlib.DriverConfig{ - ConnConfig: pgx.ConnConfig{ - PreferSimpleProtocol: true, - RuntimeParams: map[string]string{ - "client_encoding": "UTF8", - }, - CustomConnInfo: func(c *pgx.Conn) (*pgtype.ConnInfo, error) { - info := c.ConnInfo.DeepCopy() - info.RegisterDataType(pgtype.DataType{ - Value: &pgtype.OIDValue{}, - Name: "int8OID", - OID: pgtype.Int8OID, - }) - info.RegisterDataType(pgtype.DataType{ - Value: &pgtype.OIDValue{}, - Name: "zerroTypeOID", - OID: 0, - }) - info.RegisterDataType(pgtype.DataType{ - Value: &pgtype.OIDValue{}, - Name: "numericTypeOID", - OID: pgtype.NumericOID, - }) - info.RegisterDataType(pgtype.DataType{ - Value: &pgtype.OIDValue{}, - Name: "float8TypeOID", - OID: pgtype.Float8OID, - }) - info.RegisterDataType(pgtype.DataType{ - Value: &pgtype.OIDValue{}, - Name: "timestamptzTypeOID", - OID: pgtype.TimestamptzOID, - }) - - return info, nil - }, + // Enhanced pgx data types for fully working with any pgbouncer request + driverConfig := &stdlib.DriverConfig{ + ConnConfig: pgx.ConnConfig{ + PreferSimpleProtocol: true, + RuntimeParams: map[string]string{ + "client_encoding": "UTF8", }, - } - stdlib.RegisterDriverConfig(d) - connectionString = d.ConnectionString(p.Address) + CustomConnInfo: func(c *pgx.Conn) (*pgtype.ConnInfo, error) { + info := c.ConnInfo.DeepCopy() + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "int8OID", + OID: pgtype.Int8OID, + }) + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "zerroTypeOID", + OID: 0, + }) + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "numericTypeOID", + OID: pgtype.NumericOID, + }) + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "float8TypeOID", + OID: pgtype.Float8OID, + }) + info.RegisterDataType(pgtype.DataType{ + Value: &pgtype.OIDValue{}, + Name: "timestamptzTypeOID", + OID: pgtype.TimestamptzOID, + }) + + return info, nil + }, + }, } + stdlib.RegisterDriverConfig(driverConfig) - if p.DB, err = sql.Open("pgx", connectionString); err != nil { + if p.DB, err = sql.Open("pgx", driverConfig.ConnectionString(p.Address)); err != nil { return err } diff --git a/plugins/inputs/postgresql_extensible/postgresql_extensible.go b/plugins/inputs/postgresql_extensible/postgresql_extensible.go index c2bcb7b600efc..cd0feee5e0a7d 100644 --- a/plugins/inputs/postgresql_extensible/postgresql_extensible.go +++ b/plugins/inputs/postgresql_extensible/postgresql_extensible.go @@ -280,7 +280,6 @@ func init() { MaxLifetime: internal.Duration{ Duration: 0, }, - IsPgBouncer: false, }, } }) diff --git a/plugins/inputs/postgresql_extensible/postgresql_extensible_test.go b/plugins/inputs/postgresql_extensible/postgresql_extensible_test.go index 1ed62a1cd62c0..27313b9392197 100644 --- a/plugins/inputs/postgresql_extensible/postgresql_extensible_test.go +++ b/plugins/inputs/postgresql_extensible/postgresql_extensible_test.go @@ -18,7 +18,6 @@ func queryRunner(t *testing.T, q query) *testutil.Accumulator { "host=%s user=postgres sslmode=disable", testutil.GetLocalHost(), ), - IsPgBouncer: false, }, Databases: []string{"postgres"}, Query: q, From 1453a48966c1cbf262213f14e20ff2997d86ee6c Mon Sep 17 00:00:00 2001 From: Eugene Tetenchuk Date: Thu, 20 Jun 2019 21:48:26 +0300 Subject: [PATCH 3/3] Change README.md according review --- plugins/inputs/pgbouncer/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/inputs/pgbouncer/README.md b/plugins/inputs/pgbouncer/README.md index 0eb7dbc0c98e3..6c2dfa076faa3 100644 --- a/plugins/inputs/pgbouncer/README.md +++ b/plugins/inputs/pgbouncer/README.md @@ -4,9 +4,7 @@ This PgBouncer plugin provides metrics for your PgBouncer load balancer. More information about the meaning of these metrics can be found in the [PgBouncer Documentation](https://pgbouncer.github.io/usage.html) -Deprecated (_NEXT_VERSION_): use the [postgresql_extensible](../postgresql_extensible) input. - -## Migration to the postgresql_extensible input +## Reproduce behaviour with postgresql_extensible input ``` [[inputs.postgresql_extensible]]