47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package inputs
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Redis is based on telegraf Redis plugin.
|
|
type Redis struct {
|
|
baseInput
|
|
Servers []string `json:"servers"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
// PluginName is based on telegraf plugin name.
|
|
func (r *Redis) PluginName() string {
|
|
return "redis"
|
|
}
|
|
|
|
// TOML encodes to toml string
|
|
func (r *Redis) TOML() string {
|
|
s := make([]string, len(r.Servers))
|
|
for k, v := range r.Servers {
|
|
s[k] = strconv.Quote(v)
|
|
}
|
|
password := ` # password = ""`
|
|
if r.Password != "" {
|
|
password = fmt.Sprintf(` password = "%s"`, r.Password)
|
|
}
|
|
return fmt.Sprintf(`[[inputs.%s]]
|
|
## specify servers via a url matching:
|
|
## [protocol://][:password]@address[:port]
|
|
## e.g.
|
|
## tcp://localhost:6379
|
|
## tcp://:password@192.168.99.100
|
|
## unix:///var/run/redis.sock
|
|
##
|
|
## If no servers are specified, then localhost is used as the host.
|
|
## If no port is specified, 6379 is used
|
|
servers = [%s]
|
|
|
|
## specify server password
|
|
%s
|
|
`, r.PluginName(), strings.Join(s, ", "), password)
|
|
}
|