Operating System - HP-UX
1830499 Members
2537 Online
110006 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
Prashant Zanwar_4
Respected Contributor

Re: Script to monitor the systems.

okay.

Some more thing is like. Can I use it to send 1. average system load every hour
2. Can I send email without a alarm, i mean just a regular output, can I include such thing in this. And I want to send email every one hour.

Can I do this here.

Thanks 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."
Prashant Zanwar_4
Respected Contributor

Re: Script to monitor the systems.

does some uses anything else: Like SAR to create the report and send mail and uptime with that, or might be something else..Please send all help, it's really 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."
Con O'Kelly
Honored Contributor

Re: Script to monitor the systems.

Hi Prashant

My advice is that if you have MWA (now known as OV Performance Agent) installed on your system then you should definitely take advantage of its capabilities to monitor performance and send alarms.
This is one of the things it is specificlly designed to do. It's far more powerful than trying to script sar or any other method of performance alarms.

It does take a little time to configure but once you have it working you can use the same alarmdef file for each sever (assuming you want the same alarm thresholds). RAC has already outlined how it works.

If you do not have OVO (ITO) or are not using SNMP then you need to specify an "EXEC" action in the alarmdef file.

Also look at the 'agsysdb' command:
# agsydb -l
shows how MWA is configured to deal with alarms. 'Exec Actions' : on

The MWA (OVPA)User Guide has a good chapter on configuring the alarmdef file (Chp 7 - Performance Alarms -> Alarm Syntax reference)
http://ovweb.external.hp.com/ovnsmdps/pdf/mwausers_ux_c.03.75.pdf

Also look at this excellent HP whitepaper about configuring MWA which I have attached.
It gives a very good explanation of how to use the alarmdef file.

Cheers
Con

RAC_1
Honored Contributor

Re: Script to monitor the systems.

You can have a cron job that will do this for you. But I would rather stick to MWA.

You can put the output of uptime/sar to know run queue. Also you can put glance output (with adviser mode) to be emailed every hour. But I think that would not serve a purpose other that reporting the measurements at the point in time.

You should be knowing the alarms - the performance problems consistent over a period of time.

So stick with alarmdef.

Anil
There is no substitute to HARDWORK