Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
06-06-2007, 10:41 AM
|
#1
|
Member
Registered: Oct 2006
Location: India
Distribution: Fedora Core 6, Archlinux Duke
Posts: 52
Rep:
|
Using top in batch mode
Hi,
I need to redirect the output of top command to a text file for monitoring the CPU utilization later on. I am using RHEL 3 AS (2.4.21-32.EL).
I used the following command:
#top -b -n 1>top.txt
but the command does not exit by itself and the text file size keeps on increasing until killed manually using Ctrl-D.
Please help!!!!
P.S. Is there a way by which I can take only the first 10-15 lines of top's output and discard the rest?
|
|
|
06-06-2007, 01:05 PM
|
#2
|
Member
Registered: Jul 2004
Location: Czech Republic - Roudnice nad Labem
Distribution: Debian
Posts: 253
Rep:
|
Hi,
it works as expected.
Code:
top -b -n1 >top.txt
'top' command goes through one iteration, then exits.
Using 'top' - version 3.2.7
To use only first 15 lines, try 'head' command.
|
|
|
06-06-2007, 01:17 PM
|
#3
|
Member
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548
Rep:
|
Other tools for collecting historical data are sar and uptime.
Sar is set to run in 10 minute intervals by default (RH). To see if sar is running simply type:
sar
this will show data for the previous day only. Lots of other options though, as sar is very powerful. man sar for more info.
Load Average is a very useful tool for telling how busy a server really is. ie: if the cpu is at 90% but your load average is only 1.3 0.4 0.08 then you have nothing to worry about.
Load average by default is showing you the load average for the past: 1 minute, 10 minutes & 15 minutes. I will run uptime via cron every 10 minutes just to monitor the load average on a machine. ie:
/usr/bin/uptime >> uptime.out060607
Just redirect the output to a file, as above. Then, if desired you could email the file yourself at midnight, and zero out the file for the next day of stats.
A general rule of thumb is any load average under 2 is fine. Load average equates to a line at a movie theatre. If more than 2 people are waiting in line, service is not so fast. By the same token a load average of 2 means two processes are waiting for service by the CPU. Anything over that, if sustained, your response time will be affected.
Last edited by DotHQ; 06-06-2007 at 01:19 PM.
|
|
|
06-06-2007, 01:41 PM
|
#4
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,399
|
"sar" is a good tool, but sometimes it is necessary to get the detail "top" provides. Running in batch mode should work fine.
@DotHQ: sar will give you the load averages, so you are collecting this twice.
Quote:
By the same token a load average of 2 means two processes are waiting for service by the CPU
|
Oft quoted but not necessarily true.
The load average also includes tasks in "uninterruptible sleep". Generally this means (disk) I/O. Can be the major contributor to the loadavg numbers, especially if the runqueue is short.
|
|
|
06-07-2007, 09:29 AM
|
#5
|
Member
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548
Rep:
|
Quote:
Originally Posted by syg00
Oft quoted but not necessarily true.
The load average also includes tasks in "uninterruptible sleep". Generally this means (disk) I/O. Can be the major contributor to the loadavg numbers, especially if the runqueue is short.
|
I do believe that is why it's called a 'Rule of thumb'. It is more true than untrue in my opinion.
|
|
|
06-09-2007, 02:21 PM
|
#6
|
Member
Registered: Oct 2006
Location: India
Distribution: Fedora Core 6, Archlinux Duke
Posts: 52
Original Poster
Rep:
|
Thank you!! One and all. The info provided was really helpful. 
|
|
|
All times are GMT -5. The time now is 10:57 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|