views:

1898

answers:

3

On a Linux box, I need to display the average CPU utilisation per hour for the last week. Is that information logged somewhere? Or do I need to write a script that wakes up every 15 minutes to copy /proc/loadavg to a logfile?

EDIT: I'm not allowed to use any tools other than those that come with Linux.

+2  A: 

As far as I know it's not stored anywhere... It's a trivial thing to write, anyway. Just add something like

cat /proc/loadavg >> /var/log/loads

to your crontab.

Note that there are monitoring tools (like Munin) which can do this kind of thing for you, and generate pretty graphs of it to boot... they might be overkill for your situation though.

David Zaslavsky
+2  A: 

You might want to check out sar (man page), it fits your use case nicely.

System Activity Reporter (SAR) - capture important system performance metrics at periodic intervals.

Example from IBM Developer Works Article:

Add an entry to your root crontab

# Collect measurements at 10-minute intervals
0,10,20,30,40,50   * * * *   /usr/lib/sa/sa1
# Create daily reports and purge old files
0                  0 * * *   /usr/lib/sa/sa2 -A

Then you can simply query this information using a sar command (display all of today's info):

root ~ # sar -A

Or just for a certain days log file:

root ~ # sar -f /var/log/sa/sa16

You can usually find it in the sysstat package for your linux distro

Brian Gianforcaro
+1, sounds like a neat little tool
David Zaslavsky
I looked at sar. But as far as I can see it only shows the current CPU. I'd have to have it running every few seconds and do averages.Please tell me if I'm wrong, as it would be useful.
thornate
You set sar up to log to a file using the crontab example in my answer. You can then use sar to query that generated log, or a number of logs for the stats you want (load average).
Brian Gianforcaro
But does that not mean having sar running every few seconds? Wouldn't that be inefficient compared to just checking the /proc/loadavg log every 15 minutes?
thornate
@thornate check the man page for sar. It stores loadaverages.
Zoredache
A: 

I would recommend looking at Multi Router Traffic Grapher (MRTG).

Using snmpd to read the load average, it will automatically calculate averages at any time interval and length, along with nice charts for analysis.

Someone has already posted a CPU usage example.

Casey