Linux display average CPU load for last week

thornate picture thornate · Feb 10, 2009 · Viewed 68.8k times · Source

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.

Answer

Brian Gianforcaro picture Brian Gianforcaro · Feb 10, 2009

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