Add a collector for ZFS, currently focussed on ARC stats.
It is tested on FreeBSD 10.2-RELEASE and Linux (ZFS on Linux 0.6.5.4). On FreeBSD, Solaris, etc. ZFS metrics are exposed through sysctls. ZFS on Linux exposes the same metrics through procfs `/proc/spl/...`. In addition to sysctl metrics, 'computed metrics' are exposed by the collector, which are based on several sysctl values. There is some conditional logic involved in computing these metrics which cannot be easily mapped to PromQL. Not all 92 ARC sysctls are exposed right now but this can be changed with one additional LOC each.
This commit is contained in:
parent
dde59014b8
commit
f29f3873ea
10 changed files with 678 additions and 0 deletions
41
collector/zfs_zpool.go
Normal file
41
collector/zfs_zpool.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// zpool metrics
|
||||
|
||||
func (c *zfsCollector) parseZpoolOutput(reader io.Reader, handler func(string, string, float64)) (err error) {
|
||||
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
|
||||
fields := strings.Fields(scanner.Text())
|
||||
if len(fields) != 4 {
|
||||
return fmt.Errorf("Unexpected output of zpool command")
|
||||
}
|
||||
|
||||
valueString := fields[2]
|
||||
switch {
|
||||
case strings.HasSuffix(fields[2], "%"):
|
||||
percentage := strings.TrimSuffix(fields[2], "%")
|
||||
valueString = "0." + percentage
|
||||
case strings.HasSuffix(fields[2], "x"):
|
||||
valueString = strings.TrimSuffix(fields[2], "x")
|
||||
}
|
||||
|
||||
value, err := strconv.ParseFloat(valueString, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
handler(fields[0], fields[1], value)
|
||||
|
||||
}
|
||||
return scanner.Err()
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue