Implement AddGauge & AddCounter functions

and utilize them in the in the 'system' input plugins.
This commit is contained in:
Cameron Sparr
2016-08-31 17:27:37 +01:00
parent 6dbbe65897
commit b18d375d6c
12 changed files with 213 additions and 57 deletions

View File

@@ -35,7 +35,7 @@ func (s *MemStats) Gather(acc telegraf.Accumulator) error {
"used_percent": 100 * float64(vm.Used) / float64(vm.Total),
"available_percent": 100 * float64(vm.Available) / float64(vm.Total),
}
acc.AddFields("mem", fields, nil)
acc.AddCounter("mem", fields, nil)
return nil
}
@@ -56,15 +56,18 @@ func (s *SwapStats) Gather(acc telegraf.Accumulator) error {
return fmt.Errorf("error getting swap memory info: %s", err)
}
fields := map[string]interface{}{
fieldsG := map[string]interface{}{
"total": swap.Total,
"used": swap.Used,
"free": swap.Free,
"used_percent": swap.UsedPercent,
"in": swap.Sin,
"out": swap.Sout,
}
acc.AddFields("swap", fields, nil)
fieldsC := map[string]interface{}{
"in": swap.Sin,
"out": swap.Sout,
}
acc.AddGauge("swap", fieldsG, nil)
acc.AddCounter("swap", fieldsC, nil)
return nil
}