How to install and configure sar

Israel Barth
Israel Barth

sar is an application that comes as part of sysstat package. It's used to collect, report and save system activity information, and the information provided by sar is usually very useful to diagnose system behavior during an incident cause analysis.

Please note that sar gathers aggregated data, and by default it performs the aggregation every 10 minutes. For support incident analysis it's better if sar is configured to gather data every minute, as it gets less prone to hide localized issues, and that setup is what will be explained in the following sections.

How to install and configure sar

In this knowledge base article we explain how to install and configure sar in some of the supported operating systems.

CentOS 7 / RHEL 7

Pre-requisites

  • cron: cron must be installed and enabled in the server

Install sar

  • Install sysstat:
yum install -y sysstat
  • Check sar is working:
sar -V

Output will look like:

[root@14432f28165c ~]# sar -V
sysstat version 10.1.5
(C) Sebastien Godard (sysstat <at> orange.fr)
  • Once the system time hits a multiple of 10 minutes, check that sar is reporting per 10 minutes data aggregation:
sar

Output will look like:

[root@14432f28165c ~]# sar
Linux 5.10.47-linuxkit (14432f28165c) 03/18/22 _x86_64_ (8 CPU)

18:50:01 CPU %user %nice %system %iowait %steal %idle
18:50:01 all 0.03 0.00 0.08 0.00 0.00 99.89
Average: all 0.03 0.00 0.08 0.00 0.00 99.89

Configure sar to run every minute

  • Configure the cronjob to run every minute instead of every 10 minutes:
vi /etc/cron.d/sysstat

And replace a line that would look like this:

*/10 * * * * root /usr/lib64/sa/sa1 1 1

With something like this:

* * * * * root /usr/lib64/sa/sa1 1 1
  • After a couple of minutes check that sar is reporting per minute data aggregation:
sar

Output will look like:

[root@14432f28165c ~]# sar
Linux 5.10.47-linuxkit (14432f28165c) 03/18/22 _x86_64_ (8 CPU)

18:50:01 CPU %user %nice %system %iowait %steal %idle
18:50:01 all 0.03 0.00 0.08 0.00 0.00 99.89
18:52:01 all 0.03 0.00 0.08 0.00 0.00 99.89
18:53:01 all 0.03 0.00 0.08 0.00 0.00 99.89
Average: all 0.03 0.00 0.08 0.00 0.00 99.89

Rockylinux 8 / Almalinux 8 / RHEL 8

Install sar

  • Install sysstat:
dnf install -y sysstat
  • Check sar is working:
sar -V

Output will look like:

[root@e7e5a1bdcd99 ~]# sar -V
sysstat version 11.7.3
(C) Sebastien Godard (sysstat <at> orange.fr)
  • Enable the service unit:
systemctl enable --now sysstat
  • Once the system time hits a multiple of 10 minutes, check that sar is reporting per 10 minutes data aggregation:
sar

Output will look like:

Linux 5.10.47-linuxkit (e7e5a1bdcd99) 03/22/22 _x86_64_ (8 CPU)

15:13:18 LINUX RESTART (8 CPU)

15:15:24 CPU %user %nice %system %iowait %steal %idle
15:20:40 all 0.03 0.00 0.08 0.00 0.00 99.88
Average: all 0.03 0.00 0.08 0.00 0.00 99.88

Configure sar to run every minute

  • Configure the unit to run sar every minute instead of every 10 minutes:
systemctl edit sysstat-collect.timer

Set with the following content:

[Timer]
OnCalendar=*:00/1
  • Restart the unit:
systemctl restart sysstat-collect.timer
  • After a couple of minutes check that sar is reporting per minute data aggregation:
sar

Output will look like:

Linux 5.10.47-linuxkit (e7e5a1bdcd99) 03/22/22 _x86_64_ (8 CPU)

15:13:18 LINUX RESTART (8 CPU)

15:15:24 CPU %user %nice %system %iowait %steal %idle
15:20:40 all 0.03 0.00 0.08 0.00 0.00 99.88
15:22:40 all 0.03 0.00 0.09 0.00 0.00 99.87
15:23:44 all 0.03 0.00 0.07 0.00 0.00 99.90
Average: all 0.03 0.00 0.08 0.00 0.00 99.88

Ubuntu Bionic / Ubuntu Focal / Debian Buster

Pre-requisites

  • cron: cron must be installed and enabled in the server

Install sar

  • Install sysstat:
apt install -y sysstat
  • Check sar is working:
sar -V

Output will look like:

root@bcc7a7f5907d:~# sar -V
sysstat version 11.6.1
(C) Sebastien Godard (sysstat <at> orange.fr)
  • Enable sar to execute:
vi /etc/default/sysstat

And replace the following:

ENABLED="false"

With the following:

ENABLED="true"
  • Enable the service unit:
systemctl enable --now sysstat
  • Once the system time hits a multiple of 10 minutes, check that sar is reporting per 10 minutes data aggregation:
sar

Output will look like:

root@bcc7a7f5907d:~# sar
Linux 5.10.47-linuxkit (bcc7a7f5907d) 03/22/22 _x86_64_ (8 CPU)

16:30:19 CPU %user %nice %system %iowait %steal %idle
16:30:24 all 0.05 0.00 0.14 0.00 0.00 99.81
Average: all 0.05 0.00 0.14 0.00 0.00 99.81

Configure sar to run every minute

  • Configure the cronjob to run every minute instead of every 10 minutes:
vi /etc/cron.d/sysstat

And replace the lines that would look like this:

# Activity reports every 10 minutes everyday
5-55/10 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1

With something like this:

# Activity reports every minute everyday
* * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
  • After a couple of minutes check that sar is reporting per minute data aggregation:
sar

Output will look like:

root@bcc7a7f5907d:~# sar
Linux 5.10.47-linuxkit (bcc7a7f5907d) 03/22/22 _x86_64_ (8 CPU)

16:30:19 CPU %user %nice %system %iowait %steal %idle
16:30:24 all 0.05 0.00 0.14 0.00 0.00 99.81
16:32:01 all 0.09 0.00 0.09 0.00 0.00 99.81
16:33:01 all 0.04 0.00 0.08 0.00 0.00 99.88
Average: all 0.08 0.00 0.09 0.00 0.00 99.82

Debian Bullseye

Install sar

  • Install sysstat:
apt install -y sysstat
  • Check sar is working:
sar -V

Output will look like:

root@323afce4e38a:~# sar -V
sysstat version 12.5.2
(C) Sebastien Godard (sysstat <at> orange.fr)
  • Enable sar to execute:
vi /etc/default/sysstat

And replace the following:

ENABLED="false"

With the following:

ENABLED="true"
  • Enable the service unit:
systemctl enable --now sysstat
  • Once the system time hits a multiple of 10 minutes, check that sar is reporting per minute data aggregation:
sar

Output will look like:

root@521f16824f19:~# sar
Linux 5.10.47-linuxkit (521f16824f19) 03/22/22 _x86_64_ (8 CPU)

18:49:23 LINUX RESTART (8 CPU)

18:50:05 CPU %user %nice %system %iowait %steal %idle
18:50:05 all 0.04 0.00 0.09 0.00 0.00 99.88
18:56:05 all 0.04 0.00 0.09 0.00 0.00 99.88
18:57:05 all 0.03 0.00 0.08 0.00 0.00 99.90
18:58:05 all 0.03 0.00 0.08 0.00 0.00 99.89
18:59:05 all 0.03 0.00 0.07 0.00 0.00 99.90
Average: all 0.03 0.00 0.08 0.00 0.00 99.89

Configure sar to run every minute

  • Configure the unit to run sar every minute instead of every 10 minutes:
systemctl edit sysstat-collect.timer

Set with the following content:

[Timer]
OnCalendar=*:00/1
  • Restart the unit:
systemctl restart sysstat-collect.timer
  • After a couple of minutes check that sar is reporting per minute data aggregation:
sar

Output will look like:

root@521f16824f19:~# sar
Linux 5.10.47-linuxkit (521f16824f19) 03/22/22 _x86_64_ (8 CPU)

18:49:23 LINUX RESTART (8 CPU)

18:50:05 CPU %user %nice %system %iowait %steal %idle
18:50:05 all 0.04 0.00 0.09 0.00 0.00 99.88
18:56:05 all 0.04 0.00 0.09 0.00 0.00 99.88
18:57:05 all 0.03 0.00 0.08 0.00 0.00 99.90
Average: all 0.03 0.00 0.08 0.00 0.00 99.89

Additional resources

Was this article helpful?

0 out of 0 found this helpful