read contents of objset file (#1632)

* added objread functionality

Signed-off-by: Sudharshann D <sudhar287@gmail.com>
This commit is contained in:
Sudhar287 2020-05-13 15:06:00 -04:00 committed by GitHub
commit 6807e5319b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 238 additions and 6 deletions

View file

@ -311,6 +311,46 @@ func TestZpoolParsing(t *testing.T) {
}
}
func TestZpoolObjsetParsing(t *testing.T) {
zpoolPaths, err := filepath.Glob("fixtures/proc/spl/kstat/zfs/*/objset-*")
if err != nil {
t.Fatal(err)
}
c := zfsCollector{}
if err != nil {
t.Fatal(err)
}
handlerCalled := false
for _, zpoolPath := range zpoolPaths {
file, err := os.Open(zpoolPath)
if err != nil {
t.Fatal(err)
}
err = c.parsePoolObjsetFile(file, zpoolPath, func(poolName string, datasetName string, s zfsSysctl, v uint64) {
if s != zfsSysctl("kstat.zfs.misc.objset.writes") {
return
}
handlerCalled = true
if v != uint64(0) && v != uint64(4) && v != uint64(10) {
t.Fatalf("Incorrect value parsed from procfs data %v", v)
}
})
file.Close()
if err != nil {
t.Fatal(err)
}
}
if !handlerCalled {
t.Fatal("Zpool parsing handler was not called for some expected sysctls")
}
}
func TestAbdstatsParsing(t *testing.T) {
abdstatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/abdstats")
if err != nil {