Skip to content

Commit

Permalink
Add a quiet mode to telegraf
Browse files Browse the repository at this point in the history
closes #514
  • Loading branch information
sparrc committed Jan 15, 2016
1 parent 50334e6 commit f60c090
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if you don't have it already. You also must build with golang version 1.4+.

```console
$ 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:

Expand All @@ -100,6 +100,8 @@ The flags are:
-input-filter filter the input 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'
-debug print metrics as they're generated to stdout
-quiet run in quiet mode
-version print the version to stdout

Examples:
Expand Down
27 changes: 17 additions & 10 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ func (a *Agent) gatherParallel(pointChan chan *client.Point) error {
wg.Wait()

elapsed := time.Since(start)
log.Printf("Gathered metrics, (%s interval), from %d inputs in %s\n",
a.Config.Agent.Interval.Duration, counter, elapsed)
if !a.Config.Agent.Quiet {
log.Printf("Gathered metrics, (%s interval), from %d inputs in %s\n",
a.Config.Agent.Interval.Duration, counter, elapsed)
}
return nil
}

Expand All @@ -149,8 +151,10 @@ func (a *Agent) gatherSeparate(
}

elapsed := time.Since(start)
log.Printf("Gathered metrics, (separate %s interval), from %s in %s\n",
input.Config.Interval, input.Name, elapsed)
if !a.Config.Agent.Quiet {
log.Printf("Gathered metrics, (separate %s interval), from %s in %s\n",
input.Config.Interval, input.Name, elapsed)
}

if outerr != nil {
return outerr
Expand Down Expand Up @@ -235,8 +239,10 @@ func (a *Agent) writeOutput(
if err == nil {
// Write successful
elapsed := time.Since(start)
log.Printf("Flushed %d metrics to output %s in %s\n",
len(filtered), ro.Name, elapsed)
if !a.Config.Agent.Quiet {
log.Printf("Flushed %d metrics to output %s in %s\n",
len(filtered), ro.Name, elapsed)
}
return
}

Expand Down Expand Up @@ -327,12 +333,13 @@ func jitterInterval(ininterval, injitter time.Duration) time.Duration {
func (a *Agent) Run(shutdown chan struct{}) error {
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)

log.Printf("Agent Config: Interval:%s, Debug:%#v, Hostname:%#v, "+
"Flush Interval:%s\n",
a.Config.Agent.Interval.Duration, a.Config.Agent.Debug,
log.Printf("Agent Config: Interval:%s, Debug:%#v, Quiet:%#v, Hostname:%#v, "+
"Flush Interval:%s \n",
a.Config.Agent.Interval.Duration, a.Config.Agent.Debug, a.Config.Agent.Quiet,
a.Config.Agent.Hostname, a.Config.Agent.FlushInterval.Duration)

// channel shared between all input threads for accumulating points
Expand Down
8 changes: 8 additions & 0 deletions cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

var fDebug = flag.Bool("debug", false,
"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 fConfig = flag.String("config", "", "configuration file to load")
var fConfigDirectory = flag.String("config-directory", "",
Expand Down Expand Up @@ -57,6 +59,8 @@ The flags are:
-input-filter filter the input 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'
-debug print metrics as they're generated to stdout
-quiet run in quiet mode
-version print the version to stdout
Examples:
Expand Down Expand Up @@ -173,6 +177,10 @@ func main() {
ag.Config.Agent.Debug = true
}

if *fQuiet {
ag.Config.Agent.Quiet = true
}

if *fTest {
err = ag.Test()
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ type AgentConfig struct {
UTC bool `toml:"utc"`
Precision string

// Option for running in debug mode
Debug bool
// Debug is the option for running in debug mode
Debug bool

// Quiet is the option for running in quiet mode
Quiet bool
Hostname string
}

Expand Down Expand Up @@ -279,6 +282,8 @@ var header = `# Telegraf configuration
# Run telegraf in debug mode
debug = false
# Run telegraf in quiet mode
quiet = false
# Override default hostname, if empty use os.Hostname()
hostname = ""
Expand Down

0 comments on commit f60c090

Please sign in to comment.