Skip to content

Commit 77b4e65

Browse files
committed
Write data in UTC by default and use 's' precision
Closes #159 Closes #162
1 parent 13061d1 commit 77b4e65

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
## v0.1.8 [unreleased]
22

3+
### Release Notes
4+
Telegraf will now write data in UTC at second precision by default
5+
36
### Features
47
- [#150](https://github.com/influxdb/telegraf/pull/150): Add Host Uptime metric to system plugin
58
- [#158](https://github.com/influxdb/telegraf/pull/158): Apache Plugin. Thanks @KPACHbIuLLIAnO4
9+
- [#159](https://github.com/influxdb/telegraf/pull/159): Use second precision for InfluxDB writes
610
- [#165](https://github.com/influxdb/telegraf/pull/165): Add additional metrics to mysql plugin. Thanks @nickscript0
11+
- [#162](https://github.com/influxdb/telegraf/pull/162): Write UTC by default, provide option
712
- [#166](https://github.com/influxdb/telegraf/pull/166): Upload binaries to S3
813

914
### Bugfixes

agent.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ type Agent struct {
3131
// Interval at which to gather information
3232
Interval Duration
3333

34-
// Run in debug mode?
34+
// Option for outputting data in UTC
35+
UTC bool `toml:"utc"`
36+
37+
// Precision to write data at
38+
// Valid values for Precision are n, u, ms, s, m, and h
39+
Precision string
40+
41+
// Option for running in debug mode
3542
Debug bool
3643
Hostname string
3744

@@ -43,8 +50,14 @@ type Agent struct {
4350

4451
// NewAgent returns an Agent struct based off the given Config
4552
func NewAgent(config *Config) (*Agent, error) {
46-
agent := &Agent{Config: config, Interval: Duration{10 * time.Second}}
53+
agent := &Agent{
54+
Config: config,
55+
Interval: Duration{10 * time.Second},
56+
UTC: true,
57+
Precision: "s",
58+
}
4759

60+
// Apply the toml table to the agent config, overriding defaults
4861
err := config.ApplyAgent(agent)
4962
if err != nil {
5063
return nil, err
@@ -199,7 +212,11 @@ func (a *Agent) crankParallel() error {
199212

200213
var bp BatchPoints
201214
bp.Time = time.Now()
215+
if a.UTC {
216+
bp.Time = bp.Time.UTC()
217+
}
202218
bp.Tags = a.Config.Tags
219+
bp.Precision = a.Precision
203220

204221
for sub := range points {
205222
bp.Points = append(bp.Points, sub.Points...)
@@ -223,8 +240,12 @@ func (a *Agent) crank() error {
223240
}
224241
}
225242

226-
bp.Time = time.Now()
227243
bp.Tags = a.Config.Tags
244+
bp.Time = time.Now()
245+
if a.UTC {
246+
bp.Time = bp.Time.UTC()
247+
}
248+
bp.Precision = a.Precision
228249

229250
return a.flush(&bp)
230251
}
@@ -250,6 +271,10 @@ func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) err
250271

251272
bp.Tags = a.Config.Tags
252273
bp.Time = time.Now()
274+
if a.UTC {
275+
bp.Time = bp.Time.UTC()
276+
}
277+
bp.Precision = a.Precision
253278

254279
if err := a.flush(&bp); err != nil {
255280
outerr = errors.New("Error encountered processing plugins & outputs")

config.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ func (c *Config) ApplyOutput(name string, v interface{}) error {
131131
return nil
132132
}
133133

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

140141
return nil
@@ -350,11 +351,23 @@ var header = `# Telegraf configuration
350351
[tags]
351352
# dc = "us-east-1"
352353
353-
# Configuration for telegraf itself
354+
# Configuration for telegraf agent
354355
[agent]
355-
# interval = "10s"
356-
# debug = false
357-
# hostname = "prod3241"
356+
# Default data collection interval for all plugins
357+
interval = "10s"
358+
359+
# If utc = false, uses local time (utc is highly recommended)
360+
utc = true
361+
362+
# Precision of writes, valid values are n, u, ms, s, m, and h
363+
# note: using second precision greatly helps InfluxDB compression
364+
precision = "s"
365+
366+
# run telegraf in debug mode
367+
debug = false
368+
369+
# Override default hostname, if empty use os.Hostname()
370+
hostname = ""
358371
359372
360373
###############################################################################

0 commit comments

Comments
 (0)