Solved

Scripting for monitoring the memory usage of some processes

Posted on 2002-07-11
9
309 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
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!

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

691 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