ZFS Collector: Add xuio_stats functionality

Signed-Off-By: Joe Handzik <joseph.t.handzik@hpe.com>
This commit is contained in:
Joe Handzik 2017-01-23 12:33:35 -06:00
parent 3c9e779989
commit 05048c067d
5 changed files with 80 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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)

View File

@ -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")
}
}