Fix bug in setting the precision before gathering metrics

Closes #175
This commit is contained in:
Cameron Sparr 2015-09-09 21:27:58 -06:00
parent 3c7c8926fb
commit 81f4aa9a5d
3 changed files with 15 additions and 9 deletions

View File

@ -9,6 +9,7 @@ will still be backwards compatible if only `url` is specified.
### Bugfixes ### Bugfixes
- [#170](https://github.com/influxdb/telegraf/issues/170): Systemd support - [#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] ## v0.1.8 [2015-09-04]

View File

@ -25,7 +25,11 @@ type BatchPoints struct {
} }
// Add adds a measurement // 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() bp.mu.Lock()
defer bp.mu.Unlock() defer bp.mu.Unlock()

View File

@ -196,16 +196,17 @@ func (a *Agent) crankParallel() error {
go func(plugin *runningPlugin) { go func(plugin *runningPlugin) {
defer wg.Done() defer wg.Done()
var acc BatchPoints var bp BatchPoints
acc.Debug = a.Debug bp.Debug = a.Debug
acc.Prefix = plugin.name + "_" bp.Prefix = plugin.name + "_"
acc.Config = plugin.config 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) log.Printf("Error in plugin [%s]: %s", plugin.name, err)
} }
points <- &acc points <- &bp
}(plugin) }(plugin)
} }
@ -233,6 +234,7 @@ func (a *Agent) crank() error {
var bp BatchPoints var bp BatchPoints
bp.Debug = a.Debug bp.Debug = a.Debug
bp.Precision = a.Precision
for _, plugin := range a.plugins { for _, plugin := range a.plugins {
bp.Prefix = plugin.name + "_" bp.Prefix = plugin.name + "_"
@ -248,7 +250,6 @@ func (a *Agent) crank() error {
if a.UTC { if a.UTC {
bp.Time = bp.Time.UTC() bp.Time = bp.Time.UTC()
} }
bp.Precision = a.Precision
return a.flush(&bp) return a.flush(&bp)
} }
@ -266,6 +267,7 @@ func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) err
bp.Prefix = plugin.name + "_" bp.Prefix = plugin.name + "_"
bp.Config = plugin.config bp.Config = plugin.config
bp.Precision = a.Precision
if err := plugin.plugin.Gather(&bp); err != nil { if err := plugin.plugin.Gather(&bp); err != nil {
log.Printf("Error in plugin [%s]: %s", plugin.name, err) log.Printf("Error in plugin [%s]: %s", plugin.name, err)
@ -277,7 +279,6 @@ func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) err
if a.UTC { if a.UTC {
bp.Time = bp.Time.UTC() bp.Time = bp.Time.UTC()
} }
bp.Precision = a.Precision
if err := a.flush(&bp); err != nil { if err := a.flush(&bp); err != nil {
outerr = errors.New("Error encountered processing plugins & outputs") outerr = errors.New("Error encountered processing plugins & outputs")