How to Install and Use SAR(System Activity Reporting) in Linux?

I have tried to document step by step How to Install and Use SAR(System Activity Reporting) in Linux. I hope it will be useful for those who need it!

SAR Installation

Install sysstat Package

##### For Debian Based Linux #####
sudo apt-get install sysstat

##### For Redhat Based Linux #####
sudo yum install sysstat

Set Retention as to Need

##### For Debian Based Linux #####
vi /etc/sysstat/sysstat
HISTORY=30
Save & Quit

# HISTORY: Number of days to retain SAR data. Default 7 Days.
more /etc/sysstat/sysstat | grep HISTORY
HISTORY=30

##### For Redhat Based Linux #####
vi /etc/sysconfig/sysstat
HISTORY=30
Save & Quit

# HISTORY: Number of days to retain SAR data. Default 28 Days.
more /etc/sysconfig/sysstat | grep HISTORY
HISTORY=30

Enable Stat Collection

##### For Debian Based Linux #####
vi /etc/default/sysstat
change ENABLED="false" to ENABLED="true"
Save & Quit

##### For Redhat Based Linux #####
vi /etc/sysconfig/sysstat
add ENABLED="true" to the end of file 
Save & Quit

Enable and Restart sysstat Service

##### Both Debian and Redhat Based Linux #####

sudo systemctl enable sysstat

sudo systemctl restart sysstat

sudo systemctl status sysstat

NOTE: SAR collection interval time is every 10 minutes. So first time you enable statistic collection, you need to wait for 10 minutes before running sar command to get meaningful data.

Check Generated Report Files

SAR file names start with sa and followed by current day of month. For Example: sa04

##### For Debian Based Linux #####
SAR reports are stored under /var/log/sysstat
# ls -lrt /var/log/sysstat
-rw-r--r-- 1 root root  17808 Apr  4 14:50 sa04

##### For Redhat Based Linux #####
SAR reports are stored under /var/log/sa
# ls -lrt /var/log/sa
-rw-r--r--. 1 root root 2420 Apr  4 14:50 sa04

Check Frequency of SAR Statistics Collection

##### For Debian Based Linux #####
more /etc/cron.d/sysstat

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

##### For Redhat Based Linux #####
more /usr/lib/systemd/system/sysstat-collect.timer | grep OnCalendar

# Activity reports every 10 minutes everyday
OnCalendar=*:00/10

Useful SAR Commands

##### CHECK CPU STATS #####
sar

sar -s 18:00:00 -e 19:00:00                                 Between 6PM and 7PM 

sar -f /var/log/sysstat/sa04                                (DEBIAN) 4th day of month
sar -f /var/log/sa/sa04                                     (REDHAT) 4th day of month

sar -f /var/log/sysstat/sa04 -s 18:00:00 -e 19:00:00        (DEBIAN) 4th day of month & 6pm-7pm
sar -f /var/log/sa/sa04 -s 18:00:00 -e 19:00:00             (REDHAT) 4th day of month & 6pm-7pm

##### CHECK RAM STATS #####
sar -r

sar -r 18:00:00 -e 19:00:00                                  Between 6PM and 7PM

sar -r -f /var/log/sysstat/sa04                              (DEBIAN) 4th day of month
sar -r -f /var/log/sa/sa04                                   (REDHAT) 4th day of month

sar -r -f /var/log/sysstat/sa04 -s 18:00:00 -e 19:00:00      (DEBIAN) 4th day of month & 6pm-7pm
sar -r -f /var/log/sa/sa04 -s 18:00:00 -e 19:00:00           (REDHAT) 4th day of month & 6pm-7pm

##### CHECK SWAP STATS #####
sar -S

sar -S 18:00:00 -e 19:00:00                                   Between 6PM and 7PM

sar -S -f /var/log/sysstat/sa04                               (DEBIAN) 4th day of month
sar -S -f /var/log/sa/sa04                                    (REDHAT) 4th day of month

sar -S -f /var/log/sysstat/sa04 -s 18:00:00 -e 19:00:00       (DEBIAN) 4th day of month & 6pm-7pm
sar -S -f /var/log/sa/sa04 -s 18:00:00 -e 19:00:00            (REDHAT) 4th day of month & 6pm-7pm

##### CHECK DISK STATS #####
sar -b

sar -b 18:00:00 -e 19:00:00                                    Between 6PM and 7PM

sar -b -f /var/log/sysstat/sa04                                (DEBIAN) 4th day of month
sar -b -f /var/log/sa/sa04                                     (REDHAT) 4th day of month

sar -b -f /var/log/sysstat/sa04 -s 18:00:00 -e 19:00:00        (DEBIAN) 4th day of month & 6pm-7pm
sar -b -f /var/log/sa/sa04 -s 18:00:00 -e 19:00:00             (REDHAT) 4th day of month & 6pm-7pm

##### CHECK NETWORK STATS #####
sar -n DEV

sar -n DEV 18:00:00 -e 19:00:00                                 Between 6PM and 7PM

sar -n DEV -f /var/log/sysstat/sa04                             (DEBIAN) 4th day of month
sar -n DEV -f /var/log/sa/sa04                                  (REDHAT) 4th day of month

sar -n DEV -f /var/log/sysstat/sa04 -s 18:00:00 -e 19:00:00     (DEBIAN) 4th day of month & 6pm-7pm
sar -n DEV -f /var/log/sa/sa04 -s 18:00:00 -e 19:00:00          (REDHAT) 4th day of month & 6pm-7pm