LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-10-2006, 07:36 AM   #1
mguleren
LQ Newbie
 
Registered: Feb 2006
Posts: 3

Rep: Reputation: 0
record CPU history


Is there a way to record CPU history, for example in a text file as data form. Like this:

time(s) CPU(%)
0.1 87
0.2 79
0.3 86
. .
. .
. .


would it be possible?
 
Old 03-10-2006, 10:35 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The sar command can do this, to be more exact: A combination of sa1, sa2 and sar.

sa1 and sa2 run from crontab, sar can show various system related information (cpu usage being just one). There are different ways to set up this automated reporting (which can be queried by sar) and/or daily summaries, which are human readable.

I've set it up as follows (crontab entries):

Code:
# ---------------------------------------------------------------------------- #
# Sar - reports                                                 [hourly xx:00]
00 * * * * /usr/lib/sa/sa1 300 12
# sar - daily summary                                            [daily 23:59]
59 23 * * * /usr/lib/sa/sa2 -A
The first line (sa1 300 12) is executed every hour on the hour. sa1 runs 12 times with 5 minute (300 sec) intervals. This creates the /var/log/sa/saDD files (DD being day number).

The second line creates a 24 hour report, cron executes this at 23:59.

For more details: man sar / man sa1 / man sa2

The info given is a bit more elaborate then you asked. Besides the percentage used by one (or more) CPU, it breaks it down and also shows who used the CPU. Output wil look like this:

Code:
15:19:59          CPU     %user     %nice   %system   %iowait     %idle
15:24:59          all      0.00     16.60      3.98      2.54     76.87
15:29:59          all      0.00     20.40      2.30      0.51     76.78
15:34:59          all      0.00     50.38      9.28      0.45     39.89
15:39:59          all      0.00     30.90      3.96      0.43     64.71
15:44:59          all      0.00     63.84     15.25      0.19     20.73
15:49:59          all      0.00     29.37      2.12      0.48     68.03
I'm still setting up this box, so there's no user activity.

Hope this helps.

PS: You don't mention your distro, it could be that sar isn't installed by default.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Download history and copy history? inverted.gravity Linux - Newbie 1 02-21-2006 12:31 PM
Unable to record mic-in with SoundBlaster Live! while able to record other sources max76230 Linux - Newbie 2 03-14-2005 04:31 AM
please help guys, wrong cpu speed shown with a regular non-mobile cpu !! : ( maku Linux - Hardware 1 01-02-2005 02:03 PM
Record video with small CPU? theYinYeti Linux - Software 1 11-16-2004 07:34 AM
How to find back "history" database after "history -c" ? san_lss Linux - Newbie 1 01-07-2004 11:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:38 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration