fix: Print loaded plugins and deprecations for once and test (#10205)

This commit is contained in:
Sven Rebhan 2021-12-07 23:56:18 +01:00 committed by GitHub
parent 3ddc3c6b51
commit 526dcb4bc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 16 deletions

View File

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

View File

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

View File

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