Shellscript - Nagios Plugins - Swap & Memory
Plugin zum Überwachen des Arbeitsspeichers
#!/bin/sh
free -m | grep Mem | while read output;
do
mem=$(echo $output | awk ‘{print $2}’ )
used=$(echo $output | awk ‘{ print $3 }’ )
free=$(echo $output | awk ‘{ print $4 }’ )
use=`expr $used \* 100 / $mem`
if [ $use -ge 90 ]; then
echo "CRITICAL Total Mem: \"$mem\" Used: \"$used ($use%)\" Free: \"$free\" "
exit 2
elif [ $usep -ge 50 ]; then
echo "WARNING Total Mem: \"$mem\" Used: \"$used ($use%)\" Free: \"$free\" "
exit 1
else
echo "OK Mem: $mem" "Used: $used" "Free: $free"
exit 0
fi
done
free -m | grep Mem | while read output;
do
mem=$(echo $output | awk ‘{print $2}’ )
used=$(echo $output | awk ‘{ print $3 }’ )
free=$(echo $output | awk ‘{ print $4 }’ )
use=`expr $used \* 100 / $mem`
if [ $use -ge 90 ]; then
echo "CRITICAL Total Mem: \"$mem\" Used: \"$used ($use%)\" Free: \"$free\" "
exit 2
elif [ $usep -ge 50 ]; then
echo "WARNING Total Mem: \"$mem\" Used: \"$used ($use%)\" Free: \"$free\" "
exit 1
else
echo "OK Mem: $mem" "Used: $used" "Free: $free"
exit 0
fi
done
Plugin zum Überwachen des Swap
#!/bin/sh
free -m | grep Swap | while read output;
do
swap=$(echo $output | awk ‘{print $2}’ )
used=$(echo $output | awk ‘{ print $3 }’ )
free=$(echo $output | awk ‘{ print $4 }’ )
use=`expr $used \* 100 / $swap`
if [ $use -ge 90 ]; then
echo "CRITICAL Swap: \"$swap\" Used: \"$used ($use%)\" Free: \"$free\" "
exit 2
elif [ $use -ge 50 ]; then
echo "WARNING Swap: \"$swap\" Used: \"$used ($use%)\" Free: \"$free\" "
exit 1
else
echo "OK Swap: $swap" "Used: $used" "Free: $free"
exit 0
fi
done
free -m | grep Swap | while read output;
do
swap=$(echo $output | awk ‘{print $2}’ )
used=$(echo $output | awk ‘{ print $3 }’ )
free=$(echo $output | awk ‘{ print $4 }’ )
use=`expr $used \* 100 / $swap`
if [ $use -ge 90 ]; then
echo "CRITICAL Swap: \"$swap\" Used: \"$used ($use%)\" Free: \"$free\" "
exit 2
elif [ $use -ge 50 ]; then
echo "WARNING Swap: \"$swap\" Used: \"$used ($use%)\" Free: \"$free\" "
exit 1
else
echo "OK Swap: $swap" "Used: $used" "Free: $free"
exit 0
fi
done