Skip to content

Commit

Permalink
Write data in UTC by default and use 's' precision
Browse files Browse the repository at this point in the history
Closes #159
Closes #162
  • Loading branch information
sparrc committed Sep 2, 2015
1 parent 13061d1 commit 00685c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
### Features
- [#150](https://github.com/influxdb/telegraf/pull/150): Add Host Uptime metric to system plugin
- [#158](https://github.com/influxdb/telegraf/pull/158): Apache Plugin. Thanks @KPACHbIuLLIAnO4
- [#159](https://github.com/influxdb/telegraf/pull/159): Use second precision for InfluxDB writes
- [#165](https://github.com/influxdb/telegraf/pull/165): Add additional metrics to mysql plugin. Thanks @nickscript0
- [#162](https://github.com/influxdb/telegraf/pull/162): Write UTC by default, provide option
- [#166](https://github.com/influxdb/telegraf/pull/166): Upload binaries to S3

### Bugfixes
Expand Down
26 changes: 23 additions & 3 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ type Agent struct {
// Interval at which to gather information
Interval Duration

// Run in debug mode?
// Option for outputting data in UTC
UTC bool `toml:"utc"`

// Option for running in debug mode
Debug bool
Hostname string

Expand All @@ -43,8 +46,13 @@ type Agent struct {

// NewAgent returns an Agent struct based off the given Config
func NewAgent(config *Config) (*Agent, error) {
agent := &Agent{Config: config, Interval: Duration{10 * time.Second}}
agent := &Agent{
Config: config,
Interval: Duration{10 * time.Second},
UTC: true,
}

// Apply the toml table to the agent config, overriding defaults
err := config.ApplyAgent(agent)
if err != nil {
return nil, err
Expand Down Expand Up @@ -199,7 +207,11 @@ func (a *Agent) crankParallel() error {

var bp BatchPoints
bp.Time = time.Now()
if a.UTC {
bp.Time = bp.Time.UTC()
}
bp.Tags = a.Config.Tags
bp.Precision = "s"

for sub := range points {
bp.Points = append(bp.Points, sub.Points...)
Expand All @@ -223,8 +235,12 @@ func (a *Agent) crank() error {
}
}

bp.Time = time.Now()
bp.Tags = a.Config.Tags
bp.Time = time.Now()
if a.UTC {
bp.Time = bp.Time.UTC()
}
bp.Precision = "s"

return a.flush(&bp)
}
Expand All @@ -250,6 +266,10 @@ func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) err

bp.Tags = a.Config.Tags
bp.Time = time.Now()
if a.UTC {
bp.Time = bp.Time.UTC()
}
bp.Precision = "s"

if err := a.flush(&bp); err != nil {
outerr = errors.New("Error encountered processing plugins & outputs")
Expand Down
10 changes: 7 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ func (c *Config) ApplyOutput(name string, v interface{}) error {
return nil
}

// ApplyAgent loads the toml config into the given interface
func (c *Config) ApplyAgent(v interface{}) error {
// ApplyAgent loads the toml config into the given Agent object, overriding
// defaults (such as collection duration) with the values from the toml config.
func (c *Config) ApplyAgent(a *Agent) error {
if c.agent != nil {
return toml.UnmarshalTable(c.agent, v)
return toml.UnmarshalTable(c.agent, a)
}

return nil
Expand Down Expand Up @@ -352,7 +353,10 @@ var header = `# Telegraf configuration
# Configuration for telegraf itself
[agent]
# # Default data collection interval for all plugins
# interval = "10s"
# # If utc = false, uses local time
# utc = true
# debug = false
# hostname = "prod3241"
Expand Down

0 comments on commit 00685c5

Please sign in to comment.