Quick and dirty script to get zpool space stats into CollectD so you can forward them to Grafana.
Steps:
- 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
-
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.
-
Restart collectd service
service collectd restart
-
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
- Go to wherever you send your metrics and create some beautiful panels.
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