From 3c9e7799891a95db684c5772770698fa242f8502 Mon Sep 17 00:00:00 2001 From: Joe Handzik Date: Mon, 23 Jan 2017 12:19:51 -0600 Subject: [PATCH] ZFS Collector: Add vdev_cache_stats functionality Signed-Off-By: Joe Handzik --- collector/fixtures/e2e-output.txt | 9 +++++ .../proc/spl/kstat/zfs/vdev_cache_stats | 5 +++ collector/zfs.go | 5 +++ collector/zfs_linux.go | 21 ++++++++--- collector/zfs_linux_test.go | 36 +++++++++++++++++++ 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 collector/fixtures/proc/spl/kstat/zfs/vdev_cache_stats diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index 2200466c..b58f3d23 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -2383,6 +2383,15 @@ node_zfsFetch_stride_hits 7.06799e+06 # HELP node_zfsFetch_stride_misses kstat.zfs.misc.zfetchstats.stride_misses # TYPE node_zfsFetch_stride_misses untyped node_zfsFetch_stride_misses 0 +# HELP node_zfsVdevCache_delegations kstat.zfs.misc.vdev_cache_stats.delegations +# TYPE node_zfsVdevCache_delegations untyped +node_zfsVdevCache_delegations 40 +# HELP node_zfsVdevCache_hits kstat.zfs.misc.vdev_cache_stats.hits +# TYPE node_zfsVdevCache_hits untyped +node_zfsVdevCache_hits 0 +# HELP node_zfsVdevCache_misses kstat.zfs.misc.vdev_cache_stats.misses +# TYPE node_zfsVdevCache_misses untyped +node_zfsVdevCache_misses 0 # HELP node_zfsZil_zil_commit_count kstat.zfs.misc.zil.zil_commit_count # TYPE node_zfsZil_zil_commit_count untyped node_zfsZil_zil_commit_count 10 diff --git a/collector/fixtures/proc/spl/kstat/zfs/vdev_cache_stats b/collector/fixtures/proc/spl/kstat/zfs/vdev_cache_stats new file mode 100644 index 00000000..4a1acc05 --- /dev/null +++ b/collector/fixtures/proc/spl/kstat/zfs/vdev_cache_stats @@ -0,0 +1,5 @@ +8 1 0x01 3 144 8012540758 352116106118781 +name type data +delegations 4 40 +hits 4 0 +misses 4 0 diff --git a/collector/zfs.go b/collector/zfs.go index 170d6964..37a959e1 100644 --- a/collector/zfs.go +++ b/collector/zfs.go @@ -35,6 +35,7 @@ type zfsSubsystemName string const ( arc = zfsSubsystemName("zfsArc") + vdevCache = zfsSubsystemName("zfsVdevCache") zfetch = zfsSubsystemName("zfsFetch") zil = zfsSubsystemName("zfsZil") zpoolSubsystem = zfsSubsystemName("zfsPool") @@ -81,6 +82,10 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) { err = c.updateZil(ch) if err != nil { return err } + // VdevCacheStats + err = c.updateVdevCacheStats(ch) + if err != nil { return err } + // Pool stats return c.updatePoolStats(ch) } diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index f5df84c3..62031288 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go @@ -27,10 +27,11 @@ import ( ) const ( - zfsProcpathBase = "spl/kstat/zfs/" - zfsArcstatsExt = "arcstats" - zfsFetchstatsExt = "zfetchstats" - zfsZilExt = "zil" + zfsProcpathBase = "spl/kstat/zfs/" + zfsArcstatsExt = "arcstats" + zfsFetchstatsExt = "zfetchstats" + zfsVdevCacheStatsExt = "vdev_cache_stats" + zfsZilExt = "zil" ) func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) { @@ -78,6 +79,18 @@ func (c *zfsCollector) updateZil(ch chan<- prometheus.Metric) (err error) { }) } +func (c *zfsCollector) updateVdevCacheStats(ch chan<- prometheus.Metric) (err error) { + file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsVdevCacheStatsExt)) + if err != nil { + return err + } + defer file.Close() + + return c.parseProcfsFile(file, zfsVdevCacheStatsExt, func(s zfsSysctl, v zfsMetricValue) { + ch <- c.constSysctlMetric(vdevCache, s, v) + }) +} + func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmt_ext string, handler func(zfsSysctl, zfsMetricValue)) (err error) { scanner := bufio.NewScanner(reader) diff --git a/collector/zfs_linux_test.go b/collector/zfs_linux_test.go index 945a4af6..3230863f 100644 --- a/collector/zfs_linux_test.go +++ b/collector/zfs_linux_test.go @@ -125,3 +125,39 @@ func TestZilParsing(t *testing.T) { t.Fatal("Zil parsing handler was not called for some expected sysctls") } } + +func TestVdevCacheStatsParsing(t *testing.T) { + vdevCacheStatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/vdev_cache_stats") + if err != nil { + t.Fatal(err) + } + defer vdevCacheStatsFile.Close() + + c := zfsCollector{} + if err != nil { + t.Fatal(err) + } + + handlerCalled := false + err = c.parseProcfsFile(vdevCacheStatsFile, "vdev_cache_stats", func(s zfsSysctl, v zfsMetricValue) { + + if s != zfsSysctl("kstat.zfs.misc.vdev_cache_stats.delegations") { + return + } + + handlerCalled = true + + if v != zfsMetricValue(40) { + t.Fatalf("Incorrect value parsed from procfs data") + } + + }) + + if err != nil { + t.Fatal(err) + } + + if !handlerCalled { + t.Fatal("VdevCacheStats parsing handler was not called for some expected sysctls") + } +}