2015-04-01 16:34:32 +00:00
|
|
|
package system
|
|
|
|
|
2015-05-22 23:45:14 +00:00
|
|
|
import "github.com/influxdb/telegraf/plugins"
|
2015-05-18 19:15:15 +00:00
|
|
|
|
|
|
|
type SystemStats struct {
|
|
|
|
ps PS
|
|
|
|
}
|
|
|
|
|
2015-05-18 22:10:11 +00:00
|
|
|
func (_ *SystemStats) Description() string {
|
|
|
|
return "Read metrics about system load"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *SystemStats) SampleConfig() string { return "" }
|
|
|
|
|
2015-05-18 19:15:15 +00:00
|
|
|
func (s *SystemStats) add(acc plugins.Accumulator,
|
|
|
|
name string, val float64, tags map[string]string) {
|
|
|
|
if val >= 0 {
|
|
|
|
acc.Add(name, val, tags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SystemStats) Gather(acc plugins.Accumulator) error {
|
|
|
|
lv, err := s.ps.LoadAvg()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-04-06 23:03:09 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 19:15:15 +00:00
|
|
|
acc.Add("load1", lv.Load1, nil)
|
|
|
|
acc.Add("load5", lv.Load5, nil)
|
|
|
|
acc.Add("load15", lv.Load15, nil)
|
|
|
|
|
2015-04-06 16:32:10 +00:00
|
|
|
return nil
|
2015-04-01 16:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
plugins.Add("system", func() plugins.Plugin {
|
|
|
|
return &SystemStats{ps: &systemPS{}}
|
|
|
|
})
|
|
|
|
}
|