2016-12-06 19:22:26 +00:00
|
|
|
// Copyright 2016 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-02-25 12:55:02 +00:00
|
|
|
package collector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestArcstatsParsing(t *testing.T) {
|
|
|
|
arcstatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/arcstats")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer arcstatsFile.Close()
|
|
|
|
|
|
|
|
c := zfsCollector{}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
handlerCalled := false
|
|
|
|
err = c.parseArcstatsProcfsFile(arcstatsFile, func(s zfsSysctl, v zfsMetricValue) {
|
|
|
|
|
|
|
|
if s != zfsSysctl("kstat.zfs.misc.arcstats.hits") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
handlerCalled = true
|
|
|
|
|
|
|
|
if v != zfsMetricValue(8772612) {
|
|
|
|
t.Fatalf("Incorrect value parsed from procfs data")
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !handlerCalled {
|
|
|
|
t.Fatal("Arcstats parsing handler was not called for some expected sysctls")
|
|
|
|
}
|
|
|
|
}
|