From 960122b96cc53fc7813d65a7f1b95c147f414428 Mon Sep 17 00:00:00 2001 From: Adam Michel Date: Mon, 1 Jul 2013 16:11:50 -0700 Subject: [PATCH 1/4] Initial Commit of FreeBSD NFS Plugins This is an initial commit of FreeBSD NFS plugins for the Munin monitoring platform. 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. --- plugins/nfs-freebsd/README.rst | 4 +++ plugins/nfs-freebsd/nfsd | 62 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 plugins/nfs-freebsd/README.rst create mode 100755 plugins/nfs-freebsd/nfsd diff --git a/plugins/nfs-freebsd/README.rst b/plugins/nfs-freebsd/README.rst new file mode 100644 index 00000000..55e2e582 --- /dev/null +++ b/plugins/nfs-freebsd/README.rst @@ -0,0 +1,4 @@ +NFS plugins for FreeBSD +------------------------ + +NFS plugins for FreeBSD diff --git a/plugins/nfs-freebsd/nfsd b/plugins/nfs-freebsd/nfsd new file mode 100755 index 00000000..88bd077a --- /dev/null +++ b/plugins/nfs-freebsd/nfsd @@ -0,0 +1,62 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=head1 NAME + +nfsd - Plugin to monitor NFS 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 NFS 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 From d0d72f5daa9784f4590a6cfb25cc0aae1a158f84 Mon Sep 17 00:00:00 2001 From: Adam Michel Date: Mon, 1 Jul 2013 16:22:40 -0700 Subject: [PATCH 2/4] Better README --- plugins/nfs-freebsd/README.rst | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/nfs-freebsd/README.rst b/plugins/nfs-freebsd/README.rst index 55e2e582..4916f257 100644 --- a/plugins/nfs-freebsd/README.rst +++ b/plugins/nfs-freebsd/README.rst @@ -1,4 +1,22 @@ NFS plugins for FreeBSD ------------------------ -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. From e891287fd328e6c193af75c57050340996821f83 Mon Sep 17 00:00:00 2001 From: Adam Michel Date: Mon, 1 Jul 2013 16:30:42 -0700 Subject: [PATCH 3/4] Added v3 to title, added nfs_client I added a v3 to the title of the nfsd graph to reduce ambiguity. This is also the initial commit of the nfs_client plugin. It is essentially identical to server. The output of nfsstat for client is somewhat different from server in the labeling of the cache entries. As such, I've left them off here and will add a standalone plugin for nfs_client_cache where the awful, terrible, hideous string parsing will take place without sullying the triviality and simplicity of this working plugin. --- plugins/nfs-freebsd/nfs_client | 60 ++++++++++++++++++++++++++++++++++ plugins/nfs-freebsd/nfsd | 4 +-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 plugins/nfs-freebsd/nfs_client 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/nfsd b/plugins/nfs-freebsd/nfsd index 88bd077a..d73d959f 100755 --- a/plugins/nfs-freebsd/nfsd +++ b/plugins/nfs-freebsd/nfsd @@ -5,7 +5,7 @@ =head1 NAME -nfsd - Plugin to monitor NFS server activity on FreeBSD +nfsd - Plugin to monitor NFSv3 server activity on FreeBSD =head1 CONFIGURATION @@ -46,7 +46,7 @@ varray=( $values ) if [ "$1" = "config" ]; then - echo 'graph_title NFS Server' + echo 'graph_title NFSv3 Server' echo 'graph_args --base 1000 -l 0' echo 'graph_vlabel requests / ${graph_period}' echo 'graph_total total' From 3cd07ace54ca4bb2b23a8426de25c4ade6dd4459 Mon Sep 17 00:00:00 2001 From: Adam Michel Date: Mon, 1 Jul 2013 16:50:14 -0700 Subject: [PATCH 4/4] Added nfs_client_cache plugin This adds a plugin for tracking NFS client caching statistics. Because the output for this segment of nfsstat was slightly different, the parsing required some awk dancing to programatically make coherent labels. It's basically a separate function anyway. Right? --- plugins/nfs-freebsd/nfs_client_cache | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 plugins/nfs-freebsd/nfs_client_cache 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