Operating System - Linux
1819984 Members
3825 Online
109607 Solutions
New Discussion юеВ

Re: unix performance monitoring script

 
Dodo_5
Frequent Advisor

unix performance monitoring script

hey,
i am in bit prob..can u help me to write a script in unix (can use perl also) to monitor
(please don't need any tools...only script)
1.disk usage
2.cpu usage
3.memory usage

in every 10 seconds(for example)..
it should display the three usage result in screen in every 10 seconds.
it will be better if there is an option for user to set the monitoring time also..
pls help guys...

--------------------------------------------------------------------------------
8 REPLIES 8
Yogeeraj_1
Honored Contributor

Re: unix performance monitoring script

hi,

below two of the command that i have bookmarked:

pid of process consuming most CPU displayed on stdout:
# UNIX95= ps -e -o "pcpu,pid" | sort -n -k1 | tail -1 | awk '{print $2}'

pid of process consuming most memory displayed on stdout:
# UNIX95= ps -e -o "vsz,pid" | sort -n -k1 | tail -1 | awk '{print $2}'


will try to find some more.

hope this helps!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: unix performance monitoring script

hi,

below a few commands that i have recorded from one of SEP's posts:

sar -qM 1 600 > /tmp/perf_info.report &
sar -uM 1 600 > /tmp/perf_info.cpu &
sar -b 1 600 > /tmp/perf_info.buffer &
sar -d 1 600 > /tmp/perf_info.disk &
sar -w 1 600 > /tmp/perf_info.swap &
sar -v 1 600 > /tmp/perf_info.inode &


hope this helps too!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Dodo_5
Frequent Advisor

Re: unix performance monitoring script

actually i need the script for getting those usage result for every 5 seconds..
so can u write the total script to explain whole thing
Alexander Chuzhoy
Honored Contributor

Re: unix performance monitoring script

No need to write a script.
Use the existing utility called watch.
For example:
watch -n 3 "ls -la"

will show the output of ls -la updated every 3 second.
Simply pass the commands Yogeeraj gave you (without redirecting them into a file if you want to see the output on STDOUT) as arguments instead of "ls -la".

Please also assign points...
Ragu_3
Trusted Contributor

Re: unix performance monitoring script

cpu and memory usage as shown by "w" is very useful; use "awk" to show you the required field via print every n seconds.
Debian GNU/Linux for the Enterprise! Ask HP ...
Huc_1
Honored Contributor

Re: unix performance monitoring script

Here is a bash script I wrote using the above replys... see it as common efford to help you geeting started on script writting !

invoke the script as follows
watch -d -n5 "sh ./Monitor_ex.sh"


Enjoy life

Jean-Pierre Huc
Smile I will feel the difference
Andrea Rossi
Frequent Advisor

Re: unix performance monitoring script

0 8-18 * * 1-5 /usr/lib/sa/sa1 1200 3 &
5 19 * * 1-5 /usr/lib/sa/sa2 -A &
(man pages)
Dodo_5
Frequent Advisor

Re: unix performance monitoring script

thanks for those commands and script.

but i actually need a script after running that cpu, memory and disk usage will be shown in display screen concurrently changing with time..
pls send me the script