forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.go
39 lines (30 loc) · 745 Bytes
/
system.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package system
import "github.com/influxdb/telegraf/plugins"
type SystemStats struct {
ps PS
}
func (_ *SystemStats) Description() string {
return "Read metrics about system load"
}
func (_ *SystemStats) SampleConfig() string { return "" }
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
}
acc.Add("load1", lv.Load1, nil)
acc.Add("load5", lv.Load5, nil)
acc.Add("load15", lv.Load15, nil)
return nil
}
func init() {
plugins.Add("system", func() plugins.Plugin {
return &SystemStats{ps: &systemPS{}}
})
}