Early init of procfs (#1315)

Minor change to match naming convention in other collectors.

Initialize the proc or sys FS instance once while initializing
each collector instead of re-creating for each metric update.

Signed-off-by: Paul Gier <pgier@redhat.com>
This commit is contained in:
Paul Gier 2019-04-10 11:16:12 -05:00 committed by Ben Kochie
commit b1298677aa
8 changed files with 63 additions and 47 deletions

View file

@ -18,7 +18,8 @@ package collector
import (
"testing"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/prometheus/procfs"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
func TestReadProcessStatus(t *testing.T) {
@ -26,7 +27,12 @@ func TestReadProcessStatus(t *testing.T) {
t.Fatal(err)
}
want := 1
pids, states, threads, err := getAllocatedThreads()
fs, err := procfs.NewFS(*procPath)
if err != nil {
t.Errorf("failed to open procfs: %v", err)
}
c := processCollector{fs: fs}
pids, states, threads, err := c.getAllocatedThreads()
if err != nil {
t.Fatalf("Cannot retrieve data from procfs getAllocatedThreads function: %v ", err)
}