Skip to content

Instantly share code, notes, and snippets.

@jovimon
Last active August 28, 2019 16:46
Show Gist options
  • Save jovimon/e026c38ce262f2de951c3d2cefc729ad to your computer and use it in GitHub Desktop.
Save jovimon/e026c38ce262f2de951c3d2cefc729ad to your computer and use it in GitHub Desktop.
FreeNAS CollectD Zpool space metrics collector

FreeNAS CollectD Zpool space metrics collector

Quick and dirty script to get zpool space stats into CollectD so you can forward them to Grafana.

Steps:

  1. Create a file with the following script:
#!/bin/bash

HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
INTERVAL="${COLLECTD_INTERVAL:-60}"

while sleep "$INTERVAL"
do

zpools=$(zpool list -Hp -o name | grep -v boot)

for i in $zpools
do
used=$(zpool list -Hp -o allocated $i)
free=$(zpool list -Hp -o free $i)
echo "PUTVAL $HOSTNAME/zpool-$i/free interval=$INTERVAL N:$free"
echo "PUTVAL $HOSTNAME/zpool-$i/used interval=$INTERVAL N:$used"
done

done
  1. Add following line to /etc/local/collectd.conf in the "exec" plugin, with the filename of the script you created in the step before.

    Exec "nobody" "<your filename>"

2b. If you want your configuration to survive reboots, make the same change to /conf/base/etc/ix.rc.d/ix-collectd. Beware changing this file will make the config survive reboots, but apparently not FreeNAS version upgrades.

  1. Restart collectd service

    service collectd restart

  2. Check if the rrd files are created.

    ls -l /var/db/collectd/rrd/localhost/zpool-*

/var/db/collectd/rrd/localhost/zpool-almacen:
total 529
-rw-r--r--  1 root  wheel  148648 Jul 31 22:36 free.rrd
-rw-r--r--  1 root  wheel  148648 Jul 31 22:36 used.rrd

/var/db/collectd/rrd/localhost/zpool-principal:
total 529
-rw-r--r--  1 root  wheel  148648 Jul 31 22:36 free.rrd
-rw-r--r--  1 root  wheel  148648 Jul 31 22:36 used.rrd

/var/db/collectd/rrd/localhost/zpool-raid:
total 529
-rw-r--r--  1 root  wheel  148648 Jul 31 22:36 free.rrd
-rw-r--r--  1 root  wheel  148648 Jul 31 22:36 used.rrd
  1. Go to wherever you send your metrics and create some beautiful panels.

If files are not created.

You can set debug logging in collectd (https://collectd.org/wiki/index.php/Plugin:LogFile) adding the following lines to /etc/local/collectd.conf:

LoadPlugin "logfile"
<Plugin "logfile">
  LogLevel "debug"
  File "/var/log/collectd.log"
  Timestamp true
</Plugin>

And then looking into /var/log/collectd.log file. If you see entries like "No such dataset registered: " you have to add the definition of all of the metrics to the /usr/local/share/collectd/types.db file:

free value:GAUGE:0:U
used value:GAUGE:0:U
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment