We can simply install and configure the SAR on Linux servers. In debian based server we can use the command “apt” to install the SAR utility.
First install sysstat package on the server with the help of apt command
root@Ubuntu:~# apt install sysstat
After install When we try to run sar command to get below error
root@Ubuntu:~# sar
Cannot open /var/log/sysstat/sa22: No such file or directory
Please check if data collecting is enabled
root@Ubuntu:~#
After we have installed sar we will need to configure it to collect and store performance data on a regular interval.
First edit the file “/etc/default/sysstat” using your favorite file editor and change ENABLED=”false” to ENABLED=”true”
root@Ubuntu:~# vi /etc/default/sysstat
#
# Default settings for /etc/init.d/sysstat, /etc/cron.d/sysstat
# and /etc/cron.daily/sysstat files
#
# Should sadc collect system activity informations? Valid values
# are "true" and "false". Please do not put other values, they
# will be overwritten by debconf!
ENABLED="true"
Restart the service
root@Ubuntu:~# service sysstat restart
Please run sar command after some time then it shows some data
For example : run below command sar -u to show cpu utilization
root@Ubuntu:~# sar -u
Linux 5.15.0-1023-azure (Ubuntu) 11/22/22 _x86_64_ (2 CPU)
05:20:16 LINUX RESTART (2 CPU)
05:25:01 CPU %user %nice %system %iowait %steal %idle
05:35:01 all 0.06 0.00 0.05 0.08 0.00 99.81
05:45:01 all 0.04 0.00 0.04 0.07 0.00 99.85
Average: all 0.05 0.00 0.05 0.07 0.00 99.83
root@Ubuntu:~#
Note : After this, a cronjob will start collecting the SAR report every 10 min, but we would want that report to be collected much sooner so we will change the cronjob as per our requirement.
We can change/update in file “/etc/cron.d/sysstat”
root@Ubuntu:~# cat /etc/cron.d/sysstat
# The first element of the path is a directory where the debian-sa1
# script is located
PATH=/usr/lib/sysstat:/usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin
# Activity reports every 10 minutes everyday
5-55/10 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
# Additional run at 23:59 to rotate the statistics file
59 23 * * * root command -v debian-sa1 > /dev/null && debian-sa1 60 2
root@Ubuntu:~#