LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   record CPU history (https://www.linuxquestions.org/questions/linux-general-1/record-cpu-history-423478/)

mguleren 03-10-2006 07:36 AM

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?

druuna 03-10-2006 10:35 AM

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.


All times are GMT -5. The time now is 05:16 PM.