ZFS Support

Tags: #<Tag:0x00007f064f9a3010> #<Tag:0x00007f064f9a2f48>

Hi Folks,
I just wonder if someone has plans to work on monitoring of ZFS filesystems especially ZOL (ZFS On Linux)

I found some puzzle parts:

# Filesystem usage for ZFS
if type zfs > /dev/null 2>&1 ; then
    echo '<<<zfsget>>>'
    zfs get -Hp name,quota,used,avail,mountpoint,type -t filesystem,volume || \
       zfs get -Hp name,quota,used,avail,mountpoint,type
    echo '[df]'
    df -PTlk -t zfs | sed 1d
fi

as also something like this for snmpd.conf

#Zpool Usage
extend .1.3.6.1.4.1.2021.88 zpool_name /bin/bash -c "sudo zpool list -H -o name"
extend .1.3.6.1.4.1.2021.88 zpool_snap /bin/bash -c "sudo zpool list -Ho name|for strzpool in `xargs`;do sudo zfs get -rHp -o value usedbysnapshots $strzpool|awk -F: '{sum+=$1} END{print sum}';done"
extend .1.3.6.1.4.1.2021.88 zpool_used /bin/bash -c "sudo zpool list -Ho name|xargs sudo zfs get -Hp -o value used"
extend .1.3.6.1.4.1.2021.88 zpool_data_used /bin/bash -c "sudo zpool list -Ho name|for strzpool in `xargs`;do snap=`sudo zfs get -rHp -o value usedbysnapshots $strzpool|awk -F: '{sum+=$1} END{print sum}'`;pool=`sudo zfs get -Hp -o value used $zpool`; echo $pool $snap|awk '{print (\$1-\$2);}';done"
extend .1.3.6.1.4.1.2021.88 zpool_available /bin/bash -c "sudo zpool list -Ho name|xargs sudo zfs get -Hp -o value available"
extend .1.3.6.1.4.1.2021.88 zpool_capacity /bin/bash -c "sudo zpool list -H -o capacity"


#ARC Usage
extend .1.3.6.1.4.1.2021.85 arc_meta_max /bin/bash -c "sudo grep arc_meta_max /proc/spl/kstat/zfs/arcstats |awk -F' ' '{print $(NF)}'"
extend .1.3.6.1.4.1.2021.85 arc_meta_used /bin/bash -c "sudo grep arc_meta_used /proc/spl/kstat/zfs/arcstats |awk -F' ' '{print $(NF)}'"
extend .1.3.6.1.4.1.2021.85 arc_size /bin/bash -c "sudo grep -m 1 size /proc/spl/kstat/zfs/arcstats |awk -F' ' '{print $(NF)}'"
extend .1.3.6.1.4.1.2021.85 arc_meta_limit /bin/bash -c "sudo grep arc_meta_limit /proc/spl/kstat/zfs/arcstats |awk -F' ' '{print $(NF)}'"
extend .1.3.6.1.4.1.2021.85 arc_meta_c_max /bin/bash -c "sudo grep c_max /proc/spl/kstat/zfs/arcstats |awk -F' ' '{print $(NF)}'"

#ARC Stats
extend .1.3.6.1.4.1.2021.89 arc_hits /bin/bash -c "sudo grep -m 1 hits /proc/spl/kstat/zfs/arcstats |awk -F' ' '{print $(NF)}'"
extend .1.3.6.1.4.1.2021.89 arc_misses /bin/bash -c "sudo grep misses /proc/spl/kstat/zfs/arcstats |awk -F' ' '{print $(NF)}'"

#L2ARC Stats
extend .1.3.6.1.4.1.2021.89 arc_l2_hits /bin/bash -c "sudo grep l2_hits /proc/spl/kstat/zfs/arcstats |awk -F' ' '{print $(NF)}'"
extend .1.3.6.1.4.1.2021.89 arc_l2_misses /bin/bash -c "sudo grep l2_misses /proc/spl/kstat/zfs/arcstats |awk -F' ' '{print $(NF)}'"

#VFS IOPS
extend .1.3.6.1.4.1.2021.90 vopstats_zfs_nread /bin/bash -c "humnum=$(sudo zpool iostat | tail -n 1 | awk -F' ' '{print $4}') ; case ${humnum: -1:1} in [0-9]) echo $humnum | tr -d ' ' ;; 'K') bc -p ${humnum: 0:-1}*1024**1 | tr -d ' ' ;; 'M') bc -p ${humnum: 0:-1}*1024**2 | tr -d ' ' ;; 'G') bc -p ${humnum: 0:-1}*1024**3 | tr -d ' ' ;; 'T') bc -p ${humnum: 0:-1}*1024**4 | tr -d ' ' ;; 'P') bc -p ${humnum: 0:-1}*1024**5 ;; esac"
extend .1.3.6.1.4.1.2021.90 vopstats_zfs_nwrite /bin/bash -c "humnum=$(sudo zpool iostat | tail -n 1 | awk -F' ' '{print $5}') ; case ${humnum: -1:1} in [0-9]) echo $humnum | tr -d ' ' ;; 'K') bc -p ${humnum: 0:-1}*1024**1 | tr -d ' ' ;; 'M') bc -p ${humnum: 0:-1}*1024**2 | tr -d ' ' ;; 'G') bc -p ${humnum: 0:-1}*1024**3 | tr -d ' ' ;; 'T') bc -p ${humnum: 0:-1}*1024**4 | tr -d ' ' ;; 'P') bc -p ${humnum: 0:-1}*1024**5 ;; esac"

#VFS Throughput
extend .1.3.6.1.4.1.2021.90 vopstats_zfs_read_bytes /bin/bash -c "humnum=$(sudo zpool iostat | tail -n 1 | awk -F' ' '{print $6}') ; case ${humnum: -1:1} in [0-9]) echo $humnum | tr -d ' ' ;; 'K') bc -p ${humnum: 0:-1}*1024**1 | tr -d ' ' ;; 'M') bc -p ${humnum: 0:-1}*1024**2 | tr -d ' ' ;; 'G') calc -p ${humnum: 0:-1}*1024**3 | tr -d ' ' ;; 'T') calc -p ${humnum: 0:-1}*1024**4 | tr -d ' ' ;; 'P') calc -p ${humnum: 0:-1}*1024**5 ;; esac"
extend .1.3.6.1.4.1.2021.90 vopstats_zfs_write_bytes /bin/bash -c "humnum=$(sudo zpool iostat | tail -n 1 | awk -F' ' '{print $7}') ; case ${humnum: -1:1} in [0-9]) echo $humnum | tr -d ' ' ;; 'K') bc -p ${humnum: 0:-1}*1024**1 | tr -d ' ' ;; 'M') bc -p ${humnum: 0:-1}*1024**2 | tr -d ' ' ;; 'G') bc -p ${humnum: 0:-1}*1024**3 | tr -d ' ' ;; 'T') bc -p ${humnum: 0:-1}*1024**4 | tr -d ' ' ;; 'P') bc -p ${humnum: 0:-1}*1024**5 ;; esac"

#DeDupe Ratio
extend .1.3.6.1.4.1.2021.91 zfs_dedup_ratio /bin/bash -c "zpool list | grep vol | cut -d \" \" -f 13 | tr -cd '[:digit:]'"

but I am missing the skills to combine all this and let LibreNMS draw some nice graphs :wink:

Thank you,
Wolfgang

(Mod edit - codeblocks making reading easier, and code doesn’t get interpreted at markdown :slight_smile: )

5 Likes

download original freebsd script
sudo wget https://github.com/librenms/librenms-agent/raw/master/snmp/zfs-freebsd -O /etc/snmp/zfs

make it executable
sudo chmod a+x /etc/snmp/zfs

edit snmpd.conf
sudo vi /etc/snmp/snmpd.conf

add string to end of snmpd.conf
extend zfs /usr/bin/sudo /etc/snmp/zfs

create kstat.zfs
sudo vi /etc/snmp/kstat.zfs

add strings to kstat.zfs
#!/bin/bash
cat /proc/spl/kstat/zfs/arcstats | sed ‘s/ {1,}/ /g’ | sed ‘s/ 4 /: /g’ | sed ‘s/^/kstat.zfs.misc.arcstats./’

make it executable
sudo chmod a+x /etc/snmp/kstat.zfs

modify /etc/snmp/zfs
sudo vi /etc/snmp/zfs

remove following strings
@to_pull=(
‘kstat.zfs’,
‘vfs.zfs’,
);

change: my @sysctls_pull = /sbin/sysctl -q @to_pull;

from:
/sbin/sysctl -q @to_pull

to:
/etc/snmp/kstat.zfs

comment use strict and use warnings
#use strict;
#use warnings;

restart snmpd
sudo service snmpd restart

done )
P.S. this is not the best way, but it works

1 Like