From 05048c067d6116d4d7acc0b9f276fdc64caf13b3 Mon Sep 17 00:00:00 2001 From: Joe Handzik Date: Mon, 23 Jan 2017 12:33:35 -0600 Subject: [PATCH] ZFS Collector: Add xuio_stats functionality Signed-Off-By: Joe Handzik --- collector/fixtures/e2e-output.txt | 18 ++++++++++ .../fixtures/proc/spl/kstat/zfs/xuio_stats | 8 +++++ collector/zfs.go | 5 +++ collector/zfs_linux.go | 13 +++++++ collector/zfs_linux_test.go | 36 +++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 collector/fixtures/proc/spl/kstat/zfs/xuio_stats diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index b58f3d23..9547ca93 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt @@ -2392,6 +2392,24 @@ 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_zfsXuio_onloan_read_buf kstat.zfs.misc.xuio_stats.onloan_read_buf +# TYPE node_zfsXuio_onloan_read_buf untyped +node_zfsXuio_onloan_read_buf 32 +# HELP node_zfsXuio_onloan_write_buf kstat.zfs.misc.xuio_stats.onloan_write_buf +# TYPE node_zfsXuio_onloan_write_buf untyped +node_zfsXuio_onloan_write_buf 0 +# HELP node_zfsXuio_read_buf_copied kstat.zfs.misc.xuio_stats.read_buf_copied +# TYPE node_zfsXuio_read_buf_copied untyped +node_zfsXuio_read_buf_copied 0 +# HELP node_zfsXuio_read_buf_nocopy kstat.zfs.misc.xuio_stats.read_buf_nocopy +# TYPE node_zfsXuio_read_buf_nocopy untyped +node_zfsXuio_read_buf_nocopy 0 +# HELP node_zfsXuio_write_buf_copied kstat.zfs.misc.xuio_stats.write_buf_copied +# TYPE node_zfsXuio_write_buf_copied untyped +node_zfsXuio_write_buf_copied 0 +# HELP node_zfsXuio_write_buf_nocopy kstat.zfs.misc.xuio_stats.write_buf_nocopy +# TYPE node_zfsXuio_write_buf_nocopy untyped +node_zfsXuio_write_buf_nocopy 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/xuio_stats b/collector/fixtures/proc/spl/kstat/zfs/xuio_stats new file mode 100644 index 00000000..87dd7d87 --- /dev/null +++ b/collector/fixtures/proc/spl/kstat/zfs/xuio_stats @@ -0,0 +1,8 @@ +2 1 0x01 6 288 8009100742 353415816865654 +name type data +onloan_read_buf 4 32 +onloan_write_buf 4 0 +read_buf_copied 4 0 +read_buf_nocopy 4 0 +write_buf_copied 4 0 +write_buf_nocopy 4 0 diff --git a/collector/zfs.go b/collector/zfs.go index 37a959e1..e794090e 100644 --- a/collector/zfs.go +++ b/collector/zfs.go @@ -36,6 +36,7 @@ type zfsSubsystemName string const ( arc = zfsSubsystemName("zfsArc") vdevCache = zfsSubsystemName("zfsVdevCache") + xuio = zfsSubsystemName("zfsXuio") zfetch = zfsSubsystemName("zfsFetch") zil = zfsSubsystemName("zfsZil") zpoolSubsystem = zfsSubsystemName("zfsPool") @@ -86,6 +87,10 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) { err = c.updateVdevCacheStats(ch) if err != nil { return err } + // XuioStats + err = c.updateXuioStats(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 62031288..e8330700 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go @@ -31,6 +31,7 @@ const ( zfsArcstatsExt = "arcstats" zfsFetchstatsExt = "zfetchstats" zfsVdevCacheStatsExt = "vdev_cache_stats" + zfsXuioStatsExt = "xuio_stats" zfsZilExt = "zil" ) @@ -91,6 +92,18 @@ func (c *zfsCollector) updateVdevCacheStats(ch chan<- prometheus.Metric) (err er }) } +func (c *zfsCollector) updateXuioStats(ch chan<- prometheus.Metric) (err error) { + file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsXuioStatsExt)) + if err != nil { + return err + } + defer file.Close() + + return c.parseProcfsFile(file, zfsXuioStatsExt, func(s zfsSysctl, v zfsMetricValue) { + ch <- c.constSysctlMetric(xuio, 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 3230863f..82b55a17 100644 --- a/collector/zfs_linux_test.go +++ b/collector/zfs_linux_test.go @@ -161,3 +161,39 @@ func TestVdevCacheStatsParsing(t *testing.T) { t.Fatal("VdevCacheStats parsing handler was not called for some expected sysctls") } } + +func TestXuioStatsParsing(t *testing.T) { + xuioStatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/xuio_stats") + if err != nil { + t.Fatal(err) + } + defer xuioStatsFile.Close() + + c := zfsCollector{} + if err != nil { + t.Fatal(err) + } + + handlerCalled := false + err = c.parseProcfsFile(xuioStatsFile, "xuio_stats", func(s zfsSysctl, v zfsMetricValue) { + + if s != zfsSysctl("kstat.zfs.misc.xuio_stats.onloan_read_buf") { + return + } + + handlerCalled = true + + if v != zfsMetricValue(32) { + t.Fatalf("Incorrect value parsed from procfs data") + } + + }) + + if err != nil { + t.Fatal(err) + } + + if !handlerCalled { + t.Fatal("XuioStats parsing handler was not called for some expected sysctls") + } +}