Mean in green
I'm Kevin. I live in Salem, Mass with my wife and little boy and I build software.

Using sar to analyze server performance

Thursday Oct 09, 2008

Recently I've become addicted to the linux command sar (system activity reporter), which is reporting application for sadc (system activity data collector) that comes bundled with sysstat. This is a great way to see daily trends in resource usage like processor, memory, load averages, I/O and more. It comes bundled with RedHat distros, but you can also install it yourself via one of the RPM repositories.

Basically, there are two cron jobs that call sa1 and sa2. sa1 logs the current load, and sa2 compiles them into one daily log. The output can be displayed using sar.

The default settings create a log entry every ten minutes, but you can edit this by modifying the cron job that calls sa1 (RedHat puts it in /etc/cron.d/sysstat).

So, to look at today's load averages, you could use the -q flag:

$ sar -q

The output is similar to the load averages in the uptime command: current, five and fifteen minute load average figures.

Or, to look at today's memory usage, use the -r flag:

$ sar -r

the output of memory is very similar to that of top showing free, cached, swap, etc.

The logs are kept by default in /var/log/sa/sa[day], so to look at the memory usage for the first of the month, use:

$ sar -r -f /var/log/sa/sa01

But beware that these logs get rotated, so if there is a particular day that you need to save, be sure to create an archive somewhere.

I've been using sar daily. It's a great way to get a feeling of how your site is performing during varying traffic and can be a great tool to help diagnose bottlenecks. There are a slew of options that you can use with sar to report on different aspects like processes, TTY, switching, swapping and a lot more that you may or may not need.

Happy tracking!!