diff --git a/plugins/nfs-freebsd/README.rst b/plugins/nfs-freebsd/README.rst new file mode 100644 index 00000000..4916f257 --- /dev/null +++ b/plugins/nfs-freebsd/README.rst @@ -0,0 +1,22 @@ +NFS plugins for FreeBSD +------------------------ + +The NFS plugins for Munin depend on the /proc filesystem in Linux for +statistics which does not exist in FreeBSD by default. While one can +add the linproc package to their installation to emulate this +functionality, I felt it would be better to write plugins that made use +of native tools. + +I'm leveraging the nfsstat command to create these plugins. I'm sure +there is a better primary data source in FreeBSD to gather this output +from but for my purposes, using nfsstat is adequate and acceptable. +Unfortunately this means if the output of the nfsstat command changes +due to updates, these plugins will likely report inaccurate data. +These are the days of our lives, as they say. Someone with appropriate +levels of FreeBSD knowledge can probably improve these plugins +trivially. + +I'm specifically targeting FreeNAS/NAS4Free, but the code should work +on any FreeBSD system with minimal package additions. Installing munin +on FreeNAS is not supported in general, but it's easy enough to do and +I wanted it monitored, ergo we are here. diff --git a/plugins/nfs-freebsd/nfs_client b/plugins/nfs-freebsd/nfs_client new file mode 100644 index 00000000..f2d807cf --- /dev/null +++ b/plugins/nfs-freebsd/nfs_client @@ -0,0 +1,60 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=head1 NAME + +nfsd - Plugin to monitor NFSv3 client activity on FreeBSD + +=head1 CONFIGURATION + +No configuration + +=head1 AUTHORS + +Plugin created by Adam Michel, based on work by Alexandre Dupouy, with the assistance of Mike Fedyk + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +NFSSTAT=/usr/bin/nfsstat +if [ "$1" = "autoconf" ]; then + if [ -x "$NFSSTAT" ]; then + echo yes + exit 0 + else + echo "no (no $NFSSTAT)" + exit 0 + fi +fi + +labels=`$NFSSTAT -c | grep -iv "[0-9]" | grep -v ":" | sed 's/X\ /x_/' | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26}' | tr '[A-Z]' '[a-z]'` +values=`$NFSSTAT -c | grep -i "[0-9]" | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26}'` + +larray=( $labels ) +varray=( $values ) +if [ "$1" = "config" ]; then + + echo 'graph_title NFSv3 Client' + echo 'graph_args --base 1000 -l 0' + echo 'graph_vlabel requests / ${graph_period}' + echo 'graph_total total' + echo 'graph_category NFS' + for a in $labels; do echo "$a.label $a" ; echo "$a.type DERIVE"; echo "$a.min 0"; done + exit 0 +fi + +for i in {0..25}; do + label=${larray[$i]} + value=${varray[$i]} + echo "$label.value $value" +done diff --git a/plugins/nfs-freebsd/nfs_client_cache b/plugins/nfs-freebsd/nfs_client_cache new file mode 100644 index 00000000..6f74e15a --- /dev/null +++ b/plugins/nfs-freebsd/nfs_client_cache @@ -0,0 +1,60 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=head1 NAME + +nfsd - Plugin to monitor NFSv3 client cache activity on FreeBSD + +=head1 CONFIGURATION + +No configuration + +=head1 AUTHORS + +Plugin created by Adam Michel, based on work by Alexandre Dupouy, with the assistance of Mike Fedyk + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +NFSSTAT=/usr/bin/nfsstat +if [ "$1" = "autoconf" ]; then + if [ -x "$NFSSTAT" ]; then + echo yes + exit 0 + else + echo "no (no $NFSSTAT)" + exit 0 + fi +fi + +labels=`$NFSSTAT -c | grep -iv "[0-9]" | tail -n 2 | sed 's/BioRLHits/BioRL\ Hits/g' | awk '{print $1"_"$2,$1"_"$3,$4"_"$5,$4"_"$6,$7"_"$8,$7"_"$9,$10"_"$11,$10"_"$12}' | tr '\n' ' ' | tr '[A-Z]' '[a-z]'` +values=`$NFSSTAT -c | grep -i "[0-9]" | tail -n 2 | tr '\n' ' '` + +larray=( $labels ) +varray=( $values ) +if [ "$1" = "config" ]; then + + echo 'graph_title NFSv3 Client Cache' + echo 'graph_args --base 1000 -l 0' + echo 'graph_vlabel requests / ${graph_period}' + echo 'graph_total total' + echo 'graph_category NFS' + for a in $labels; do echo "$a.label $a" ; echo "$a.type DERIVE"; echo "$a.min 0"; done + exit 0 +fi + +for i in {0..15}; do + label=${larray[$i]} + value=${varray[$i]} + echo "$label.value $value" +done diff --git a/plugins/nfs-freebsd/nfsd b/plugins/nfs-freebsd/nfsd new file mode 100755 index 00000000..d73d959f --- /dev/null +++ b/plugins/nfs-freebsd/nfsd @@ -0,0 +1,62 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=head1 NAME + +nfsd - Plugin to monitor NFSv3 server activity on FreeBSD + +=head1 CONFIGURATION + +No configuration + +=head1 AUTHORS + +Plugin created by Adam Michel, based on work by Alexandre Dupouy, with the assistance of Mike Fedyk + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +# This is where nfsstat lives +NFSSTAT=/usr/bin/nfsstat +if [ "$1" = "autoconf" ]; then + if [ -x "$NFSSTAT" ]; then + echo yes + exit 0 + else + echo "no (no $NFSSTAT)" + exit 0 + fi +fi + +labels=`$NFSSTAT -s | grep -iv "[0-9]" | grep -v ":" | sed 's/Server\ //' | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30}' | tr '[A-Z]' '[a-z]'` +values=`$NFSSTAT -s | grep -i "[0-9]" | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30}'` + +larray=( $labels ) +varray=( $values ) + +if [ "$1" = "config" ]; then + + echo 'graph_title NFSv3 Server' + echo 'graph_args --base 1000 -l 0' + echo 'graph_vlabel requests / ${graph_period}' + echo 'graph_total total' + echo 'graph_category NFS' + for a in $labels; do echo "$a.label $a" ; echo "$a.type DERIVE"; echo "$a.min 0"; done + exit 0 +fi + +for i in {0..29}; do + label=${larray[$i]} + value=${varray[$i]} + echo "$label.value $value" +done