Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_cpu_stats.sh

Rating
13 votes
Favoured:
5
Compatible With
  • Nagios 2.x
  • Nagios 3.x
Owner
Hits
155570
Files:
FileDescription
check_cpu_stats.ncfgcheck_cpu_stats.ncfg v2.3 (NagiosGrapher Template)
check_cpu_stats.shcheck_cpu_stats.sh
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
Nagios plugin (script) to check CPU Utilization Statistics (user,system,iowait,idle,nice and steal %) with iostat external program
Nagios plugin (script) to check cpu utilization statistics. This script has been designed and written on Unix plateform (Linux, Aix, Solaris), requiring iostat as external program. The location of these can easily be changed by editing the variables $IOSTAT at the top of the script. The script is used to query 6 of the key cpu statistics (user,system,iowait,idle,nice and steal if possible) at the same time. Note though that there is now set of warning and critical values for user,system and iowait percent.

Usage : ./check_cpu_stats.sh -w -c ( -i -n )

# Exemple: ./check_cpu_stats.sh
# ./check_cpu_stats.sh -w 70,40,30 -c 90,50,40
# ./check_cpu_stats.sh -w 90,40,30 -c 90,50,40 -i 3 -n 5


CPU STATISTICS WARNING : user=0.00% system=20.77% iowait=32.37% idle=46.86% nice=0.00% steal=0.00% | CpuUser=0.00;CpuSystem=20.77;CpuIowait=32.37;CpuIdle=46.86;CpuNice=0.00;CpuSteal=0.00;40,20,30;50,30,45

You can use too provided nagiosgrapher template for this plugin.


# ========================================================================================
#
# HISTORY :
# Release | Date | Authors | Description
# --------------+---------------+----------------------+-----------------------------------
# 2.0 | 16.02.08 | Steve Bosek | Solaris support and new parameters
# | | | New Parameters : - iostat seconds intervals
# | | | - iostat report number
# 2.1 | 08.06.08 | Steve Bosek | Bug perfdata and convert comma in point for Linux result
# 2.1.1 | 05.12.08 | Steve Bosek | Fixed improperly terminated string that was left open at line 130
# 2.1.2 | 06.12.08 | Bas van der Doorn | Fixed linux steal reported as idle, comparisons
# 2.2 | 06.12.08 | Bas van der Doorn | Capable systems will output nice and steal data
# 2.2.1 | 06.12.08 | Steve Bosek | Add for uniform Unix output nice and steal data on all perfdata
# 2.3 | 11.12.08 | Steve Bosek | Add Threshold for user and system output with format -w user,system,iowait -c user,system,iowait
# Add Default parameters value for threshold if not define
# Add check for ${TAB_WARNING_THRESHOLD@} and ${TAB_CRITICAL_THRESHOLD@}
# Add verify for Critical CPU Threshold lower as Warning CPU threshold
# 2.3.1 | 16.12.08 | Steve Bosek | Potability AIX,SOLARIS,LINUX for table initialisation (TAB_WARNING_THRESHOLD and TAB_CRITICAL_THRESHOLD)
# 2.3.2 | 22.12.08 | Steve Bosek | Strict Guideline Nagios for perfdata
# 2.3.3 | 08.02.08 | Philipp Lemke | Add HP-UX support (tested on HP-UX B.11.23 U ia64) - steve bosek : uniform perfdata
# 2.3.4 | 29.03.08 | Steve Bosek | Bug line 176 : USER_CRITICAL_THRESHOLD=`echo ${TAB_CRITICAL_THRESHOLD0}`
# 2.3.5 | 05.05.09 | Steve Bosek | Bug fix in NAGIOS_DATA for HP-UX
# 2.3.6 | 05.08.11 | Steve Bosek | Bug fix in NAGIOS_DATA : replace comma with semicolon in perfdata - compatibility with pnp
Reviews (6)
hi sbosek team

really great plug-in!
but, i found some miss information if there is process name with space-bar as shown below.

# ksh check_cpu_stats.sh
CPU STATISTICS OK : user=4.58% system=2.35%, iowait=1.64%, idle=88.83%, nice=2.60%, steal=0.00%;Top 5 CPU Processes(cpu%,pname,pid): 29.3% pigz 1329275, 25.5% english 1407819, 13.3% spamd child, 1137260% 13.2 php, 1410968% 8.8 mysqld 2945555%| CpuUser=4.58%;70;90;0; CpuSystem=2.35%;40;60;0; CpuIowait=1.64%;30;40;0; CpuIdle=88.83%;0;0;0; CpuNice=2.60%;0;0;0; CpuSteal=0.00%;0;0;0;

some process percentage are 1137260% etc.
quite sure it caused by a daemon name with "spamd child". the space-bar caused some malfunction with your great script parsing.
can wait your next release guys!

thanks
I made it compatible with POSIX-conformant sh.
Is any license condition on redistributing the modified code?
The change set as follows.

--- check_cpu_stats.orig 2014-02-06 11:28:47.000000000 +0900
+++ check_cpu_stats 2014-02-06 11:29:59.509817215 +0900
@@ -1,4 +1,4 @@
-#!/bin/ksh
+#!/bin/sh
# ==============================================================================
# CPU Utilization Statistics plugin for Nagios
#
@@ -163,7 +163,7 @@


# List to Table for warning threshold (compatibility with
-set +A TAB_WARNING_THRESHOLD `echo $LIST_WARNING_THRESHOLD | sed 's/,/ /g'`
+TAB_WARNING_THRESHOLD=( `echo $LIST_WARNING_THRESHOLD | sed 's/,/ /g'` )
if [ "${#TAB_WARNING_THRESHOLD[@]}" -ne "3" ]; then
echo "ERROR : Bad count parameter in Warning Threshold"
exit $STATE_WARNING
@@ -174,7 +174,7 @@
fi

# List to Table for critical threshold
-set +A TAB_CRITICAL_THRESHOLD `echo $LIST_CRITICAL_THRESHOLD | sed 's/,/ /g'`
+TAB_CRITICAL_THRESHOLD=( `echo $LIST_CRITICAL_THRESHOLD | sed 's/,/ /g'` )
if [ "${#TAB_CRITICAL_THRESHOLD[@]}" -ne "3" ]; then
echo "ERROR : Bad count parameter in CRITICAL Threshold"
exit $STATE_WARNING
I ran it with option show on the page on Suse linux 11 and I get following output

nagios@cubic:~> ./check_cpu_stats.sh -w 90,40,30 -c 90,50,40 -i 3 -n 5
./check_cpu_stats.sh: line 172: [: 90,40,30: integer expression expected
./check_cpu_stats.sh: line 175: [: 90,50,40: integer expression expected
CPU STATISTICS OK : user=6.50% system=1.33% iowait=92.17% idle=% nice=0.00% | CpuUser=6.50;CpuSystem=1.33;CpuIoWait=92.17;CpuIdle=;CpuNice=0.00;90,40,30;90,50,40
nagios@cubic:~>

Integre expression expected is one issue and second thing idle is always empty.
if I run it like this then i don't get integer expression but Idle is still empty

nagios@cubic:~> ./check_cpu_stats.sh -w 90 -c 95 -i 2 -n 10
CPU STATISTICS WARNING : user=7.25% system=2.62% iowait=90.12% idle=% nice=0.00% | CpuUser=7.25;CpuSystem=2.62;CpuIoWait=90.12;CpuIdle=;CpuNice=0.00;90;95
nagios@cubic:~>

also you can see that its warning just because IoWait is hitting 90%
byamybrown@gamestop.com, October 13, 2011
byMajed1, August 22, 2011
i install ksh in gentoo and now it produces output from command line:
nagios@srvmonm /usr/lib/nagios/plugins $ ./check_cpu_stats2.3.6.sh
CPU STATISTICS CRITICAL : user=176% system=7.1%, iowait=0%, idle=2%, nice=21%, steal=0% | CpuUser=176%;70;90;0; CpuSystem=7.1%;40;60;0; CpuIowait=0%;30;40;0; CpuIdle=2%;0;0;0; CpuNice=21%;0;0;0; CpuSteal=0%;0;0;0;
it also works in nagios. Moreover, now it checks other linux systems through nrpe and draws graphs in nagios.
i can't imagine anything else to tune up :)
byMajed, July 17, 2011
0 of 1 people found this review helpful
works locally in nagios and through command line but doesn't work through nrpe (gives can't read output) and doesn't graph with pnp4nagios.
Owner's reply

Bug corrected in perfdata for pnp in 2.3.6. Can you retry with this new release please.