forked from SumoLogic/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_test.go
116 lines (106 loc) · 2.99 KB
/
memory_test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package mem
import (
"testing"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs/system"
"github.com/influxdata/telegraf/testutil"
"github.com/shirou/gopsutil/mem"
"github.com/stretchr/testify/require"
)
func TestMemStats(t *testing.T) {
var mps system.MockPS
var err error
defer mps.AssertExpectations(t)
var acc testutil.Accumulator
vms := &mem.VirtualMemoryStat{
Total: 12400,
Available: 7600,
Used: 5000,
Free: 1235,
Active: 8134,
Inactive: 1124,
Slab: 1234,
Wired: 134,
// Buffers: 771,
// Cached: 4312,
// Shared: 2142,
CommitLimit: 1,
CommittedAS: 118680,
Dirty: 4,
HighFree: 0,
HighTotal: 0,
HugePageSize: 4096,
HugePagesFree: 0,
HugePagesTotal: 0,
LowFree: 69936,
LowTotal: 255908,
Mapped: 42236,
PageTables: 1236,
Shared: 0,
SReclaimable: 1923022848,
SUnreclaim: 157728768,
SwapCached: 0,
SwapFree: 524280,
SwapTotal: 524280,
VMallocChunk: 3872908,
VMallocTotal: 3874808,
VMallocUsed: 1416,
Writeback: 0,
WritebackTmp: 0,
}
mps.On("VMStat").Return(vms, nil)
plugin := &MemStats{ps: &mps}
err = plugin.Init()
require.NoError(t, err)
plugin.platform = "linux"
require.NoError(t, err)
err = plugin.Gather(&acc)
require.NoError(t, err)
expected := []telegraf.Metric{
testutil.MustMetric(
"mem",
map[string]string{},
map[string]interface{}{
"total": uint64(12400),
"available": uint64(7600),
"used": uint64(5000),
"available_percent": float64(7600) / float64(12400) * 100,
"used_percent": float64(5000) / float64(12400) * 100,
"free": uint64(1235),
"cached": uint64(0),
"buffered": uint64(0),
"active": uint64(8134),
"inactive": uint64(1124),
// "wired": uint64(134),
"slab": uint64(1234),
"commit_limit": uint64(1),
"committed_as": uint64(118680),
"dirty": uint64(4),
"high_free": uint64(0),
"high_total": uint64(0),
"huge_page_size": uint64(4096),
"huge_pages_free": uint64(0),
"huge_pages_total": uint64(0),
"low_free": uint64(69936),
"low_total": uint64(255908),
"mapped": uint64(42236),
"page_tables": uint64(1236),
"shared": uint64(0),
"sreclaimable": uint64(1923022848),
"sunreclaim": uint64(157728768),
"swap_cached": uint64(0),
"swap_free": uint64(524280),
"swap_total": uint64(524280),
"vmalloc_chunk": uint64(3872908),
"vmalloc_total": uint64(3874808),
"vmalloc_used": uint64(1416),
"write_back": uint64(0),
"write_back_tmp": uint64(0),
},
time.Unix(0, 0),
telegraf.Gauge,
),
}
testutil.RequireMetricsEqual(t, expected, acc.GetTelegrafMetrics(), testutil.IgnoreTime())
}