Change InnerConfig to config and modified exec.go to back-compatible with old command configuration.
This commit is contained in:
parent
ed11665fa6
commit
50dc2698bf
|
@ -107,7 +107,7 @@
|
|||
# Read flattened metrics from one or more commands that output JSON to stdout
|
||||
[[inputs.exec]]
|
||||
# the command to run
|
||||
commands = ["/usr/bin/mycollector --foo=bar"]
|
||||
command = "/usr/bin/mycollector --foo=bar"
|
||||
name_suffix = "_mycollector"
|
||||
|
||||
# Read metrics of haproxy, via socket or csv stats page
|
||||
|
|
|
@ -14,14 +14,14 @@ const (
|
|||
)
|
||||
|
||||
// Config represents the configuration for Graphite endpoints.
|
||||
type InnerConfig struct {
|
||||
type Config struct {
|
||||
Separator string
|
||||
Tags []string
|
||||
Templates []string
|
||||
}
|
||||
|
||||
// DefaultTags returns the config's tags.
|
||||
func (c *InnerConfig) DefaultTags() models.Tags {
|
||||
func (c *Config) DefaultTags() models.Tags {
|
||||
tags := models.Tags{}
|
||||
for _, t := range c.Tags {
|
||||
parts := strings.Split(t, "=")
|
||||
|
@ -31,7 +31,7 @@ func (c *InnerConfig) DefaultTags() models.Tags {
|
|||
}
|
||||
|
||||
// Validate validates the config's templates and tags.
|
||||
func (c *InnerConfig) Validate() error {
|
||||
func (c *Config) Validate() error {
|
||||
if err := c.validateTemplates(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func (c *InnerConfig) Validate() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *InnerConfig) validateTemplates() error {
|
||||
func (c *Config) validateTemplates() error {
|
||||
// map to keep track of filters we see
|
||||
filters := map[string]struct{}{}
|
||||
|
||||
|
@ -110,7 +110,7 @@ func (c *InnerConfig) validateTemplates() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *InnerConfig) validateTags() error {
|
||||
func (c *Config) validateTags() error {
|
||||
for _, t := range c.Tags {
|
||||
if err := c.validateTag(t); err != nil {
|
||||
return err
|
||||
|
@ -119,7 +119,7 @@ func (c *InnerConfig) validateTags() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *InnerConfig) validateTemplate(template string) error {
|
||||
func (c *Config) validateTemplate(template string) error {
|
||||
hasMeasurement := false
|
||||
for _, p := range strings.Split(template, ".") {
|
||||
if p == "measurement" || p == "measurement*" {
|
||||
|
@ -134,7 +134,7 @@ func (c *InnerConfig) validateTemplate(template string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *InnerConfig) validateFilter(filter string) error {
|
||||
func (c *Config) validateFilter(filter string) error {
|
||||
for _, p := range strings.Split(filter, ".") {
|
||||
if p == "" {
|
||||
return fmt.Errorf("filter contains blank section: %s", filter)
|
||||
|
@ -147,7 +147,7 @@ func (c *InnerConfig) validateFilter(filter string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *InnerConfig) validateTag(keyValue string) error {
|
||||
func (c *Config) validateTag(keyValue string) error {
|
||||
parts := strings.Split(keyValue, "=")
|
||||
if len(parts) != 2 {
|
||||
return fmt.Errorf("invalid template tags: '%s'", keyValue)
|
|
@ -28,6 +28,9 @@ and strings will be ignored.
|
|||
# Read flattened metrics from one or more commands that output JSON to stdout
|
||||
[[inputs.exec]]
|
||||
# Shell/commands array
|
||||
# compatible with old version
|
||||
# we can still use the old command configuration
|
||||
# command = "/usr/bin/mycollector --foo=bar"
|
||||
commands = ["/tmp/test.sh","/tmp/test2.sh"]
|
||||
|
||||
# Data format to consume. This can be "json", "influx" or "graphite" (line-protocol)
|
||||
|
|
|
@ -13,7 +13,7 @@ const (
|
|||
// Config represents the configuration for Graphite endpoints.
|
||||
type Config struct {
|
||||
Commands []string
|
||||
graphite.InnerConfig
|
||||
graphite.Config
|
||||
}
|
||||
|
||||
// New Config instance.
|
||||
|
|
|
@ -16,6 +16,9 @@ import (
|
|||
|
||||
const sampleConfig = `
|
||||
# Shell/commands array
|
||||
# compatible with old version
|
||||
# we can still use the old command configuration
|
||||
# command = "/usr/bin/mycollector --foo=bar"
|
||||
commands = ["/tmp/test.sh","/tmp/test2.sh"]
|
||||
|
||||
# Data format to consume. This can be "json", "influx" or "graphite" (line-protocol)
|
||||
|
@ -52,6 +55,7 @@ const sampleConfig = `
|
|||
|
||||
type Exec struct {
|
||||
Commands []string
|
||||
Command string
|
||||
DataFormat string
|
||||
|
||||
Separator string
|
||||
|
@ -84,8 +88,6 @@ func (c CommandRunner) Run(e *Exec, command string) ([]byte, error) {
|
|||
}
|
||||
|
||||
cmd := exec.Command(split_cmd[0], split_cmd[1:]...)
|
||||
//name := strings.Replace(filepath.Base(cmd.Path), "/", "_", -1)
|
||||
//name = strings.Replace(name, ".", "_", -1)
|
||||
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
|
@ -119,6 +121,10 @@ func (e *Exec) initConfig() error {
|
|||
e.Lock()
|
||||
defer e.Unlock()
|
||||
|
||||
if e.Command != "" && len(e.Commands) < 1 {
|
||||
e.Commands = []string{e.Command}
|
||||
}
|
||||
|
||||
c := NewConfig(e.Commands, e.Tags, e.Templates, e.Separator)
|
||||
c.WithDefaults()
|
||||
if err := c.Validate(); err != nil {
|
||||
|
|
|
@ -33,7 +33,7 @@ type Config struct {
|
|||
Protocol string
|
||||
UdpReadBuffer int
|
||||
|
||||
graphite.InnerConfig
|
||||
graphite.Config
|
||||
}
|
||||
|
||||
// WithDefaults takes the given config and returns a new config with any required
|
||||
|
|
Loading…
Reference in New Issue