Change InnerConfig to config and modified exec.go to back-compatible with old command configuration.

This commit is contained in:
Henry Hu
2016-02-03 23:47:55 +08:00
parent 7c8222813b
commit d74159d6d1
7 changed files with 23 additions and 14 deletions

View File

@@ -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)

View File

@@ -13,7 +13,7 @@ const (
// Config represents the configuration for Graphite endpoints.
type Config struct {
Commands []string
graphite.InnerConfig
graphite.Config
}
// New Config instance.

View File

@@ -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 {