Minor usability fixes to config
This commit is contained in:
@@ -9,12 +9,8 @@ import (
|
||||
"github.com/influxdb/tivan/plugins"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Address string
|
||||
}
|
||||
|
||||
type Mysql struct {
|
||||
Servers []*Server
|
||||
Servers []string
|
||||
}
|
||||
|
||||
var sampleConfig = `
|
||||
@@ -32,7 +28,7 @@ func (m *Mysql) Description() string {
|
||||
return "Read metrics from one or many mysql servers"
|
||||
}
|
||||
|
||||
var localhost = &Server{}
|
||||
var localhost = ""
|
||||
|
||||
func (m *Mysql) Gather(acc plugins.Accumulator) error {
|
||||
if len(m.Servers) == 0 {
|
||||
@@ -80,8 +76,8 @@ var mappings = []*mapping{
|
||||
},
|
||||
}
|
||||
|
||||
func (m *Mysql) gatherServer(serv *Server, acc plugins.Accumulator) error {
|
||||
db, err := sql.Open("mysql", serv.Address)
|
||||
func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error {
|
||||
db, err := sql.Open("mysql", serv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ var sampleConfig = `
|
||||
# to sslmode=disable as well.
|
||||
#
|
||||
|
||||
address = "localhost"
|
||||
address = "sslmode=disable"
|
||||
|
||||
# A list of databases to pull metrics about. If not specified, metrics for all
|
||||
# databases are gathered.
|
||||
@@ -69,6 +69,10 @@ func (p *Postgresql) Gather(acc plugins.Accumulator) error {
|
||||
}
|
||||
|
||||
func (p *Postgresql) gatherServer(serv *Server, acc plugins.Accumulator) error {
|
||||
if serv.Address == "" {
|
||||
serv = localhost
|
||||
}
|
||||
|
||||
db, err := sql.Open("postgres", serv.Address)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -94,11 +94,19 @@ func (g *Redis) Gather(acc plugins.Accumulator) error {
|
||||
return outerr
|
||||
}
|
||||
|
||||
const defaultPort = "6379"
|
||||
|
||||
func (g *Redis) gatherServer(addr string, acc plugins.Accumulator) error {
|
||||
if g.c == nil {
|
||||
|
||||
_, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
addr = addr + ":" + defaultPort
|
||||
}
|
||||
|
||||
c, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Unable to connect to redis server '%s': %s", addr, err)
|
||||
}
|
||||
|
||||
g.c = c
|
||||
|
||||
Reference in New Issue
Block a user