Operating System - HP-UX
1752790 Members
5685 Online
108789 Solutions
New Discussion юеВ

Script to monitor the systems.

 
Prashant Zanwar_4
Respected Contributor

Script to monitor the systems.

Hey guys,

I am again in a need of help to develop a script which shall monitor for CPU and Memory for average usage. And if the usage is consistently high for 5-10 Minutes, it should mail to particular mail alias. Does some one have anything on their systems already. I could do this, but I am not a expert, please send help, every help is appreciated.

Thanks and regards
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
13 REPLIES 13
Geoff Wild
Honored Contributor

Re: Script to monitor the systems.

Before OVO and Big Brother, I did this:


# cat uptime.mon
#!/bin/sh
#
# Name: /scripts/uptime.mon
# Files Used: /scripts/uptime.mon.mesg
#
# Description: This is a script to run "uptime" and send e-mail if the
# system is busy. This is a pro-active script that
# will notify the users emails in the variable MAILADMIN
# And busy variable is the CPU threshold before
# mailing the message to MAILAMIN.

#
# log file: /tmp/uptime.mon.log
logfile=/tmp/uptime.mon.log
if [ -f $logfile ];
then
touch $logfile
else
touch $logfile
fi
busy=170
#
# GUTS of the script
#
#
uptime| cut -d"load average: " -f2 |cut -c14,16-17 |
read sizz;
echo `date``uptime|cut -c28-71` >>$logfile 2>&1
if [ $busy -le $sizz ];
then
/usr/bin/mailx -s "WARN: Sysload HIGH: `uptime|awk '{print $10}'`" `cat /scripts/mailadmin.list` < /scripts/uptime.mon.mesg
fi


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Prashant Zanwar_4
Respected Contributor

Re: Script to monitor the systems.

Hi,

Doesnt someone have any other suggestions on this? Please reply..

Thanks and regards
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
Geoff Wild
Honored Contributor

Re: Script to monitor the systems.

For memory, you could use the "memdetail" c program, grab the info you need and if over a thresehold - email.

Output looks like:

# memdetail
Memory Stat total used avail %used
physical 10080.0 9375.4 704.6 93%
active virtual 10367.6 4340.3 6027.3 42%
active real 7244.3 2914.4 4329.9 40%
memory swap 7692.9 1310.7 6382.3 17%
device swap 26528.0 9963.6 16564.4 38%

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Geoff Wild
Honored Contributor

Re: Script to monitor the systems.

Prashant, did you check out Big Brother?

If you don't want to use it, you might want to look at some of the scripts...

For example, link to bb-memory.sh

http://www.deadcat.net/download.php?fileid=750&filename=bb-memory.sh&location=1


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
RAC_1
Honored Contributor

Re: Script to monitor the systems.

You can check /var/opt/perf/alaramdef file. There are examples in /opt/perf/doc/examples directrory. You can modify /var/opt/perf/aladef file to put your requirements.

Anil
There is no substitute to HARDWORK
Prashant Zanwar_4
Respected Contributor

Re: Script to monitor the systems.

I can see that file..I mean /var/opt/perf/alarmdef -- i dont have mwa agent running on the server.

How can I work out to just enable the mwa agent and alert only on memory and cpu. Are there other things also which will come on in picture when I start mwa.

Or enable mwa and run script through crontab-- is that possible.
Thanks a lot for responses..I dont know how mwa works--

Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
RAC_1
Honored Contributor

Re: Script to monitor the systems.

The file /var/opt/perf/alarmdef has section like follows. Modify it as shown. Changes that I made are marked with ##

alarm Memory_Bottleneck > 50 for 5 minutes
type = "Memory"
start
if Memory_Bottleneck > 90 then
red alert "Memory Bottleneck probability= ", Memory_Bottleneck, "%"
##exec "echo "Memory_Bottleneck"|mailx xyz@abc.com -s "Memory Alarm""
else
yellow alert "Memory Bottleneck probability= ", Memory_Bottleneck, "%"
repeat every 10 minutes
if Memory_Bottleneck > 90 then
red alert "Memory Bottleneck probability= ", Memory_Bottleneck, "%"
##exec "echo "Memory_Bottleneck"|mailx xyz@abc.com -s "Memory Alarm""
else
yellow alert "Memory Bottleneck probability= ", Memory_Bottleneck, "%"
end
reset alert "End of Memory Bottleneck Alert"

Modify the cput section in same way. then run a command utility. On utility prompt do alamdef. Ths check the syntax os the alarmdef file. Once successful, do mwa restart scopeux
Read man page of utility for details.

Anil
There is no substitute to HARDWORK
Prashant Zanwar_4
Respected Contributor

Re: Script to monitor the systems.

Hi,

Got thru working with Utility program. Now I am just curious, once I start the mwa agent, will it inform concerned team automatically, according to me it will..

And also is there something available which can give me the details of syntaxes/commands which can be used under this file.

Thanks a lot, I appreciate a lot.

Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
RAC_1
Honored Contributor

Re: Script to monitor the systems.

The email will be sent to the user, you put in the alarmdef file. As said earlier, you can refer the documents in /opt/perf/doc and man pages. the utility command will help you with syntx check.

Anil
There is no substitute to HARDWORK