Add a collector for ZFS, currently focussed on ARC stats.

It is tested on FreeBSD 10.2-RELEASE and Linux (ZFS on Linux 0.6.5.4).

On FreeBSD, Solaris, etc. ZFS metrics are exposed through sysctls.
ZFS on Linux exposes the same metrics through procfs `/proc/spl/...`.

In addition to sysctl metrics, 'computed metrics' are exposed by
the collector, which are based on several sysctl values.
There is some conditional logic involved in computing these metrics
which cannot be easily mapped to PromQL.

Not all 92 ARC sysctls are exposed right now but this can be changed
with one additional LOC each.
This commit is contained in:
Christian Schwarz 2016-02-25 13:55:02 +01:00 committed by Joe Handzik
commit f29f3873ea
10 changed files with 678 additions and 0 deletions

View file

@ -0,0 +1,59 @@
package collector
import (
"os"
"testing"
)
func TestZpoolParsing(t *testing.T) {
zpoolOutput, err := os.Open("fixtures/zfs/zpool_stats_stdout.txt")
if err != nil {
t.Fatal(err)
}
defer zpoolOutput.Close()
c := zfsCollector{}
if err != nil {
t.Fatal(err)
}
pools := make([]string, 2)
troutSize := float64(-1)
troutDedupratio := float64(-1)
zrootCapacity := float64(-1)
err = c.parseZpoolOutput(zpoolOutput, func(pool, name string, value float64) {
pools = append(pools, pool)
if pool == "trout" && name == "size" {
troutSize = value
}
if pool == "trout" && name == "dedupratio" {
troutDedupratio = value
}
if pool == "zroot" && name == "capacity" {
zrootCapacity = value
}
})
if err != nil {
t.Fatal(err)
}
if pools[0] == "trout" && pools[1] == "zroot" {
t.Fatal("Did not parse all pools in fixture")
}
if troutSize != float64(4294967296) {
t.Fatal("Unexpected value for pool 'trout's size value")
}
if troutDedupratio != float64(1.0) {
t.Fatal("Unexpected value for pool 'trout's dedupratio value")
}
if zrootCapacity != float64(0.5) {
t.Fatal("Unexpected value for pool 'zroot's capacity value")
}
}