Operating System - HP-UX
1753797 Members
8203 Online
108805 Solutions
New Discussion юеВ

Re: command to check memory/cpu usage

 
SOLVED
Go to solution
jerry1
Super Advisor

command to check memory/cpu usage

Does anyone know what command line command
there is to get the memory/cpu usage so I can
use it with nagios. There does not seem to be
any pre-compiled check for memory or cpu usage
in nagios.
11 REPLIES 11
Sandman!
Honored Contributor
Solution

Re: command to check memory/cpu usage

-- CPU usage every 5 secs for 100 iterations

# sar -Mu 5 100

-- Memory usage ever 5 secs for 100 iterations

# vmstat -S 5 100
jerry1
Super Advisor

Re: command to check memory/cpu usage

Already looked at those commands.
Does not give me the values I need like in
glance in percent.
Current
CPU Util | 14% 14% 14%
Mem Util | 47% 47% 47%
GrayMatter_1
Advisor

Re: command to check memory/cpu usage

try the 'top' command

Cheers!
GM
TwoProc
Honored Contributor

Re: command to check memory/cpu usage

OK Jerry, I wrote this for you. It's about as close as I can get quickly.

$ ./glance_stats
CPU Util 57% 65% 76%
Mem Util 84% 84% 84%

It takes about 6 seconds to run, because it REALLY wants to run three iterations. Although to me, this should only take two seconds. This is about as tight as I could make it using the "-j 1" and the "-iterations 2" parameters. Both of these, according the the man page are the minimum. However, instead of getting two 1 second runs, I seem to get three 2 second runs. Go figure...

Here's the script file:
glance -f /var/tmp/glance.$$ -nosort -j 1 -iterations 2 > /dev/null 2>&1
awk '/CPU Util|Mem Util/{print $1" "$2" "$5" "$6" "$7}' \
/var/tmp/glance.$$ | tail -2
rm -f /var/tmp/glance.$$
We are the people our parents warned us about --Jimmy Buffett
GrayMatter_1
Advisor

Re: command to check memory/cpu usage

nagios does come with precompiled progs for checking the cpu load on the current box. the command is check_load. I don't see any precompiled scripts for checking mem on our box. Have you installed the plugins from http://nagiosplug.sourceforge.net/ ?

This is also a great read on how to monitor a remote system with nagios:
http://www.crucialwebhost.com/blog/nagios-howto-using-nrpe-to-monitor-remote-services/

here's an example from our nagios box:

watchman:~# /usr/local/nagios/libexec/check_load -w .8,1.2,1.6 -c 1.0,1.5,2.0
OK - load average: 0.13, 0.08, 0.02|load1=0.130;0.800;1.000;0; load5=0.080;1.200;1.500;0; load15=0.020;1.600;2.000;0;


Cheers!
GM
jerry1
Super Advisor

Re: command to check memory/cpu usage

John, thanks for the code. But there seems
to be some kind of race condition. I do not
get the High on CPU every now and then.

# glance_stats
CPU Util 9% 9% 9%
Mem Util 48% 48% 48%

root@dbsvr1 [/lhome]
# glance_stats
CPU Util 8% 9% 11%
Mem Util 48% 48% 48%

root@dbsvr1 [/lhome]
# glance_stats
CPU Util 6% 9%
Mem Util 48% 48% 48%
jerry1
Super Advisor

Re: command to check memory/cpu usage

Turns out there was a field on CPU that
did not get populated all the time so
I changed your code to take care of that
and I only needed the Avg.

glance -f /var/tmp/glance.cpu -nosort -j 1 -iterations 2 > /dev/null 2>&1
awk -F\| '/CPU Util/{print $2}' \
/var/tmp/glance.cpu | tail -1 | awk '{print $2}'

Thanks again.
I will also look at the links sent.
There seems to be a lot of locations on
the web about Nagios and distributions.

Thanks all.
TwoProc
Honored Contributor

Re: command to check memory/cpu usage

Assign pts, please
We are the people our parents warned us about --Jimmy Buffett
TwoProc
Honored Contributor

Re: command to check memory/cpu usage

Jerry,

This will help quite a bit with your problem.

https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1033211
We are the people our parents warned us about --Jimmy Buffett