Add rule about 'localhost'

This commit is contained in:
Evan Phoenix 2015-05-18 16:08:22 -07:00
parent 5e6d33a57f
commit 40cc034acb
4 changed files with 18 additions and 1 deletions

View File

@ -135,6 +135,11 @@ var header = `# Tivan configuration
# Use 'tivan -config tivan.toml -test' to see what metrics a config # Use 'tivan -config tivan.toml -test' to see what metrics a config
# file would generate. # 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 # Configuration for influxdb server to send metrics to
# [influxdb] # [influxdb]
# url = "http://10.20.2.4" # url = "http://10.20.2.4"

View File

@ -77,6 +77,10 @@ var mappings = []*mapping{
} }
func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error { func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error {
if serv == "localhost" {
serv = ""
}
db, err := sql.Open("mysql", serv) db, err := sql.Open("mysql", serv)
if err != nil { if err != nil {
return err return err

View File

@ -69,7 +69,7 @@ func (p *Postgresql) Gather(acc plugins.Accumulator) error {
} }
func (p *Postgresql) gatherServer(serv *Server, 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 serv = localhost
} }

View File

@ -7,6 +7,14 @@
# to be active. Declaring a plugin means just specifying the name # to be active. Declaring a plugin means just specifying the name
# as a section with no variables. # 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 # Configuration for influxdb server to send metrics to
# [influxdb] # [influxdb]
# url = "http://10.20.2.4" # url = "http://10.20.2.4"