diff --git a/collector/pool_test.go b/collector/pool_test.go index c7b0796..bd3c65b 100644 --- a/collector/pool_test.go +++ b/collector/pool_test.go @@ -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 `, }, } diff --git a/collector/transform.go b/collector/transform.go index add3127..e931e97 100644 --- a/collector/transform.go +++ b/collector/transform.go @@ -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