2015-10-04 05:09:18 +00:00
|
|
|
package procstat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
2015-10-05 22:45:40 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/influxdb/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())
|
|
|
|
specifications := []*Specification{&Specification{PidFile: file.Name(), Prefix: "foo"}}
|
|
|
|
p := Procstat{
|
|
|
|
Specifications: specifications,
|
|
|
|
}
|
|
|
|
p.Gather(&acc)
|
|
|
|
assert.True(t, acc.HasFloatValue("foo_cpu_user"))
|
|
|
|
assert.True(t, acc.HasUIntValue("foo_memory_vms"))
|
|
|
|
}
|