diff --git a/config.go b/config.go index c1a28aea3..2593cd81e 100644 --- a/config.go +++ b/config.go @@ -135,6 +135,11 @@ var header = `# Tivan configuration # Use 'tivan -config tivan.toml -test' to see what metrics a config # file would generate. +# One rule that plugins conform is wherever a connection string +# can be passed, the values '' and 'localhost' are treated specially. +# They indicate to the plugin to use their own builtin configuration to +# connect to the local system. + # Configuration for influxdb server to send metrics to # [influxdb] # url = "http://10.20.2.4" diff --git a/plugins/mysql/mysql.go b/plugins/mysql/mysql.go index d00a59e18..334171820 100644 --- a/plugins/mysql/mysql.go +++ b/plugins/mysql/mysql.go @@ -77,6 +77,10 @@ var mappings = []*mapping{ } func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error { + if serv == "localhost" { + serv = "" + } + db, err := sql.Open("mysql", serv) if err != nil { return err diff --git a/plugins/postgresql/postgresql.go b/plugins/postgresql/postgresql.go index ff26abdd7..0df8bae47 100644 --- a/plugins/postgresql/postgresql.go +++ b/plugins/postgresql/postgresql.go @@ -69,7 +69,7 @@ func (p *Postgresql) Gather(acc plugins.Accumulator) error { } func (p *Postgresql) gatherServer(serv *Server, acc plugins.Accumulator) error { - if serv.Address == "" { + if serv.Address == "" || serv.Address == "localhost" { serv = localhost } diff --git a/tivan.toml b/tivan.toml index 21c692350..7cf8042fe 100644 --- a/tivan.toml +++ b/tivan.toml @@ -7,6 +7,14 @@ # to be active. Declaring a plugin means just specifying the name # as a section with no variables. +# Use 'tivan -config tivan.toml -test' to see what metrics a config +# file would generate. + +# One rule that plugins conform is wherever a connection string +# can be passed, the values '' and 'localhost' are treated specially. +# They indicate to the plugin to use their own builtin configuration to +# connect to the local system. + # Configuration for influxdb server to send metrics to # [influxdb] # url = "http://10.20.2.4"