telegraf/plugins/inputs/system/memory_test.go

54 lines
1.2 KiB
Go
Raw Normal View History

2015-12-11 20:07:32 +00:00
package system
import (
"testing"
2016-01-20 18:57:35 +00:00
"github.com/influxdata/telegraf/testutil"
2015-12-11 20:07:32 +00:00
"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,
2017-11-29 18:49:45 +00:00
Slab: 1234,
2018-01-03 00:37:11 +00:00
Wired: 134,
2015-12-11 20:07:32 +00:00
// Buffers: 771,
// Cached: 4312,
// Shared: 2142,
}
mps.On("VMStat").Return(vms, nil)
err = (&MemStats{&mps}).Gather(&acc)
require.NoError(t, err)
2016-01-05 23:58:35 +00:00
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),
2018-01-03 00:37:11 +00:00
"wired": uint64(134),
2017-11-29 18:49:45 +00:00
"slab": uint64(1234),
2016-01-05 23:58:35 +00:00
}
acc.AssertContainsTaggedFields(t, "mem", memfields, make(map[string]string))
2015-12-11 20:07:32 +00:00
acc.Metrics = nil
2015-12-11 20:07:32 +00:00
}