Skip to content

Commit

Permalink
fix(inputs.zfs): Support gathering metrics on zfs 2.2.0 and later (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
delichik authored Nov 13, 2023
1 parent 19c3d26 commit b7e7756
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 4 deletions.
24 changes: 23 additions & 1 deletion plugins/inputs/zfs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions plugins/inputs/zfs/zfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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)
Expand Down
62 changes: 61 additions & 1 deletion plugins/inputs/zfs/zfs_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -235,16 +262,21 @@ 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

err = z.Gather(&acc)
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) {
Expand Down Expand Up @@ -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),
}
}

0 comments on commit b7e7756

Please sign in to comment.