Add a quiet mode to telegraf

closes #514
This commit is contained in:
Cameron Sparr 2016-01-15 12:25:56 -07:00
parent 50334e6bac
commit f60c090e4c
4 changed files with 35 additions and 13 deletions

View File

@ -85,7 +85,7 @@ if you don't have it already. You also must build with golang version 1.4+.
```console ```console
$ telegraf -help $ telegraf -help
Telegraf, The plugin-driven server agent for reporting metrics into InfluxDB Telegraf, The plugin-driven server agent for collecting and reporting metrics.
Usage: Usage:
@ -100,6 +100,8 @@ The flags are:
-input-filter filter the input plugins to enable, separator is : -input-filter filter the input plugins to enable, separator is :
-output-filter filter the output plugins to enable, separator is : -output-filter filter the output plugins to enable, separator is :
-usage print usage for a plugin, ie, 'telegraf -usage mysql' -usage print usage for a plugin, ie, 'telegraf -usage mysql'
-debug print metrics as they're generated to stdout
-quiet run in quiet mode
-version print the version to stdout -version print the version to stdout
Examples: Examples:

View File

@ -121,8 +121,10 @@ func (a *Agent) gatherParallel(pointChan chan *client.Point) error {
wg.Wait() wg.Wait()
elapsed := time.Since(start) elapsed := time.Since(start)
log.Printf("Gathered metrics, (%s interval), from %d inputs in %s\n", if !a.Config.Agent.Quiet {
a.Config.Agent.Interval.Duration, counter, elapsed) log.Printf("Gathered metrics, (%s interval), from %d inputs in %s\n",
a.Config.Agent.Interval.Duration, counter, elapsed)
}
return nil return nil
} }
@ -149,8 +151,10 @@ func (a *Agent) gatherSeparate(
} }
elapsed := time.Since(start) elapsed := time.Since(start)
log.Printf("Gathered metrics, (separate %s interval), from %s in %s\n", if !a.Config.Agent.Quiet {
input.Config.Interval, input.Name, elapsed) log.Printf("Gathered metrics, (separate %s interval), from %s in %s\n",
input.Config.Interval, input.Name, elapsed)
}
if outerr != nil { if outerr != nil {
return outerr return outerr
@ -235,8 +239,10 @@ func (a *Agent) writeOutput(
if err == nil { if err == nil {
// Write successful // Write successful
elapsed := time.Since(start) elapsed := time.Since(start)
log.Printf("Flushed %d metrics to output %s in %s\n", if !a.Config.Agent.Quiet {
len(filtered), ro.Name, elapsed) log.Printf("Flushed %d metrics to output %s in %s\n",
len(filtered), ro.Name, elapsed)
}
return return
} }
@ -327,12 +333,13 @@ func jitterInterval(ininterval, injitter time.Duration) time.Duration {
func (a *Agent) Run(shutdown chan struct{}) error { func (a *Agent) Run(shutdown chan struct{}) error {
var wg sync.WaitGroup var wg sync.WaitGroup
a.Config.Agent.FlushInterval.Duration = jitterInterval(a.Config.Agent.FlushInterval.Duration, a.Config.Agent.FlushInterval.Duration = jitterInterval(
a.Config.Agent.FlushInterval.Duration,
a.Config.Agent.FlushJitter.Duration) a.Config.Agent.FlushJitter.Duration)
log.Printf("Agent Config: Interval:%s, Debug:%#v, Hostname:%#v, "+ log.Printf("Agent Config: Interval:%s, Debug:%#v, Quiet:%#v, Hostname:%#v, "+
"Flush Interval:%s\n", "Flush Interval:%s \n",
a.Config.Agent.Interval.Duration, a.Config.Agent.Debug, a.Config.Agent.Interval.Duration, a.Config.Agent.Debug, a.Config.Agent.Quiet,
a.Config.Agent.Hostname, a.Config.Agent.FlushInterval.Duration) a.Config.Agent.Hostname, a.Config.Agent.FlushInterval.Duration)
// channel shared between all input threads for accumulating points // channel shared between all input threads for accumulating points

View File

@ -16,6 +16,8 @@ import (
var fDebug = flag.Bool("debug", false, var fDebug = flag.Bool("debug", false,
"show metrics as they're generated to stdout") "show metrics as they're generated to stdout")
var fQuiet = flag.Bool("quiet", false,
"run in quiet mode")
var fTest = flag.Bool("test", false, "gather metrics, print them out, and exit") var fTest = flag.Bool("test", false, "gather metrics, print them out, and exit")
var fConfig = flag.String("config", "", "configuration file to load") var fConfig = flag.String("config", "", "configuration file to load")
var fConfigDirectory = flag.String("config-directory", "", var fConfigDirectory = flag.String("config-directory", "",
@ -57,6 +59,8 @@ The flags are:
-input-filter filter the input plugins to enable, separator is : -input-filter filter the input plugins to enable, separator is :
-output-filter filter the output plugins to enable, separator is : -output-filter filter the output plugins to enable, separator is :
-usage print usage for a plugin, ie, 'telegraf -usage mysql' -usage print usage for a plugin, ie, 'telegraf -usage mysql'
-debug print metrics as they're generated to stdout
-quiet run in quiet mode
-version print the version to stdout -version print the version to stdout
Examples: Examples:
@ -173,6 +177,10 @@ func main() {
ag.Config.Agent.Debug = true ag.Config.Agent.Debug = true
} }
if *fQuiet {
ag.Config.Agent.Quiet = true
}
if *fTest { if *fTest {
err = ag.Test() err = ag.Test()
if err != nil { if err != nil {

View File

@ -76,8 +76,11 @@ type AgentConfig struct {
UTC bool `toml:"utc"` UTC bool `toml:"utc"`
Precision string Precision string
// Option for running in debug mode // Debug is the option for running in debug mode
Debug bool Debug bool
// Quiet is the option for running in quiet mode
Quiet bool
Hostname string Hostname string
} }
@ -279,6 +282,8 @@ var header = `# Telegraf configuration
# Run telegraf in debug mode # Run telegraf in debug mode
debug = false debug = false
# Run telegraf in quiet mode
quiet = false
# Override default hostname, if empty use os.Hostname() # Override default hostname, if empty use os.Hostname()
hostname = "" hostname = ""