Skip to content

Commit 8eac622

Browse files
committed
Write data in UTC by default and use 's' precision
Closes #159 Closes #162
1 parent b86c6bb commit 8eac622

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
[#150](https://github.com/influxdb/telegraf/pull/150): Add Host Uptime metric to system plugin
66
[#158](https://github.com/influxdb/telegraf/pull/158): Apache Plugin. Thanks @KPACHbIuLLIAnO4
7+
[#159](https://github.com/influxdb/telegraf/pull/159): Use second precision for InfluxDB writes
8+
[#162](https://github.com/influxdb/telegraf/pull/162): Write UTC by default, provide option
79

810
### Bugfixes
911

agent.go

+23-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ 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+
// Option for running in debug mode
3538
Debug bool
3639
Hostname string
3740

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

4447
// NewAgent returns an Agent struct based off the given Config
4548
func NewAgent(config *Config) (*Agent, error) {
46-
agent := &Agent{Config: config, Interval: Duration{10 * time.Second}}
49+
agent := &Agent{
50+
Config: config,
51+
Interval: Duration{10 * time.Second},
52+
UTC: true,
53+
}
4754

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

200208
var bp BatchPoints
201209
bp.Time = time.Now()
210+
if a.UTC {
211+
bp.Time = bp.Time.UTC()
212+
}
202213
bp.Tags = a.Config.Tags
214+
bp.Precision = "s"
203215

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

226-
bp.Time = time.Now()
227238
bp.Tags = a.Config.Tags
239+
bp.Time = time.Now()
240+
if a.UTC {
241+
bp.Time = bp.Time.UTC()
242+
}
243+
bp.Precision = "s"
228244

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

251267
bp.Tags = a.Config.Tags
252268
bp.Time = time.Now()
269+
if a.UTC {
270+
bp.Time = bp.Time.UTC()
271+
}
272+
bp.Precision = "s"
253273

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

config.go

+7-3
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
@@ -352,7 +353,10 @@ var header = `# Telegraf configuration
352353
353354
# Configuration for telegraf itself
354355
[agent]
356+
# # Default data collection interval for all plugins
355357
# interval = "10s"
358+
# # If utc = false, uses local time
359+
# utc = true
356360
# debug = false
357361
# hostname = "prod3241"
358362

0 commit comments

Comments
 (0)