ZFS Collector: Add zil functionality

Signed-Off-By: Joe Handzik <joseph.t.handzik@hpe.com>
pull/432/head
Joe Handzik 2017-01-23 11:56:39 -06:00
parent a3125ab4d9
commit a02ca9502c
5 changed files with 108 additions and 0 deletions

View File

@ -2383,6 +2383,45 @@ node_zfsFetch_stride_hits 7.06799e+06
# HELP node_zfsFetch_stride_misses kstat.zfs.misc.zfetchstats.stride_misses # HELP node_zfsFetch_stride_misses kstat.zfs.misc.zfetchstats.stride_misses
# TYPE node_zfsFetch_stride_misses untyped # TYPE node_zfsFetch_stride_misses untyped
node_zfsFetch_stride_misses 0 node_zfsFetch_stride_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
# HELP node_zfsZil_zil_commit_writer_count kstat.zfs.misc.zil.zil_commit_writer_count
# TYPE node_zfsZil_zil_commit_writer_count untyped
node_zfsZil_zil_commit_writer_count 0
# HELP node_zfsZil_zil_itx_copied_bytes kstat.zfs.misc.zil.zil_itx_copied_bytes
# TYPE node_zfsZil_zil_itx_copied_bytes untyped
node_zfsZil_zil_itx_copied_bytes 0
# HELP node_zfsZil_zil_itx_copied_count kstat.zfs.misc.zil.zil_itx_copied_count
# TYPE node_zfsZil_zil_itx_copied_count untyped
node_zfsZil_zil_itx_copied_count 0
# HELP node_zfsZil_zil_itx_count kstat.zfs.misc.zil.zil_itx_count
# TYPE node_zfsZil_zil_itx_count untyped
node_zfsZil_zil_itx_count 0
# HELP node_zfsZil_zil_itx_indirect_bytes kstat.zfs.misc.zil.zil_itx_indirect_bytes
# TYPE node_zfsZil_zil_itx_indirect_bytes untyped
node_zfsZil_zil_itx_indirect_bytes 0
# HELP node_zfsZil_zil_itx_indirect_count kstat.zfs.misc.zil.zil_itx_indirect_count
# TYPE node_zfsZil_zil_itx_indirect_count untyped
node_zfsZil_zil_itx_indirect_count 0
# HELP node_zfsZil_zil_itx_metaslab_normal_bytes kstat.zfs.misc.zil.zil_itx_metaslab_normal_bytes
# TYPE node_zfsZil_zil_itx_metaslab_normal_bytes untyped
node_zfsZil_zil_itx_metaslab_normal_bytes 0
# HELP node_zfsZil_zil_itx_metaslab_normal_count kstat.zfs.misc.zil.zil_itx_metaslab_normal_count
# TYPE node_zfsZil_zil_itx_metaslab_normal_count untyped
node_zfsZil_zil_itx_metaslab_normal_count 0
# HELP node_zfsZil_zil_itx_metaslab_slog_bytes kstat.zfs.misc.zil.zil_itx_metaslab_slog_bytes
# TYPE node_zfsZil_zil_itx_metaslab_slog_bytes untyped
node_zfsZil_zil_itx_metaslab_slog_bytes 0
# HELP node_zfsZil_zil_itx_metaslab_slog_count kstat.zfs.misc.zil.zil_itx_metaslab_slog_count
# TYPE node_zfsZil_zil_itx_metaslab_slog_count untyped
node_zfsZil_zil_itx_metaslab_slog_count 0
# HELP node_zfsZil_zil_itx_needcopy_bytes kstat.zfs.misc.zil.zil_itx_needcopy_bytes
# TYPE node_zfsZil_zil_itx_needcopy_bytes untyped
node_zfsZil_zil_itx_needcopy_bytes 0
# HELP node_zfsZil_zil_itx_needcopy_count kstat.zfs.misc.zil.zil_itx_needcopy_count
# TYPE node_zfsZil_zil_itx_needcopy_count untyped
node_zfsZil_zil_itx_needcopy_count 0
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter # TYPE process_cpu_seconds_total counter
# HELP process_max_fds Maximum number of open file descriptors. # HELP process_max_fds Maximum number of open file descriptors.

View File

@ -0,0 +1,15 @@
7 1 0x01 13 624 8012538347 351689526932992
name type data
zil_commit_count 4 10
zil_commit_writer_count 4 0
zil_itx_count 4 0
zil_itx_indirect_count 4 0
zil_itx_indirect_bytes 4 0
zil_itx_copied_count 4 0
zil_itx_copied_bytes 4 0
zil_itx_needcopy_count 4 0
zil_itx_needcopy_bytes 4 0
zil_itx_metaslab_normal_count 4 0
zil_itx_metaslab_normal_bytes 4 0
zil_itx_metaslab_slog_count 4 0
zil_itx_metaslab_slog_bytes 4 0

View File

@ -36,6 +36,7 @@ type zfsSubsystemName string
const ( const (
arc = zfsSubsystemName("zfsArc") arc = zfsSubsystemName("zfsArc")
zfetch = zfsSubsystemName("zfsFetch") zfetch = zfsSubsystemName("zfsFetch")
zil = zfsSubsystemName("zfsZil")
zpoolSubsystem = zfsSubsystemName("zfsPool") zpoolSubsystem = zfsSubsystemName("zfsPool")
) )
@ -76,6 +77,10 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
err = c.updateZfetchstats(ch) err = c.updateZfetchstats(ch)
if err != nil { return err } if err != nil { return err }
// Zil
err = c.updateZil(ch)
if err != nil { return err }
// Pool stats // Pool stats
return c.updatePoolStats(ch) return c.updatePoolStats(ch)
} }

View File

@ -30,6 +30,7 @@ const (
zfsProcpathBase = "spl/kstat/zfs/" zfsProcpathBase = "spl/kstat/zfs/"
zfsArcstatsExt = "arcstats" zfsArcstatsExt = "arcstats"
zfsFetchstatsExt = "zfetchstats" zfsFetchstatsExt = "zfetchstats"
zfsZilExt = "zil"
) )
func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) { func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) {
@ -65,6 +66,18 @@ func (c *zfsCollector) updateZfetchstats(ch chan<- prometheus.Metric) (err error
}) })
} }
func (c *zfsCollector) updateZil(ch chan<- prometheus.Metric) (err error) {
file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsZilExt))
if err != nil {
return err
}
defer file.Close()
return c.parseProcfsFile(file, zfsZilExt, func(s zfsSysctl, v zfsMetricValue) {
ch <- c.constSysctlMetric(zil, s, v)
})
}
func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmt_ext string, handler func(zfsSysctl, zfsMetricValue)) (err error) { func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmt_ext string, handler func(zfsSysctl, zfsMetricValue)) (err error) {
scanner := bufio.NewScanner(reader) scanner := bufio.NewScanner(reader)

View File

@ -89,3 +89,39 @@ func TestZfetchstatsParsing(t *testing.T) {
t.Fatal("Zfetchstats parsing handler was not called for some expected sysctls") t.Fatal("Zfetchstats parsing handler was not called for some expected sysctls")
} }
} }
func TestZilParsing(t *testing.T) {
zilFile, err := os.Open("fixtures/proc/spl/kstat/zfs/zil")
if err != nil {
t.Fatal(err)
}
defer zilFile.Close()
c := zfsCollector{}
if err != nil {
t.Fatal(err)
}
handlerCalled := false
err = c.parseProcfsFile(zilFile, "zil", func(s zfsSysctl, v zfsMetricValue) {
if s != zfsSysctl("kstat.zfs.misc.zil.zil_commit_count") {
return
}
handlerCalled = true
if v != zfsMetricValue(10) {
t.Fatalf("Incorrect value parsed from procfs data")
}
})
if err != nil {
t.Fatal(err)
}
if !handlerCalled {
t.Fatal("Zil parsing handler was not called for some expected sysctls")
}
}