Allow a PerCPU configuration variable, issue #108

This commit is contained in:
Cameron Sparr
2015-08-13 11:27:24 -06:00
parent 5d4b6c41a8
commit 04963f12a3
5 changed files with 44 additions and 31 deletions

View File

@@ -8,16 +8,27 @@ import (
type CPUStats struct {
ps PS
PerCPU bool `toml:"percpu"`
TotalCPU bool `toml:"totalcpu"`
}
func (_ *CPUStats) Description() string {
return "Read metrics about cpu usage"
}
func (_ *CPUStats) SampleConfig() string { return "" }
var sampleConfig = `
# Whether to report per-cpu stats or not
percpu = true
# Whether to report total system cpu stats or not
totalcpu = true`
func (_ *CPUStats) SampleConfig() string {
return sampleConfig
}
func (s *CPUStats) Gather(acc plugins.Accumulator) error {
times, err := s.ps.CPUTimes()
times, err := s.ps.CPUTimes(s.PerCPU, s.TotalCPU)
if err != nil {
return fmt.Errorf("error getting CPU info: %s", err)
}