LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 06-06-2007, 10:41 AM   #1
neothephoenix
Member
 
Registered: Oct 2006
Location: India
Distribution: Fedora Core 6, Archlinux Duke
Posts: 52

Rep: Reputation: 15
Unhappy 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?
 
Old 06-06-2007, 01:05 PM   #2
Vookimedlo
Member
 
Registered: Jul 2004
Location: Czech Republic - Roudnice nad Labem
Distribution: Debian
Posts: 253

Rep: Reputation: 33
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.
 
Old 06-06-2007, 01:17 PM   #3
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 542

Rep: Reputation: 33
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.
 
Old 06-06-2007, 01:41 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,095

Rep: Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978
"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.
 
Old 06-07-2007, 09:29 AM   #5
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 542

Rep: Reputation: 33
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.
 
Old 06-09-2007, 02:21 PM   #6
neothephoenix
Member
 
Registered: Oct 2006
Location: India
Distribution: Fedora Core 6, Archlinux Duke
Posts: 52

Original Poster
Rep: Reputation: 15
Thank you!! One and all. The info provided was really helpful.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
i want to convert .wav file into mp3 files in batch mode sparsh Linux - Software 6 11-20-2007 10:53 AM
Gimp batch mode! experienced an execution error. Shioni Linux - Software 0 04-21-2006 06:41 AM
gpg in batch mode - help cricos Linux - Newbie 1 01-21-2006 08:14 PM
How can I change display mode from character mode to graph mode wuzhong Linux - Hardware 1 08-08-2004 09:36 AM
MySQL in batch mode ganninu Linux - General 1 11-20-2003 05:49 AM


All times are GMT -5. The time now is 01:05 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration