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
Solved

Scripting for monitoring the memory usage of some processes

Posted on 2002-07-11
9
306 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
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 20

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

861 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