Skip to content

Commit

Permalink
Fix bug in setting the precision before gathering metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Sep 10, 2015
1 parent 3c7c892 commit 81f4aa9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ will still be backwards compatible if only `url` is specified.

### Bugfixes
- [#170](https://github.com/influxdb/telegraf/issues/170): Systemd support
- [#175](https://github.com/influxdb/telegraf/issues/175): Set write precision before gathering metrics

## v0.1.8 [2015-09-04]

Expand Down
6 changes: 5 additions & 1 deletion accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ type BatchPoints struct {
}

// Add adds a measurement
func (bp *BatchPoints) Add(measurement string, val interface{}, tags map[string]string) {
func (bp *BatchPoints) Add(
measurement string,
val interface{},
tags map[string]string,
) {
bp.mu.Lock()
defer bp.mu.Unlock()

Expand Down
17 changes: 9 additions & 8 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,17 @@ func (a *Agent) crankParallel() error {
go func(plugin *runningPlugin) {
defer wg.Done()

var acc BatchPoints
acc.Debug = a.Debug
acc.Prefix = plugin.name + "_"
acc.Config = plugin.config
var bp BatchPoints
bp.Debug = a.Debug
bp.Prefix = plugin.name + "_"
bp.Config = plugin.config
bp.Precision = a.Precision

if err := plugin.plugin.Gather(&acc); err != nil {
if err := plugin.plugin.Gather(&bp); err != nil {
log.Printf("Error in plugin [%s]: %s", plugin.name, err)
}

points <- &acc
points <- &bp
}(plugin)
}

Expand Down Expand Up @@ -233,6 +234,7 @@ func (a *Agent) crank() error {
var bp BatchPoints

bp.Debug = a.Debug
bp.Precision = a.Precision

for _, plugin := range a.plugins {
bp.Prefix = plugin.name + "_"
Expand All @@ -248,7 +250,6 @@ func (a *Agent) crank() error {
if a.UTC {
bp.Time = bp.Time.UTC()
}
bp.Precision = a.Precision

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

bp.Prefix = plugin.name + "_"
bp.Config = plugin.config
bp.Precision = a.Precision

if err := plugin.plugin.Gather(&bp); err != nil {
log.Printf("Error in plugin [%s]: %s", plugin.name, err)
Expand All @@ -277,7 +279,6 @@ func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) err
if a.UTC {
bp.Time = bp.Time.UTC()
}
bp.Precision = a.Precision

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

0 comments on commit 81f4aa9

Please sign in to comment.