Skip to content

Commit

Permalink
fix: Print loaded plugins and deprecations for once and test (influxd…
Browse files Browse the repository at this point in the history
  • Loading branch information
srebhan authored Dec 7, 2021
1 parent 3ddc3c6 commit 526dcb4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
28 changes: 17 additions & 11 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions docs/COMMANDS_AND_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <plugin>` |print usage for a plugin, ie, `telegraf --usage mysql`|
|`--version` |display the version and exit|

Expand Down
7 changes: 4 additions & 3 deletions internal/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <plugin> print usage for a plugin, ie, 'telegraf --usage mysql'
--version display the version and exit
Expand Down

0 comments on commit 526dcb4

Please sign in to comment.