forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_test.go
53 lines (45 loc) · 1.24 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
package system
import (
"testing"
"github.com/influxdata/telegraf/testutil"
"github.com/shirou/gopsutil/mem"
"github.com/stretchr/testify/require"
)
func TestMemStats(t *testing.T) {
var mps 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,
}
mps.On("VMStat").Return(vms, nil)
err = (&MemStats{&mps}).Gather(&acc)
require.NoError(t, err)
memfields := 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),
}
acc.AssertContainsTaggedFields(t, "mem", memfields, make(map[string]string))
acc.Metrics = nil
}