diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 66cdd35315301..390c55ad1d818 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -15,6 +15,8 @@ import ( "syscall" "time" + "github.com/fatih/color" + "github.com/influxdata/tail/watch" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/agent" @@ -256,20 +258,14 @@ func runAgent(ctx context.Context, logger.SetupLogging(logConfig) - if *fRunOnce { - wait := time.Duration(*fTestWait) * time.Second - return ag.Once(ctx, wait) - } - - if *fTest || *fTestWait != 0 { - wait := time.Duration(*fTestWait) * time.Second - return ag.Test(ctx, wait) - } - log.Printf("I! Loaded inputs: %s", strings.Join(c.InputNames(), " ")) log.Printf("I! Loaded aggregators: %s", strings.Join(c.AggregatorNames(), " ")) log.Printf("I! Loaded processors: %s", strings.Join(c.ProcessorNames(), " ")) - log.Printf("I! Loaded outputs: %s", strings.Join(c.OutputNames(), " ")) + if !*fRunOnce && (*fTest || *fTestWait != 0) { + log.Print(color.RedString("W! Outputs are not used in testing mode!")) + } else { + log.Printf("I! Loaded outputs: %s", strings.Join(c.OutputNames(), " ")) + } log.Printf("I! Tags enabled: %s", c.ListTags()) if count, found := c.Deprecations["inputs"]; found && (count[0] > 0 || count[1] > 0) { @@ -285,6 +281,16 @@ func runAgent(ctx context.Context, log.Printf("W! Deprecated outputs: %d and %d options", count[0], count[1]) } + if *fRunOnce { + wait := time.Duration(*fTestWait) * time.Second + return ag.Once(ctx, wait) + } + + if *fTest || *fTestWait != 0 { + wait := time.Duration(*fTestWait) * time.Second + return ag.Test(ctx, wait) + } + if *fPidfile != "" { f, err := os.OpenFile(*fPidfile, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { diff --git a/docs/COMMANDS_AND_FLAGS.md b/docs/COMMANDS_AND_FLAGS.md index 9a57a0b832bd7..4579e84488058 100644 --- a/docs/COMMANDS_AND_FLAGS.md +++ b/docs/COMMANDS_AND_FLAGS.md @@ -36,8 +36,8 @@ telegraf [flags] |`--section-filter` |filter config sections to output, separator is `:`. Valid values are `agent`, `global_tags`, `outputs`, `processors`, `aggregators` and `inputs`| |`--sample-config` |print out full sample configuration| |`--once` |enable once mode: gather metrics once, write them, and exit| -|`--test` |enable test mode: gather metrics once and print them| -|`--test-wait` |wait up to this many seconds for service inputs to complete in test or once mode| +|`--test` |enable test mode: gather metrics once and print them. **No outputs are executed!**| +|`--test-wait` |wait up to this many seconds for service inputs to complete in test or once mode. **Implies `--test` if not used with `--once`**| |`--usage ` |print usage for a plugin, ie, `telegraf --usage mysql`| |`--version` |display the version and exit| diff --git a/internal/usage.go b/internal/usage.go index 78e9a846b198b..a650a4854b3cd 100644 --- a/internal/usage.go +++ b/internal/usage.go @@ -38,9 +38,10 @@ The commands & flags are: 'processors', 'aggregators' and 'inputs' --sample-config print out full sample configuration --once enable once mode: gather metrics once, write them, and exit - --test enable test mode: gather metrics once and print them - --test-wait wait up to this many seconds for service - inputs to complete in test or once mode + --test enable test mode: gather metrics once and print them. + No outputs are executed! + --test-wait wait up to this many seconds for service inputs to complete + in test or once mode. Implies --test if not used with --once. --usage print usage for a plugin, ie, 'telegraf --usage mysql' --version display the version and exit