Connecting Tech Pros Worldwide Help | Site Map

unix performance monitoring script

  #1  
Old January 12th, 2007, 11:12 AM
Newbie
 
Join Date: Jan 2007
Posts: 2
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...
  #2  
Old January 12th, 2007, 12:30 PM
ramudukamudu's Avatar
Newbie
 
Join Date: Jan 2007
Posts: 16

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.
  #3  
Old January 12th, 2007, 03:57 PM
arne's Avatar
Expert
 
Join Date: Oct 2006
Posts: 307

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.
  #4  
Old January 12th, 2007, 04:24 PM
drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,521

re: unix performance monitoring script


In Unix it's du and df for disk usage.
I found this.
  #5  
Old January 13th, 2007, 11:27 AM
ramudukamudu's Avatar
Newbie
 
Join Date: Jan 2007
Posts: 16

re: unix performance monitoring script


Thanks flocks,
That's really helpful.
  #6  
Old January 16th, 2007, 03:03 PM
Member
 
Join Date: Jan 2007
Posts: 36

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
  #7  
Old June 22nd, 2007, 03:48 PM
Member
 
Join Date: Jan 2007
Posts: 41

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 ???
  #8  
Old June 22nd, 2007, 04:22 PM
Expert
 
Join Date: Apr 2006
Posts: 512

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 Threads
Thread Thread Starter Forum Replies Last Post
DB2 Consultants required at Bangalore Mike answers 0 September 18th, 2008 08:05 PM
DB2 Consultants required at Bangalore Mike answers 0 September 18th, 2008 07:55 PM