Skip to content

Commit

Permalink
Create a new parseFreeBSDPoolObjsetStats function, to generate a list
Browse files Browse the repository at this point in the history
of per pool metrics to be queried via sysctl

Signed-off-by: Conall O'Brien <conall@conall.net>
  • Loading branch information
conallob committed Jul 20, 2023
1 parent 896b8a1 commit 75d23aa
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions collector/zfs_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (

"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"

"golang.org/x/sys/unix"
)

type zfsCollector struct {
Expand Down Expand Up @@ -264,3 +266,38 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {

return nil
}

func (c *zfsCollector) parseFreeBSDPoolObjsetStats() error {
zfsPoolMibPrefix := "kstat.zfs.pool.dataset"
zfsPoolObjs := []string{}

zfsDatasets, err := unix.Sysctl(zfsPoolMibPrefix)
if err != nil {
return fmt.Errorf("couldn't get sysctl: %w", err)
}
for dataset, _ := range zfsDatasets {
if strings.HasSuffix(dataset, ".dataset_name") {
zfsPoolObjs = append(zfsPoolObjs, strings.SplitAfter(dataset, ".")[3])
}
}

// TODO(conallob): Check if bsdSysCtl or prometheus.Metric should be used
perPoolMetric := []bsdSysctl{}
sysCtlMetrics := []string{
"nunlinked", "nunlinks", "nread", "reads", "nwritten", "writes",
}

for poolObj := range zfsPoolObjs {
for metric := range sysCtlMetrics {
sysCtlMetrics = append(sysCtlMetrics, {
name: fmt.SprintF("node_zfs_zpool_dataset_%s", metric),
description: fmt.SprintF("node_zfs_zpool_dataset_%s", metric),
mib: fmt.Sprintf("%s.%s.%s",
zfsPoolMibPrefix, poolObj, metric),
dataType: bsdSysctlTypeUint64,
valueType: prometheus.CounterValue,
})
}

return nil
}

0 comments on commit 75d23aa

Please sign in to comment.