2018-07-11 23:43:49 +00:00
|
|
|
package swap
|
2018-07-02 20:07:57 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-07-11 23:43:49 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/inputs/system"
|
2018-07-02 20:07:57 +00:00
|
|
|
"github.com/influxdata/telegraf/testutil"
|
|
|
|
"github.com/shirou/gopsutil/mem"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSwapStats(t *testing.T) {
|
2018-07-11 23:43:49 +00:00
|
|
|
var mps system.MockPS
|
2018-07-02 20:07:57 +00:00
|
|
|
var err error
|
|
|
|
defer mps.AssertExpectations(t)
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
|
|
|
|
sms := &mem.SwapMemoryStat{
|
|
|
|
Total: 8123,
|
|
|
|
Used: 1232,
|
|
|
|
Free: 6412,
|
|
|
|
UsedPercent: 12.2,
|
|
|
|
Sin: 7,
|
|
|
|
Sout: 830,
|
|
|
|
}
|
|
|
|
|
|
|
|
mps.On("SwapStat").Return(sms, nil)
|
|
|
|
|
|
|
|
err = (&SwapStats{&mps}).Gather(&acc)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
swapfields := map[string]interface{}{
|
|
|
|
"total": uint64(8123),
|
|
|
|
"used": uint64(1232),
|
|
|
|
"used_percent": float64(12.2),
|
|
|
|
"free": uint64(6412),
|
|
|
|
}
|
|
|
|
acc.AssertContainsTaggedFields(t, "swap", swapfields, make(map[string]string))
|
|
|
|
}
|