Connecting Tech Pros Worldwide Help | Site Map

unix performance monitoring script

Newbie
 
Join Date: Jan 2007
Posts: 2
#1: Jan 12 '07
hey,
i am in bit prob..can u help me to write a script in unix (can use perl also) to monitor
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...
ramudukamudu's Avatar
Newbie
 
Join Date: Jan 2007
Posts: 16
#2: Jan 12 '07

re: unix performance monitoring script


Hi, I am also facing similar problem. I need to monitor the memory usage, idle %CPU percentage while my application is running. right now I am using "top" utility. But it is difficult to extact required information from "top". "top" is generating the O/P continuously. I want one shot answer as "vmstat","iostat" utilities give.
Could you suggest the solution??
regards,
ramudu.
arne's Avatar
Expert
 
Join Date: Oct 2006
Posts: 306
#3: Jan 12 '07

re: unix performance monitoring script


Quote:

Originally Posted by ramudukamudu

Hi, I am also facing similar problem. I need to monitor the memory usage, idle %CPU percentage while my application is running. right now I am using "top" utility. But it is difficult to extact required information from "top". "top" is generating the O/P continuously. I want one shot answer as "vmstat","iostat" utilities give.
Could you suggest the solution??
regards,
ramudu.

For Linux, consider using the information provided under /proc:

/proc/diskstat
/proc/cpustat
/proc/meminfo

This is where many monitoring tools under Linux get their info from.
For specific processes look under /proc/<PID>/

Can't say anything about UNIX, though ...

Hope that helps.
drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,561
#4: Jan 12 '07

re: unix performance monitoring script


In Unix it's du and df for disk usage.
I found this.
ramudukamudu's Avatar
Newbie
 
Join Date: Jan 2007
Posts: 16
#5: Jan 13 '07

re: unix performance monitoring script


Thanks flocks,
That's really helpful.
Member
 
Join Date: Jan 2007
Posts: 36
#6: Jan 16 '07

re: unix performance monitoring script


You could always make a crontab job to dump the values, but you'd probably get less of a performance hit by writing a short perl or shell script to do it, and then "daemonize" it.

I use Python the most, so that's what I'll use to prototype:

import time
cpuidle = 0 # adjust to the word index of the stat you want, counting from 0
# when you do "cat /proc/cpustat"
diskfree = 0 # adjust as per cpuidle
memfree = 9 # adjust as per cpuidle (this one is probably right)
logfile = open("/var/log/perflog","w")
while True:
logfile.write("CPU: %s DISK: %s MEM: %s\n" % (
file("/proc/cpustat").read().split(" ")[cpuidle],
file("/proc/diskstat").read().split(" ")[diskfree],
file("/proc/meminfo").read().split(" ")[memfree]))
logfile.flush()
time.sleep(10)

You could probably convert this to perl quite easily...

reagards,
-cybervegan
Member
 
Join Date: Jan 2007
Posts: 41
#7: Jun 22 '07

re: unix performance monitoring script


Quote:

Originally Posted by cybervegan

You could always make a crontab job to dump the values, but you'd probably get less of a performance hit by writing a short perl or shell script to do it, and then "daemonize" it.

I use Python the most, so that's what I'll use to prototype:

import time
cpuidle = 0 # adjust to the word index of the stat you want, counting from 0
# when you do "cat /proc/cpustat"
diskfree = 0 # adjust as per cpuidle
memfree = 9 # adjust as per cpuidle (this one is probably right)
logfile = open("/var/log/perflog","w")
while True:
logfile.write("CPU: %s DISK: %s MEM: %s\n" % (
file("/proc/cpustat").read().split(" ")[cpuidle],
file("/proc/diskstat").read().split(" ")[diskfree],
file("/proc/meminfo").read().split(" ")[memfree]))
logfile.flush()
time.sleep(10)

You could probably convert this to perl quite easily...

reagards,
-cybervegan

Will this work for hp and solaris ???
Expert
 
Join Date: Apr 2006
Posts: 512
#8: Jun 22 '07

re: unix performance monitoring script


Quote:

Originally Posted by avik1983

hey,
i am in bit prob..can u help me to write a script in unix (can use perl also) to monitor
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...

have you tried to code anything yet? read up anything on shell scripting before this?
Reply


Similar Unix / Linux / BSD bytes