Monitor disk space with nagios

Status
Not open for further replies.

aleatorvb

Dabbler
Joined
Nov 14, 2012
Messages
10
You can monitor remote disk with nagios over ssh.


Ssh script to be copied on the freenas server, I used /mnt/pool1/users/nagios/check_diskfree.sh
Code:

case $1 in
  --help | -h )
         echo "Usage: check_diskfree [dev] [warn] [crit]"
         echo " [warn] and [crit] as int"
         echo " Example: check_diskfree hda1 70 90"
         exit 3
         ;;
  * )
    ;;
esac

if [ ! "$1" -o ! "$2" -o ! "$3" ]; then
        echo "Usage: check_diskfree [dev] [warn] [crit]"
        echo " [warn] and [crit] as int"
        echo " Example: check_diskfree hda1 70 90"
        echo "Unknown: Options missing"
        exit 3
fi

used=`df /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \  -f3`
free=`df /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \  -f4`
full=`echo $(($used+$free))`
percent=`echo $((( $free * 100 ) / $full))`
warn=`echo $((( $full * $2 ) / 100 ))`
crit=`echo $((( $full * $3 ) / 100 ))`

if [ "$warn" -gt "$crit" -o "$warn" -eq "$crit" ]; then
   echo "Unknown: [crit] must be larger than [warn]"
        exit 3
fi

if [ "$used" -lt "$warn" -o "$used" -eq "$warn" ]; then
        echo "OK. Free Space: `df -h /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \  -f4`B, $percent%"
        exit 0
 elif [ "$used" -gt "$warn" -a "$used" -lt "$crit" ]; then
        echo "Warning. Free Space: `df -h /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \  -f4`B, $percent%"
        exit 1
 elif [ "$used" -gt "$crit" ]; then
        echo "Critical. Free Space: `df -h /$1 | tail -n1 | sed -r 's/\ +/\ /g' | cut -d \  -f4`B, $percent%"
        exit 2
 else
   echo "Unknown"
   exit 3
fi


Configure nagios to monitor
- using check_diskfree.sh script
- dataset /mnt/pool1
- warning at 90%, critical at 95%
Code:
define service{
        use                             local-service
        host_name                       freenas_host_name
        service_description             Disk Usage
        check_command                   check_by_ssh!22!/mnt/pool1/users/nagios/check_diskfree.sh!mnt/pool1!90!95$
        max_check_attempts              3
        check_interval                  5
        retry_interval                  3
        check_period                    24x7
}



Works like a charm.


Attention!
This requires having the nagios user being able to ssh to the freenas_host_ip_address with passwordless login using ssh-keys.
Create a nagios user on freenas and allow it to remotely login via ssh.
Also select a home folder for it.

Create public/private key pair
Code:
# login to nagios server with the nagios user
cd ~
mkdir .ssh
chmod -R 700 .ssh
cd .ssh
ssh-keygen -t rsa
# do not enter any password if you want passwordless login


..and then copy the key to freenas (using ubuntu as example here)
Code:
ssh-copy-id freenas_host_ip
#enter password
exit
exit


.. now we're back on nagios server. To test passwordless login type
Code:
ssh freenas_host_ip
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
Pretty sad this has to be labeled in the hacking section.

Why? You expect FreeNAS to support every other monitoring system available as part of the base system? collectd not good enough?
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
If you have to ask why chances are I cant educate you on to why

Since you don't understand my question, then you won't be teaching me anything, you are quite correct.

FreeNAS uses collectd to gather those stats. You can either work within that powerful, networked framework to collect the requested stats, or you can hack your Nagios to directly monitor it in any of many ways. Since there already exist bridges from collectd to Nagios, there is no real need to hack this, but it MAY be more convenient to omit the intermediate collectd or required complications of configuration.

Of course, if Nagios was the only network monitoring package, then maybe it would be reasonable to also support direct monitoring. But since Nagios is only one of dozens (or even hundreds) of monitoring packages, special-casing for your preferred monitoring package is unlikely.

Most people in the hacking section are able to come to this sort of understanding without much explanation. We've mostly all cobbled together some hacky cheats dozens or thousands of times over the years; criticizing FreeNAS in the tone you did for not idolizing your preferred monitoring tool may not go over too well.

School's out and I obviously need more coffee 'coz I am clearly cranky.
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
Oh and PS the OP did a wonderful job at this. Nicely done.
 
Status
Not open for further replies.
Top