Skip to content

Commit

Permalink
fix(transform): Add support for ancient ZFS fragmentation metric
Browse files Browse the repository at this point in the history
Fixes #26
  • Loading branch information
pdf committed Jan 28, 2023
1 parent f14e189 commit a0240d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions collector/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ zfs_pool_health{pool="suspendedpool"} 6
metricResults: `# HELP zfs_pool_unsupported !!! This property is unsupported, results are likely to be undesirable, please file an issue at https://github.com/pdf/zfs_exporter/issues to have this property supported !!!
# TYPE zfs_pool_unsupported gauge
zfs_pool_unsupported{pool="testpool"} 1024
`,
},
{
name: `legacy fragmentation`,
pools: []string{`testpool`},
propsRequested: []string{`fragmentation`},
metricNames: []string{`zfs_pool_fragmentation_ratio`},
propsResults: map[string]map[string]string{
`testpool`: {
`fragmentation`: `5%`,
},
},
metricResults: `# HELP zfs_pool_fragmentation_ratio The fragmentation ratio of the pool.
# TYPE zfs_pool_fragmentation_ratio gauge
zfs_pool_fragmentation_ratio{pool="testpool"} 0.05
`,
},
}
Expand Down
3 changes: 3 additions & 0 deletions collector/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func transformBool(value string) (float64, error) {
}

func transformPercentage(value string) (float64, error) {
if len(value) > 0 && value[len(value)-1] == '%' {
value = value[:len(value)-1]
}
v, err := transformNumeric(value)
if err != nil {
return -1, err
Expand Down

0 comments on commit a0240d1

Please sign in to comment.