Home Directory Plugins System Metrics CPU Usage and Load CPU Stats/Memory Used Plugin - Top 5 CPU/Memory Consuming Processes for Unix Servers

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

CPU Stats/Memory Used Plugin - Top 5 CPU/Memory Consuming Processes for Unix Servers

Current Version
v1.0
Last Release Date
2012-10-19
Compatible With
  • Nagios 3.x
  • Nagios XI
  • Nagios Fusion
License
GPL
Hits
80198
Files:
FileDescription
check_cpu_stats.shReturns CPU Load with Top 5 CPU consuming processes
check_mem_hpux_customReturns Memory Used with Top 5 Memory consuming processes
CPU_&_Memory_top5_Unix.JPGScreenshot
Network Monitoring Software - Download Nagios XI
Log Management Software - Nagios Log Server - Download
Netflow Analysis Software - Nagios Network Analyzer - Download
CPU Stats/Memory Used Plugin - Top 5 CPU/Memory Consuming Processes for Unix Servers
Returns the CPU Stats & Memory Used for all unix servers (tested on HPUX, should work on all), with Top 5 CPU or Memory consuming process details like ProcessID, ProcessName, CPU% or MemKB(used). Very useful when you got an alert from Nagios or an integrated ticketing tool with the details like which all process caused the high cpu load or memory load on your production servers, no need to login individually and check on that monitored server, it will provide you the information right out of the Nagios UI & the Nagios Alerts or Tickets.
Reviews (4)
bymicharg, May 11, 2019
Hi all, unfortunately the comment does not allow attaching scripts. I have patched the 2 provided scripts to work on Linux (they fail now). Tried with CentOS 7.x. Can you please review and update the current versions (that are since 2012)?

The patched files and more information (also for prerequisites) on https://micharg.blogspot.com/2019/05/patched-nagios-scripts-to-monitor-top-5.html
I tested both of them on CentOS 7.2, the CPU check worked after dos2unix.
But the MEM check needed some more changes.

The script used "machinfo" but this isn't a command in CentOS. So I used "cat /proc/meminfo | grep Memtotal"
I also changed the total free memory, to this command:

# Total memory available
totalmem=`cat /proc/meminfo | grep -i memtotal`
totalmem=`echo $totalmem | awk '{print $2}'`
#totalmem=`echo "$totalmem * 1024" | bc`
#echo "TotalMem=$totalmem"

#Total Free Memory
freemem=`cat /proc/meminfo | grep -i memfree`
freemem=`echo $freemem | awk '{print $2}'`

I also had a problem with "bc", I constantly got a error about the decimal that was included.
But I changed the calculation so it wouldn't get the error anymore:

# Total memory used
usedmem=`echo "$totalmem - $freemem" | bc -l`
#echo "UsedMem=$usedmem"

#Percent Used Mem for Calculation.
percused=`echo $usedmem / $totalmem | bc -l`

#Percent Used Mem
percentused=`echo "scale=0;($percused * 100/1)" | bc -l`

#echo "PercentUsedMem=$percentused"
percentfree=`echo "100 - $percentused" | bc -l`

And I got an integer expression on line 123, so I changed the command a bit.
OUTPUT=";Top 5 Memory Processes(memKB,pname,pid): " ;
for word in $COMMAND; do
i=`expr $i + 1`
j=`expr $j + 1`
if [[ $i -eq 3 ]]; then
i=0;
if [ $j -eq 15 ]; then
OUTPUT="$OUTPUT `echo $word`" ;
else
OUTPUT="$OUTPUT `echo $word, `" ;
fi
else
if [ "$i%3" = "1" ]; then ## It was this: [ $i%3 -eq 1 ] ##
OUTPUT="$OUTPUT `echo $word"KB"`" ;
else
OUTPUT="$OUTPUT `echo $word `" ;
fi
fi
done

After I made this changes it worked fine.
byyabonio, January 23, 2016
To use this plugin under linux you may need to convert it with dos2unix tool. It comes in windows format.
bysandyzd, November 18, 2012
0 of 1 people found this review helpful
Hi Manish Kumar,
I left a email in your Gmail,please check it. There are some screenshots in my email. Please help me to solve the problem.Thank you very much.