Operating System - HP-UX
1825799 Members
2248 Online
109687 Solutions
New Discussion

Re: Script to check the memory and process utilization

 
SOLVED
Go to solution
Chakravarthi
Trusted Contributor

Script to check the memory and process utilization

Hi all,

Is there any script which monitors a specific process, and informs the user about the CPU and memory utilization.

regards
chakri
12 REPLIES 12
G. Vrijhoeven
Honored Contributor

Re: Script to check the memory and process utilization

Hi,

You can use top ( free ) or glance ( evaluation version 60 days free) .

Gideon
Chakravarthi
Trusted Contributor

Re: Script to check the memory and process utilization

I want a report for every 30 minutes, and this should be automated
Chuck J
Valued Contributor

Re: Script to check the memory and process utilization

You can use:

# glance -G

to report on a specific process.

Chuck J
Stefan Farrelly
Honored Contributor
Solution

Re: Script to check the memory and process utilization


Put the following lines into a script, make it executable, and run it with an argument of the pid you want, it then shows you what you want.

echo "PID USER CPU% MEM_SIZE COMMAND"
while true
do
UNIX95= ps -eo "pid ruser pcpu vsz=Kbytes" -o comm |grep $1
sleep 1
done
Im from Palmerston North, New Zealand, but somehow ended up in London...
Chakravarthi
Trusted Contributor

Re: Script to check the memory and process utilization

Hi stefan,

Script doesnt show me all the process, i want to see the process which are started on command line,, they are not visible,

--chakri
Stefan Farrelly
Honored Contributor

Re: Script to check the memory and process utilization

your initial question said monitor a specific process - which the script I supplied will do.

So now you want to monitor all processes ? if so remove from the script the bit;
| grep $1

now it will show all processes every 1 second (you can easily adjust the interval by modifying the sleep value from 1 to whatever you want). Now when you run the script you can simply pipe it into grep for what you want (either a pid, or userid or command).

eg; ./<script> | grep

The script uses ps -e which shows ALL processes running at the instant it is run so you should be able to grep to find what you want from the output.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Chakravarthi
Trusted Contributor

Re: Script to check the memory and process utilization

i corrected your script,, i can see them if i use -ef option, but when i use your script they are not visible

can you give me proper command syntax to use.

regards
chakri
Stefan Farrelly
Honored Contributor

Re: Script to check the memory and process utilization

Im not sure what you mean, but try changing the UNIX95 line to;

UNIX95= ps -eo "pid ruser pcpu vsz=Kbytes" -o args

If this still doenst do what you want please provide examples.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Chakravarthi
Trusted Contributor

Re: Script to check the memory and process utilization

thanks

args is working fine
Chakravarthi
Trusted Contributor

Re: Script to check the memory and process utilization

hi ste ,

if want to see memory utilization in %, then what is the option

regards
chakri
Stefan Farrelly
Honored Contributor

Re: Script to check the memory and process utilization


for an individual user what do you mean by %, % of what ? total memory in use on the server?

Heres a script to show total memory and free% for the whole server;

let x=$(grep -i physical: /var/adm/syslog/OLDsyslog.log|tail -1|awk '{print $2}')/1048
let z=$(vmstat|tail -1|awk '{print $5}')*4096;let z=$z/1000000
let free=100000/$x*$z
let free=$free/1000
let free=100-$free
echo "$x Mb physical memory \n$z Mb memory free \n$free % used"

To do it for an individual user is going to take some more scripting. Is that what you want ?
Im from Palmerston North, New Zealand, but somehow ended up in London...
Chakravarthi
Trusted Contributor

Re: Script to check the memory and process utilization

I WANT TO SEE HOW MUCH MEMORY THE PROCESS IS TAKING IN % LIKE CPU STATS