Page 1 of 1
Nagios Core CPU Plugin
Posted: Mon Nov 13, 2017 6:14 am
by vnoc
Hi Team,
I was been using a CPU Load plugin which gives me the CPU load is percentage . This plugin is working fine in less than 7 Redhat versions perfectly.
But right now all my servers versions are getting changes to 7.2 Redhat and this plugin is not working.
Can anyone help me in changing the script to be usable in 7.2 version.
Please find the attached of current plugin which I have been using
Re: Nagios Core CPU Plugin
Posted: Mon Nov 13, 2017 10:43 am
by mcapra
Just saying "it's not working" isn't very helpful, particularly with third party scripts. As part of troubleshooting, knowing
how is it not working is very valuable. What sorts of outputs exist, how the script is behaving compared to how it used to, etc.
I suspect the issue is with the trailing cut command assigned to
IDLE as it's expecting a
% symbol as the delimiter. I don't think the
top output displays a
% character in Cent/RHEL 7 though.
I don't have a RHEL 7.2 box to test against, but this works fine for me on CentOS 7.4:
Code: Select all
#!/bin/sh
# Version 0.2
#
# ### History ###
# V0.1 Created script from CPU Idle script
# V0.2 Handle dicimal compare and output
if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ] ; then
warn=$2
crit=$4
IDLE=`top -b -n2|grep Cpu|tail -1|cut -d',' -f4|cut -d ' ' -f2`
USAGE=`echo "100 - $IDLE"|bc|sed -r 's/^\./0./g'` ||exit 3
# echo "DEBUG: head: ${USAGE%%.*} tail: ${USAGE##*.} "
# echo "DEBUG: ||$USAGE_RAW|| , ||$USAGE||"
if [ $warn -lt ${USAGE%%.*} ];then
if [ $crit -lt ${USAGE%%.*} ]; then
echo "CRITICAL - CPU Usage = $USAGE %|CPU Usage=$USAGE%;;;;"
exit 2
else
echo "WARNING - CPU Usage = $USAGE %|CPU Usage=$USAGE%;;;;"
exit 1
fi
else
echo "OK - CPU Usage = $USAGE %|CPU Usage=$USAGE%;;;;"
exit 0
fi
else
echo "$0 - Nagios Plugin for checking CPU Usage in percentage "
echo ""
echo "Usage: $0 -w <warnlevel> -c <critlevel>"
echo " = warnlevel and critlevel is warning and critical value for alerts. "
echo ""
echo "EXAMPLE: /usr/lib64/nagios/plugins/$0 -w 80 -c 90 "
echo " = This will send warning alert when CPU Usage percentage is higher than 80%, and send critical when higher than 90%"
echo ""
exit 3
fi
In action:
Code: Select all
# ./check_load -w 10 -c 20
OK - CPU Usage = 6.4 %|CPU Usage=6.4%;;;;
Re: Nagios Core CPU Plugin
Posted: Mon Nov 13, 2017 4:58 pm
by kyang