Solved

Scripting for monitoring the memory usage of some processes

Posted on 2002-07-11
9
308 Views
Last Modified: 2013-12-27
Hi All
I need a script which monitors the memory usage of the machine for some specific processes.

Something like

./CheckUtilisation.sh <process handle> <threshold>

and it outputs let's say "Yes" if threshold exceeeds.

Regards
Khem
0
Comment
Question by:k_suchdeva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 7145799
Install

application RMCmem         The MemTool Package

and you have all for memory.

Example:
memps ang gui programms.
0
 
LVL 2

Author Comment

by:k_suchdeva
ID: 7145801
I only want a simple script.

Can not install third party packages.
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 7148515
what is your Solaris ???

2.6, or 2.7 or 2.8 or 2.9
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:k_suchdeva
ID: 7148554
uname -a
SunOS XXXXXXX 5.7 Generic_106541-16 sun4u sparc SUNW,Ultra-80


0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7148716
not for a specified process, but probably worth looking at it:
   man sar
0
 

Expert Comment

by:emrehayretci
ID: 7153417
Improve the following script. It should help you.


frequency=3

while (true); do
STATUS=`vmstat $frequency 3| awk -e '{print $5}'`
LASTSTATUS=`echo $STATUS| awk -e '{print $5}'`
if [ $LASTSTATUS -lt <put your trshhold>]; then
    echo "TreshHold Exceeds"
    <write want to want to do in here(i.e. send mail to
    someone)>
fi

done
0
 
LVL 2

Accepted Solution

by:
blowfish earned 100 total points
ID: 7218950
Hi,  

The answer proposed by emrehayretci, uses the vmstat command to display the machine's virual memory and CPU statistics.  If you want to monitor resource usage of a process, then you need to use the ps command.  So, here is a solution to your question.  You could read the man page for ps, for more information regarding the command line options.  

I'm not sure what you mean by <process handle>, so I'm going to assume that you meant process-id, or, PID.  Memory usage can be reported as a process's total virtual size (VSZ), or it's current resident memory size (RSS).  I will assume that you want to monitor it's total virtual size.  

To get a detailed (-f for full) list of all (-e for everything) processes on the machine, use the command:

  ps -ef

This listing however does not give you the memory usage that you are looking for, so, you'll have to use the -o command line option.  The -o command line option tells ps what colums to display in it's output.  You will need to use the following command to list all processes, the user, the process-id, the virtual size (kb), and the command-line arguments:

  ps -e -o user,pid,vsz,args

Now that you can list the information, we need to wrap it in a script that can extract the details of the processes that you are interested in.  

For something like this, I usually use awk.  Awk is a natural when it comes to selecting data that is presented in columns.  Let's say that you want to monitor all of root's processes, and report on any that are bigger than 1024kb:

while :
do
  ps -e -o user,pid,vsz,args | awk '$1 ~ /root/ && $3 > 1024 {print}'
  echo "  sleeping ..."
  sleep 30
done

Hope this helps,

--frankf
0
 
LVL 21

Expert Comment

by:tfewster
ID: 8003363
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by blowfish

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8065839
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 59
Using Grep to Find a file 8 117
AIX 5.x set up arrow to recall 11 69
Equivalent of WSUS for Solaris, AIX and Cisco devices 11 125
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question