forked from bigpigeon/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.go
48 lines (36 loc) · 989 Bytes
/
memory.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
40
41
42
43
44
45
46
47
48
// +build darwin linux openbsd windows
package memory
import (
"github.com/elastic/beats/metricbeat/helper"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/topbeat/system"
)
func init() {
helper.Registry.AddMetricSeter("system", "memory", New)
}
// New creates new instance of MetricSeter
func New() helper.MetricSeter {
return &MetricSeter{}
}
type MetricSeter struct{}
func (m *MetricSeter) Setup(ms *helper.MetricSet) error {
return nil
}
func (m *MetricSeter) Fetch(ms *helper.MetricSet, host string) (event common.MapStr, err error) {
memStat, err := system.GetMemory()
if err != nil {
logp.Warn("Getting memory details: %v", err)
return nil, err
}
swapStat, err := system.GetSwap()
if err != nil {
logp.Warn("Getting swap details: %v", err)
return nil, err
}
event = common.MapStr{
"mem": system.GetMemoryEvent(memStat),
"swap": system.GetSwapEvent(swapStat),
}
return event, nil
}