Add ability to generate config from available plugins
This commit is contained in:
@@ -14,17 +14,27 @@ type Server struct {
|
||||
}
|
||||
|
||||
type Mysql struct {
|
||||
Disabled bool
|
||||
Servers []*Server
|
||||
Servers []*Server
|
||||
}
|
||||
|
||||
var sampleConfig = `
|
||||
# specify servers via a url matching:
|
||||
# [username[:password]@][protocol[(address)]]/[?tls=[true|false|skip-verify]]
|
||||
#
|
||||
# If no servers are specified, then localhost is used as the host.
|
||||
servers = ["localhost"]`
|
||||
|
||||
func (m *Mysql) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (m *Mysql) Description() string {
|
||||
return "Read metrics from one or many mysql servers"
|
||||
}
|
||||
|
||||
var localhost = &Server{}
|
||||
|
||||
func (m *Mysql) Gather(acc plugins.Accumulator) error {
|
||||
if m.Disabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(m.Servers) == 0 {
|
||||
// if we can't get stats in this case, thats fine, don't report
|
||||
// an error.
|
||||
|
||||
@@ -17,6 +17,39 @@ type Postgresql struct {
|
||||
Servers []*Server
|
||||
}
|
||||
|
||||
var sampleConfig = `
|
||||
# specify servers via an array of tables
|
||||
[[postgresql.servers]]
|
||||
|
||||
# specify address via a url matching:
|
||||
# postgres://[pqgotest[:password]]@localhost?sslmode=[disable|verify-ca|verify-full]
|
||||
# or a simple string:
|
||||
# host=localhost user=pqotest password=... sslmode=...
|
||||
#
|
||||
# All connection parameters are optional. By default, the host is localhost
|
||||
# and the user is the currently running user. For localhost, we default
|
||||
# to sslmode=disable as well.
|
||||
#
|
||||
|
||||
address = "localhost"
|
||||
|
||||
# A list of databases to pull metrics about. If not specified, metrics for all
|
||||
# databases are gathered.
|
||||
|
||||
# databases = ["app_production", "blah_testing"]
|
||||
|
||||
# [[postgresql.servers]]
|
||||
# address = "influx@remoteserver"
|
||||
`
|
||||
|
||||
func (p *Postgresql) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (p *Postgresql) Description() string {
|
||||
return "Read metrics from one or many postgresql servers"
|
||||
}
|
||||
|
||||
var localhost = &Server{Address: "sslmode=disable"}
|
||||
|
||||
func (p *Postgresql) Gather(acc plugins.Accumulator) error {
|
||||
|
||||
@@ -13,14 +13,27 @@ import (
|
||||
)
|
||||
|
||||
type Redis struct {
|
||||
Disabled bool
|
||||
Address string
|
||||
Servers []string
|
||||
Servers []string
|
||||
|
||||
c net.Conn
|
||||
buf []byte
|
||||
}
|
||||
|
||||
var sampleConfig = `
|
||||
# An array of address to gather stats about. Specify an ip on hostname
|
||||
# with optional port. ie localhost, 10.10.3.33:18832, etc.
|
||||
#
|
||||
# If no servers are specified, then localhost is used as the host.
|
||||
servers = ["localhost"]`
|
||||
|
||||
func (r *Redis) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (r *Redis) Description() string {
|
||||
return "Read metrics from one or many redis servers"
|
||||
}
|
||||
|
||||
var Tracking = map[string]string{
|
||||
"uptime_in_seconds": "uptime",
|
||||
"connected_clients": "clients",
|
||||
@@ -59,19 +72,7 @@ var ErrProtocolError = errors.New("redis protocol error")
|
||||
// Reads stats from all configured servers accumulates stats.
|
||||
// Returns one of the errors encountered while gather stats (if any).
|
||||
func (g *Redis) Gather(acc plugins.Accumulator) error {
|
||||
if g.Disabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
var servers []string
|
||||
|
||||
if g.Address != "" {
|
||||
servers = append(servers, g.Address)
|
||||
}
|
||||
|
||||
servers = append(servers, g.Servers...)
|
||||
|
||||
if len(servers) == 0 {
|
||||
if len(g.Servers) == 0 {
|
||||
g.gatherServer(":6379", acc)
|
||||
return nil
|
||||
}
|
||||
@@ -80,7 +81,7 @@ func (g *Redis) Gather(acc plugins.Accumulator) error {
|
||||
|
||||
var outerr error
|
||||
|
||||
for _, serv := range servers {
|
||||
for _, serv := range g.Servers {
|
||||
wg.Add(1)
|
||||
go func(serv string) {
|
||||
defer wg.Done()
|
||||
|
||||
@@ -5,6 +5,8 @@ type Accumulator interface {
|
||||
}
|
||||
|
||||
type Plugin interface {
|
||||
SampleConfig() string
|
||||
Description() string
|
||||
Gather(Accumulator) error
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,12 @@ type CPUStats struct {
|
||||
ps PS
|
||||
}
|
||||
|
||||
func (_ *CPUStats) Description() string {
|
||||
return "Read metrics about cpu usage"
|
||||
}
|
||||
|
||||
func (_ *CPUStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *CPUStats) Gather(acc plugins.Accumulator) error {
|
||||
times, err := s.ps.CPUTimes()
|
||||
if err != nil {
|
||||
@@ -77,6 +83,12 @@ type DiskStats struct {
|
||||
ps PS
|
||||
}
|
||||
|
||||
func (_ *DiskStats) Description() string {
|
||||
return "Read metrics about disk usage by mount point"
|
||||
}
|
||||
|
||||
func (_ *DiskStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *DiskStats) Gather(acc plugins.Accumulator) error {
|
||||
disks, err := s.ps.DiskUsage()
|
||||
if err != nil {
|
||||
@@ -103,6 +115,12 @@ type DiskIOStats struct {
|
||||
ps PS
|
||||
}
|
||||
|
||||
func (_ *DiskIOStats) Description() string {
|
||||
return "Read metrics about disk IO by device"
|
||||
}
|
||||
|
||||
func (_ *DiskIOStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *DiskIOStats) Gather(acc plugins.Accumulator) error {
|
||||
diskio, err := s.ps.DiskIO()
|
||||
if err != nil {
|
||||
@@ -131,6 +149,12 @@ type NetIOStats struct {
|
||||
ps PS
|
||||
}
|
||||
|
||||
func (_ *NetIOStats) Description() string {
|
||||
return "Read metrics about network interface usage"
|
||||
}
|
||||
|
||||
func (_ *NetIOStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *NetIOStats) Gather(acc plugins.Accumulator) error {
|
||||
netio, err := s.ps.NetIO()
|
||||
if err != nil {
|
||||
@@ -159,6 +183,12 @@ type MemStats struct {
|
||||
ps PS
|
||||
}
|
||||
|
||||
func (_ *MemStats) Description() string {
|
||||
return "Read metrics about memory usage"
|
||||
}
|
||||
|
||||
func (_ *MemStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *MemStats) Gather(acc plugins.Accumulator) error {
|
||||
vm, err := s.ps.VMStat()
|
||||
if err != nil {
|
||||
@@ -186,6 +216,12 @@ type SwapStats struct {
|
||||
ps PS
|
||||
}
|
||||
|
||||
func (_ *SwapStats) Description() string {
|
||||
return "Read metrics about swap memory usage"
|
||||
}
|
||||
|
||||
func (_ *SwapStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *SwapStats) Gather(acc plugins.Accumulator) error {
|
||||
swap, err := s.ps.SwapStat()
|
||||
if err != nil {
|
||||
@@ -208,6 +244,12 @@ type DockerStats struct {
|
||||
ps PS
|
||||
}
|
||||
|
||||
func (_ *DockerStats) Description() string {
|
||||
return "Read metrics about docker containers"
|
||||
}
|
||||
|
||||
func (_ *DockerStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *DockerStats) Gather(acc plugins.Accumulator) error {
|
||||
containers, err := s.ps.DockerStat()
|
||||
if err != nil {
|
||||
@@ -271,6 +313,12 @@ type SystemStats struct {
|
||||
ps PS
|
||||
}
|
||||
|
||||
func (_ *SystemStats) Description() string {
|
||||
return "Read metrics about system load"
|
||||
}
|
||||
|
||||
func (_ *SystemStats) SampleConfig() string { return "" }
|
||||
|
||||
func (s *SystemStats) add(acc plugins.Accumulator,
|
||||
name string, val float64, tags map[string]string) {
|
||||
if val >= 0 {
|
||||
|
||||
Reference in New Issue
Block a user