2015-04-01 16:34:32 +00:00
|
|
|
package system
|
|
|
|
|
2015-08-31 20:03:38 +00:00
|
|
|
import (
|
|
|
|
"github.com/cloudfoundry/gosigar"
|
2015-05-18 19:15:15 +00:00
|
|
|
|
2015-08-31 20:03:38 +00:00
|
|
|
"github.com/influxdb/telegraf/plugins"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SystemStats struct{}
|
2015-05-18 19:15:15 +00:00
|
|
|
|
2015-05-18 22:10:11 +00:00
|
|
|
func (_ *SystemStats) Description() string {
|
2015-08-31 20:03:38 +00:00
|
|
|
return "Read metrics about system load & uptime"
|
2015-05-18 22:10:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *SystemStats) SampleConfig() string { return "" }
|
|
|
|
|
2015-08-31 20:03:38 +00:00
|
|
|
func (_ *SystemStats) add(acc plugins.Accumulator,
|
2015-05-18 19:15:15 +00:00
|
|
|
name string, val float64, tags map[string]string) {
|
|
|
|
if val >= 0 {
|
|
|
|
acc.Add(name, val, tags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 20:03:38 +00:00
|
|
|
func (_ *SystemStats) Gather(acc plugins.Accumulator) error {
|
|
|
|
loadavg := sigar.LoadAverage{}
|
|
|
|
if err := loadavg.Get(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
uptime := sigar.Uptime{}
|
|
|
|
if err := uptime.Get(); err != nil {
|
2015-05-18 19:15:15 +00:00
|
|
|
return err
|
2015-04-06 23:03:09 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 20:03:38 +00:00
|
|
|
acc.Add("load1", loadavg.One, nil)
|
|
|
|
acc.Add("load5", loadavg.Five, nil)
|
|
|
|
acc.Add("load15", loadavg.Fifteen, nil)
|
|
|
|
acc.Add("uptime", uptime.Length, nil)
|
|
|
|
acc.Add("uptime_format", uptime.Format(), nil)
|
2015-05-18 19:15:15 +00:00
|
|
|
|
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 {
|
2015-08-31 20:03:38 +00:00
|
|
|
return &SystemStats{}
|
2015-04-01 16:34:32 +00:00
|
|
|
})
|
|
|
|
}
|