Nagios Core CPU Plugin

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Nagios Core CPU Plugin

Postby vnoc » Mon Nov 13, 2017 6:14 am

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
(728 Bytes) Downloaded 6 times
Posts: 54
Joined: Thu Jul 27, 2017 1:51 am

Re: Nagios Core CPU Plugin

Postby mcapra » Mon Nov 13, 2017 10:43 am

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
# 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
        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
                echo "WARNING - CPU Usage = $USAGE %|CPU Usage=$USAGE%;;;;"
                exit 1
                echo "OK - CPU Usage = $USAGE %|CPU Usage=$USAGE%;;;;"
        exit 0
        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

In action:
Code: Select all
# ./check_load -w 10 -c 20
OK - CPU Usage = 6.4 %|CPU Usage=6.4%;;;;
Former Nagios employee
User avatar
Posts: 3157
Joined: Thu May 05, 2016 3:54 pm

Re: Nagios Core CPU Plugin

Postby kyang » Mon Nov 13, 2017 4:58 pm

Thanks @mcapra!
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
Support Tech
Posts: 1609
Joined: Tue Jul 25, 2017 3:35 pm

Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 16 guests