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. closes #1093
This commit is contained in:
parent
1a7340bb02
commit
0367a39e1f
|
@ -16,6 +16,7 @@ import (
|
||||||
|
|
||||||
type Postgresql struct {
|
type Postgresql struct {
|
||||||
Address string
|
Address string
|
||||||
|
Outputaddress string
|
||||||
Databases []string
|
Databases []string
|
||||||
OrderedColumns []string
|
OrderedColumns []string
|
||||||
AllColumns []string
|
AllColumns []string
|
||||||
|
@ -58,6 +59,11 @@ var sampleConfig = `
|
||||||
## databases are gathered.
|
## databases are gathered.
|
||||||
## databases = ["app_production", "testing"]
|
## 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
|
## 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
|
## 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
|
## 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+ ?")
|
var KVMatcher, _ = regexp.Compile("(password|sslcert|sslkey|sslmode|sslrootcert)=\\S+ ?")
|
||||||
|
|
||||||
func (p *Postgresql) SanitizedAddress() (_ string, err error) {
|
func (p *Postgresql) SanitizedAddress() (_ string, err error) {
|
||||||
|
if p.Outputaddress != "" {
|
||||||
|
return p.Outputaddress, nil
|
||||||
|
}
|
||||||
var canonicalizedAddress string
|
var canonicalizedAddress string
|
||||||
if strings.HasPrefix(p.Address, "postgres://") || strings.HasPrefix(p.Address, "postgresql://") {
|
if strings.HasPrefix(p.Address, "postgres://") || strings.HasPrefix(p.Address, "postgresql://") {
|
||||||
canonicalizedAddress, err = pq.ParseURL(p.Address)
|
canonicalizedAddress, err = pq.ParseURL(p.Address)
|
||||||
|
|
Loading…
Reference in New Issue