forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.go
74 lines (65 loc) · 2.03 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package mem
import (
"fmt"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/inputs/system"
)
type MemStats struct {
ps system.PS
}
func (_ *MemStats) Description() string {
return "Read metrics about memory usage"
}
func (_ *MemStats) SampleConfig() string { return "" }
func (s *MemStats) Gather(acc telegraf.Accumulator) error {
vm, err := s.ps.VMStat()
if err != nil {
return fmt.Errorf("error getting virtual memory info: %s", err)
}
fields := map[string]interface{}{
"total": vm.Total,
"available": vm.Available,
"used": vm.Used,
"free": vm.Free,
"cached": vm.Cached,
"buffered": vm.Buffers,
"active": vm.Active,
"inactive": vm.Inactive,
"wired": vm.Wired,
"slab": vm.Slab,
"used_percent": 100 * float64(vm.Used) / float64(vm.Total),
"available_percent": 100 * float64(vm.Available) / float64(vm.Total),
"commit_limit": vm.CommitLimit,
"committed_as": vm.CommittedAS,
"dirty": vm.Dirty,
"high_free": vm.HighFree,
"high_total": vm.HighTotal,
"huge_page_size": vm.HugePageSize,
"huge_pages_free": vm.HugePagesFree,
"huge_pages_total": vm.HugePagesTotal,
"low_free": vm.LowFree,
"low_total": vm.LowTotal,
"mapped": vm.Mapped,
"page_tables": vm.PageTables,
"shared": vm.Shared,
"sreclaimable": vm.SReclaimable,
"sunreclaim": vm.SUnreclaim,
"swap_cached": vm.SwapCached,
"swap_free": vm.SwapFree,
"swap_total": vm.SwapTotal,
"vmalloc_chunk": vm.VMallocChunk,
"vmalloc_total": vm.VMallocTotal,
"vmalloc_used": vm.VMallocUsed,
"write_back": vm.Writeback,
"write_back_tmp": vm.WritebackTmp,
}
acc.AddGauge("mem", fields, nil)
return nil
}
func init() {
ps := system.NewSystemPS()
inputs.Add("mem", func() telegraf.Input {
return &MemStats{ps: ps}
})
}