2015-10-04 05:09:18 +00:00
|
|
|
package procstat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
2015-10-05 22:45:40 +00:00
|
|
|
|
2017-03-06 15:59:36 +00:00
|
|
|
"github.com/shirou/gopsutil/process"
|
2015-10-05 22:45:40 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2016-01-20 18:57:35 +00:00
|
|
|
"github.com/influxdata/telegraf/testutil"
|
2015-10-04 05:09:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGather(t *testing.T) {
|
|
|
|
var acc testutil.Accumulator
|
|
|
|
pid := os.Getpid()
|
|
|
|
file, err := ioutil.TempFile(os.TempDir(), "telegraf")
|
|
|
|
require.NoError(t, err)
|
|
|
|
file.Write([]byte(strconv.Itoa(pid)))
|
|
|
|
file.Close()
|
|
|
|
defer os.Remove(file.Name())
|
|
|
|
p := Procstat{
|
2016-01-07 00:56:30 +00:00
|
|
|
PidFile: file.Name(),
|
|
|
|
Prefix: "foo",
|
2017-03-06 15:59:36 +00:00
|
|
|
pidmap: make(map[int32]*process.Process),
|
2016-04-20 19:18:07 +00:00
|
|
|
tagmap: make(map[int32]map[string]string),
|
2015-10-04 05:09:18 +00:00
|
|
|
}
|
|
|
|
p.Gather(&acc)
|
2016-01-07 00:56:30 +00:00
|
|
|
assert.True(t, acc.HasFloatField("procstat", "foo_cpu_time_user"))
|
|
|
|
assert.True(t, acc.HasUIntField("procstat", "foo_memory_vms"))
|
2015-10-04 05:09:18 +00:00
|
|
|
}
|