From f4efeef5b340c28b0a404ae703eddfbbc5ecd972 Mon Sep 17 00:00:00 2001 From: Mika Eloranta Date: Mon, 25 Apr 2016 18:09:35 +0300 Subject: [PATCH] postgresql_extensible: custom address in metrics output Allow overriding the the metrics "server" tag with the specified value. Can be used to give a more user-friendly value for the server name. --- .../postgresql_extensible/postgresql_extensible.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/inputs/postgresql_extensible/postgresql_extensible.go b/plugins/inputs/postgresql_extensible/postgresql_extensible.go index 710e537c3..75bc6b936 100644 --- a/plugins/inputs/postgresql_extensible/postgresql_extensible.go +++ b/plugins/inputs/postgresql_extensible/postgresql_extensible.go @@ -16,6 +16,7 @@ import ( type Postgresql struct { Address string + Outputaddress string Databases []string OrderedColumns []string AllColumns []string @@ -58,6 +59,11 @@ var sampleConfig = ` ## databases are gathered. ## databases = ["app_production", "testing"] # + # outputaddress = "db01" + ## A custom name for the database that will be used as the "server" tag in the + ## measurement output. If not specified, a default one generated from + ## the connection address is used. + # ## Define the toml config where the sql queries are stored ## New queries can be added, if the withdbname is set to true and there is no ## databases defined in the 'databases field', the sql query is ended by a @@ -200,6 +206,9 @@ type scanner interface { var KVMatcher, _ = regexp.Compile("(password|sslcert|sslkey|sslmode|sslrootcert)=\\S+ ?") func (p *Postgresql) SanitizedAddress() (_ string, err error) { + if p.Outputaddress != "" { + return p.Outputaddress, nil + } var canonicalizedAddress string if strings.HasPrefix(p.Address, "postgres://") || strings.HasPrefix(p.Address, "postgresql://") { canonicalizedAddress, err = pq.ParseURL(p.Address)