Connecting Tech Pros Worldwide Help | Site Map

unix performance monitoring script

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 12th, 2007, 10:12 AM
Newbie
 
Join Date: Jan 2007
Posts: 2
Default 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
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...
Reply
  #2  
Old January 12th, 2007, 11:30 AM
ramudukamudu's Avatar
Newbie
 
Join Date: Jan 2007
Posts: 16
Default

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

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

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

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

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

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

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.