diff --git a/plugins/inputs/zfs/README.md b/plugins/inputs/zfs/README.md index 77448c93c..28faca361 100644 --- a/plugins/inputs/zfs/README.md +++ b/plugins/inputs/zfs/README.md @@ -223,6 +223,27 @@ For ZFS >= 2.1.x the format has changed significantly: - nunlinks (integer, count) - nunlinked (integer, count) +For ZFS >= 2.2.x the following additional fields are available: + +- additional fields for ZFS > 2.2.x + - zil_commit_count (integer, count) + - zil_commit_writer_count (integer, count) + - zil_itx_count (integer, count) + - zil_itx_indirect_count (integer, count) + - zil_itx_indirect_bytes (integer, bytes) + - zil_itx_copied_count (integer, count) + - zil_itx_copied_bytes (integer, bytes) + - zil_itx_needcopy_count (integer, count) + - zil_itx_needcopy_bytes (integer, bytes) + - zil_itx_metaslab_normal_count (integer, count) + - zil_itx_metaslab_normal_bytes (integer, bytes) + - zil_itx_metaslab_normal_write (integer, bytes) + - zil_itx_metaslab_normal_alloc (integer, bytes) + - zil_itx_metaslab_slog_count (integer, count) + - zil_itx_metaslab_slog_bytes (integer, bytes) + - zil_itx_metaslab_slog_write (integer, bytes) + - zil_itx_metaslab_slog_alloc (integer, bytes) + On FreeBSD: - zfs_pool @@ -391,6 +412,7 @@ memory is too low) ### ZIL (Linux Only) -note: ZIL measurements are system-wide, neither per-pool nor per-dataset +note: `zil` measurements in `kstatMetrics` are system-wide, in `poolMetrics` +they are pool-wide `zil_commit_count` counts when ZFS transactions are committed to a ZIL diff --git a/plugins/inputs/zfs/zfs_linux.go b/plugins/inputs/zfs/zfs_linux.go index 1a5ab8297..7409c91cc 100644 --- a/plugins/inputs/zfs/zfs_linux.go +++ b/plugins/inputs/zfs/zfs_linux.go @@ -84,7 +84,7 @@ func getTags(pools []poolInfo) map[string]string { } func gather(lines []string, fileLines int) ([]string, []string, error) { - if len(lines) != fileLines { + if len(lines) < fileLines { return nil, nil, errors.New("expected lines in kstat does not match") } @@ -172,7 +172,7 @@ func gatherPoolStats(pool poolInfo, acc telegraf.Accumulator) error { } if gatherErr != nil { - return err + return gatherErr } acc.AddFields("zfs_pool", fields, tags) diff --git a/plugins/inputs/zfs/zfs_linux_test.go b/plugins/inputs/zfs/zfs_linux_test.go index 20604df8d..ee45c45f4 100644 --- a/plugins/inputs/zfs/zfs_linux_test.go +++ b/plugins/inputs/zfs/zfs_linux_test.go @@ -130,6 +130,33 @@ nread 4 1884160 nunlinks 4 14148 nunlinked 4 14147 ` +const objsetV22Contents = `36 1 0x01 7 2160 5214787391 74985931356512 +name type data +dataset_name 7 HOMEV22 +writes 4 978 +nwritten 4 6450688 +reads 4 22 +nread 4 1884160 +nunlinks 4 14148 +nunlinked 4 14147 +zil_commit_count 4 1 +zil_commit_writer_count 4 2 +zil_itx_count 4 3 +zil_itx_indirect_count 4 4 +zil_itx_indirect_bytes 4 5 +zil_itx_copied_count 4 6 +zil_itx_copied_bytes 4 7 +zil_itx_needcopy_count 4 8 +zil_itx_needcopy_bytes 4 9 +zil_itx_metaslab_normal_count 4 10 +zil_itx_metaslab_normal_bytes 4 11 +zil_itx_metaslab_normal_write 4 12 +zil_itx_metaslab_normal_alloc 4 13 +zil_itx_metaslab_slog_count 4 14 +zil_itx_metaslab_slog_bytes 4 15 +zil_itx_metaslab_slog_write 4 16 +zil_itx_metaslab_slog_alloc 4 17 +` const zilContents = `7 1 0x01 14 672 34118481334 437444452158445 name type data zil_commit_count 4 77 @@ -235,6 +262,8 @@ func TestZfsPoolMetrics(t *testing.T) { err = os.WriteFile(testKstatPath+"/HOME/objset-0x20a", []byte(objsetContents), 0640) require.NoError(t, err) + err = os.WriteFile(testKstatPath+"/HOME/objset-0x20b", []byte(objsetV22Contents), 0640) + require.NoError(t, err) acc.Metrics = nil @@ -242,9 +271,12 @@ func TestZfsPoolMetrics(t *testing.T) { require.NoError(t, err) tags["dataset"] = "HOME" - poolMetrics = getPoolMetricsNewFormat() acc.AssertContainsTaggedFields(t, "zfs_pool", poolMetrics, tags) + + tags["dataset"] = "HOMEV22" + poolMetrics = getPoolMetricsNewFormatV22() + acc.AssertContainsTaggedFields(t, "zfs_pool", poolMetrics, tags) } func TestZfsGeneratesMetrics(t *testing.T) { @@ -554,3 +586,31 @@ func getPoolMetricsNewFormat() map[string]interface{} { "writes": int64(978), } } + +func getPoolMetricsNewFormatV22() map[string]interface{} { + return map[string]interface{}{ + "nread": int64(1884160), + "nunlinked": int64(14147), + "nunlinks": int64(14148), + "nwritten": int64(6450688), + "reads": int64(22), + "writes": int64(978), + "zil_commit_count": int64(1), + "zil_commit_writer_count": int64(2), + "zil_itx_count": int64(3), + "zil_itx_indirect_count": int64(4), + "zil_itx_indirect_bytes": int64(5), + "zil_itx_copied_count": int64(6), + "zil_itx_copied_bytes": int64(7), + "zil_itx_needcopy_count": int64(8), + "zil_itx_needcopy_bytes": int64(9), + "zil_itx_metaslab_normal_count": int64(10), + "zil_itx_metaslab_normal_bytes": int64(11), + "zil_itx_metaslab_normal_write": int64(12), + "zil_itx_metaslab_normal_alloc": int64(13), + "zil_itx_metaslab_slog_count": int64(14), + "zil_itx_metaslab_slog_bytes": int64(15), + "zil_itx_metaslab_slog_write": int64(16), + "zil_itx_metaslab_slog_alloc": int64(17), + } +}