Solved

Scripting for monitoring the memory usage of some processes

Posted on 2002-07-11
9
303 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

770 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