How to configure SAR data collection on RHEL8

How to configure SAR data collection on RHEL8
Photo by Neil Mark Thomas / Unsplash

On RHEL8, it uses systemd instead of cron jobs to manage SAR data collection service.

Run the following command to check if the SAR data collection is started.

[root@h04-11 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.5 (Ootpa)

[root@h04-11 ~]# systemctl status sysstat-collect.timer
● sysstat-collect.timer - Run system activity accounting tool every 10 minutes
   Loaded: loaded (/usr/lib/systemd/system/sysstat-collect.timer; enabled; vendor preset: disabled)
   Active: inactive (dead)
  Trigger: n/a

If it's not started, run the following command to start it.

[root@h04-11 ~]# systemctl start sysstat-collect.timer
[root@h04-11 ~]# systemctl status sysstat-collect.timer
● sysstat-collect.timer - Run system activity accounting tool every 10 minutes
   Loaded: loaded (/usr/lib/systemd/system/sysstat-collect.timer; enabled; vendor preset: disabled)
   Active: active (waiting) since Tue 2022-01-04 19:49:54 UTC; 1s ago
  Trigger: Tue 2022-01-04 19:50:00 UTC; 4s left

Jan 04 19:49:54 h04-11 systemd[1]: Started Run system activity accounting tool every 10 minutes.

Check the sar file existence after a few minutes as below.

[root@h04-11 ~]# ls -ltr /var/log/sa
total 0
[root@h04-11 ~]# date
Tue Jan  4 19:50:25 UTC 2022
[root@h04-11 ~]# ls -ltr /var/log/sa
total 12
-rw-r--r--. 1 root root 11632 Jan  4 19:50 sa04

Check the default interval of SAR data collection as below.

[root@h04-11 ~]# systemctl cat sysstat-collect.timer
# /usr/lib/systemd/system/sysstat-collect.timer
# /usr/lib/systemd/system/sysstat-collect.timer
# (C) 2014 Tomasz Torcz <tomek@pipebreaker.pl>
#
# sysstat-11.7.3 systemd unit file:
#        Activates activity collector every 10 minutes

[Unit]
Description=Run system activity accounting tool every 10 minutes

[Timer]
OnCalendar=*:00/10

[Install]
WantedBy=sysstat.service

To change the interval of SAR data collection, edit the systemd unit file as below.

[root@h04-11 ~]# export SYSTEMD_EDITOR=/usr/bin/vi
[root@h04-11 ~]# systemctl edit sysstat-collect.timer

Add the following to set the desired interval. In this example, we changed it from 10 minutes to 1 minute. The blank "OnCalendar=" directive is there to remove the original setting.

[Unit]
Description=Run system activity accounting tool every 1 minute

[Timer]
OnCalendar=
OnCalendar=*:00/1

Reload systemd service to apply the change.

[root@h04-11 ~]# systemctl daemon-reload

[root@h04-11 ~]# systemctl cat sysstat-collect.timer
# /usr/lib/systemd/system/sysstat-collect.timer
# /usr/lib/systemd/system/sysstat-collect.timer
# (C) 2014 Tomasz Torcz <tomek@pipebreaker.pl>
#
# sysstat-11.7.3 systemd unit file:
#        Activates activity collector every 10 minutes

[Unit]
Description=Run system activity accounting tool every 10 minutes

[Timer]
OnCalendar=*:00/10

[Install]
WantedBy=sysstat.service

# /etc/systemd/system/sysstat-collect.timer.d/override.conf
[Unit]
Description=Run system activity accounting tool every 1 minute

[Timer]
OnCalendar=
OnCalendar=*:00/1

[root@h04-11 ~]# cat /etc/systemd/system/sysstat-collect.timer.d/override.conf
[Unit]
Description=Run system activity accounting tool every 1 minute

[Timer]
OnCalendar=
OnCalendar=*:00/1

[root@h04-11 ~]# systemctl status sysstat-collect.timer
● sysstat-collect.timer - Run system activity accounting tool every 1 minute
   Loaded: loaded (/usr/lib/systemd/system/sysstat-collect.timer; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/sysstat-collect.timer.d
           └─override.conf
   Active: active (running) since Tue 2022-01-04 19:49:54 UTC; 27min ago
  Trigger: n/a

Jan 04 19:49:54 h04-11 systemd[1]: Started Run system activity accounting tool every 10 minutes.

To verify if the interval of SAR data collection is modified successfully, do the following.

[root@h04-11 ~]# sar -u -f /var/log/sa/sa04
Linux 4.18.0-348.2.1.el8_5.x86_64 (h04-11) 	01/04/2022 	_x86_64_	(32 CPU)

07:50:18 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
08:00:18 PM     all      0.11      0.00      0.13      0.00      0.00     99.76
08:10:08 PM     all      0.11      0.00      0.13      0.00      0.00     99.75
08:14:08 PM     all      0.12      0.00      0.13      0.00      0.00     99.74
08:15:35 PM     all      0.12      0.00      0.13      0.01      0.00     99.73
08:16:18 PM     all      0.12      0.00      0.14      0.02      0.00     99.72
08:17:07 PM     all      0.10      0.00      0.13      0.00      0.00     99.77
08:18:18 PM     all      0.12      0.00      0.13      0.00      0.00     99.75
Average:        all      0.11      0.00      0.13      0.00      0.00     99.75

Reference