Skip to content

How to configure sysstat/sar on Ubuntu/Debian


This article describes how to install and use sysstat (sar) a system performance tools for Linux. According to the package description it includes the following system performance tools:
– sar: collects and reports system activity information;
– iostat: reports CPU utilization and disk I/O statistics;
– mpstat: reports global and per-processor statistics;
– pidstat: reports statistics for Linux tasks (processes);
– sadf: displays data collected by sar in various formats.

The statistics reported by sar deal with I/O transfer rates,  paging activity, process-related activities, interrupts,  network activity, memory and swap space utilization, CPU  utilization, kernel activities and TTY statistics, among others. Both UP and SMP machines are fully supported.

Step 1.  Install sysstat
sudo apt-get install sysstat

Step 2. Enable stat collection
sudo vi /etc/default/sysstat
change ENABLED=”false” to ENABLED=”true”
save the file

Step 3. Change the collection interval from every 10 minutes to every 2 minutes.
sudo vi /etc/cron.d/sysstat
5-55/10 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
*/2 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
save the file

Step 4. Restart sysstat
sudo service sysstat restart

Step 5. If you want to see all statistics you can type:
sar -A

Step 6. If you want to save the statistics for further analysis to a file use:
sudo sar -A > $(date +`hostname`-%d-%m-%y-%H%M.log)


man sysstat
man sar

Posted in Knowledge Base.

Tagged with , , .

11 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Nick says

    A very clear and precise explanation of how to get sar up and running and writing to disk. I wish other articles on the web could be as clear…

  2. Raoul says

    Thanks, it just worked!

  3. Todor says

    Very nice intro!

  4. ken says

    thanks for writing this document and making it available.

  5. Remco says

    Thanks bro!

  6. Here is me says

    Thank you bro. I am using “top” to measure my server usage. Could you tell me if “sar” is better of “top” is better.

    Thank you very much.

  7. Peter says

    Step 6 is unneccessary as Sysstat already keeps all the statistics in binary format in /var/log/sysstat/saDD (where DD is the numeric date). This is determined by the HISTORY option in /etc/sysstat/sysstat . To read in a specific Sysstat file just use “sar -f FILE” (where FILE is the specific file from the /var/log/sysstat directory.)

  8. joanmi says

    Hello, i’m triying to do the thing and when i try to change ENABLED=flase to true there’s an incoming message that says something like “it was not possible to make a copy of the older document before saving the new balblabla…” and it don’t let me to save it. what can i do?

  9. Leo says

    Hi, I am not sure which text editor you are using but if you’re on a desktop machine you can use:
    gksu gedit
    otherwise use the following:
    sudo vi -r /etc/default/sysstat


  10. Leo says

    Both commands serve to a good purpose which is to show server statistics. Sar is helpful because it gives the information overtime and saves it in a database sort of. Top command gives you the current statistics happening at this moment.
    I think sar gives you more information about cpu usage, disk usage and memory usage. Also cpu tasks is very useful.


  11. Leo says

    Excellent point!
    I will still leave step 6 since it may be helpful for people that want to export the whole data and send it for example to another engineer for analisys.

Some HTML is OK

or, reply to this post via trackback.