The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters, writes information the specified number of times spaced at the specified intervals in seconds.
If the interval parameter is set to zero, the sar command displays the average statistics for the time since the system was started. If the interval parameter is specified without the count parameter, then reports are generated continuously.
The collected data can also be saved in the file specified by the -o filename flag, in addition to being displayed onto the screen. If filename is omitted, sar uses the standard system activity daily data file, the /var/log/sa/sadd file,where the dd parameter indicates the current day.
Install SAR
We can install SAR using yum, with following command
# yum install sysstat
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
dockerrepo                                                                                                                                      | 2.9 kB 00:00:00
rhui-REGION-client-config-server-7Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â | 2.9 kB 00:00:00
rhui-REGION-rhel-server-releases                                                                                                                | 3.5 kB 00:00:00
rhui-REGION-rhel-server-rh-common                                                                                                              | 3.8 kB 00:00:00
(1/3): rhui-REGION-rhel-server-releases/7Server/x86_64/group                                                                                   | 699 kB 00:00:00
(2/3): rhui-REGION-rhel-server-releases/7Server/x86_64/updateinfo                                                                              | 1.3 MB 00:00:00
(3/3): rhui-REGION-rhel-server-releases/7Server/x86_64/primary_db                                                                              | 26 MB 00:00:01
Resolving Dependencies
–> Running transaction check
—> Package sysstat.x86_64 0:10.1.5-7.el7 will be installed
–> Processing Dependency: libsensors.so.4()(64bit) for package: sysstat-10.1.5-7.el7.x86_64
–> Running transaction check
—> Package lm_sensors-libs.x86_64 0:3.3.4-11.el7 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================================================================
Package                              Arch                        Version                           Repository                                              Size
========================================================================================================================================================================
Installing:
sysstat                              x86_64                      10.1.5-7.el7                      rhui-REGION-rhel-server-releases                      296 k
Installing for dependencies:
lm_sensors-libs                      x86_64                       3.3.4-11.el7                      rhui-REGION-rhel-server-releases                        40 k
Transaction Summary
========================================================================================================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 336 k
Installed size: 1.1 M
Downloading packages:
(1/2): lm_sensors-libs-3.3.4-11.el7.x86_64.rpm                                                                                                 | 40 kB 00:00:00
(2/2): sysstat-10.1.5-7.el7.x86_64.rpm                                                                                                          | 296 kB 00:00:00
————————————————————————————————————————————————————————
Total                                                                                                                                 900 kB/s | 336 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : lm_sensors-libs-3.3.4-11.el7.x86_64Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1/2
Installing : sysstat-10.1.5-7.el7.x86_64Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2/2
Verifying : sysstat-10.1.5-7.el7.x86_64Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 1/2
Verifying : lm_sensors-libs-3.3.4-11.el7.x86_64Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 2/2
Installed:
sysstat.x86_64 0:10.1.5-7.el7
Dependency Installed:
lm_sensors-libs.x86_64 0:3.3.4-11.el7
Complete!
Check SAR
Once installed, verify the sar version using following command:
# sar –V
sysstat version 10.1.5
(C) Sebastien Godard (sysstat <at> orange.fr)
Collect the statistics using cron job
Create sysstat file under /etc/cron.d directory that will collect the historical sar data.
# cat /etc/cron.d/sysstat
# Run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib64/sa/sa1 1 1
# 0 * * * * root /usr/lib64/sa/sa1 600 6 &
# Generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib64/sa/sa2 -A
- So the first cron entry will run every 10 minutes which will call the sadc utility and collect system stats and store it in a binary file.
- And the second cron entry will dump all the contents of that binary file into another text file.
By default 7 days statistics, So you can modify that HISTORY entry easily by editing the file.
# cat /etc/sysconfig/sysstat
# How long to keep log files (in days).
# If value is greater than 28, then log files are kept in
# multiple directories, one for each month.
HISTORY=28
By default all the statistics will save /var/log/sa location.
# cd /var/log/sa