Wise people learn when they can; fools learn when they must - Arthur Wellesley

Saturday, 11 August 2018

LINUX- 36 SAR (RHEL-7) P1


                              LINUX- 36 SAR (RHEL-7) P1

**Its same for RHEL6 as well as RHEL7**

Other posts under SAR,
System Activity Report (SAR)

Detailed overview of system to call every performance/utilization data, even can retrieve historical data as well.

The sar command produces system utilization reports based on the data collected by sadc. “sadc” used to collect the performance/utilization related files and “sar” processes those files to refine the result as per our requirement.

We can fetch following utilization details,

CPU usage, Memory utilization, I/O devices consumption, Network monitoring, Disk usage, process and thread allocation, battery performance, Plug and play devices, Processor performance, file system and more

What is “sadc”?

sadc - System activity data collector.
/usr/lib64/sa/sadc

The sadc command collects system utilization data and writes it to a file for further analysis by sar. By default, the data is written to files in the /var/log/sa/ directory, like below.

-rw-r--r--. 1 root root  64016 Jul 28 19:10 sa28
-rw-r--r--. 1 root root  98816 Jul 29 19:00 sa29

Here filename is sa<date>, where date is current day.

We can also use “sadc” directly,

[root@rhel7-server ~]# /usr/lib64/sa/sadc 1 5 >test.txt

[root@rhel7-server ~]# cat test.txt
▒▒q!
▒▒n[
    Linuxrhel7-server3.10.0-121.el7.x86_64x86_64▒▒▒ ▒▒@▒0▒X"▒▒ 
▒▒0VV▒▒▒&dw@▒▒▒▒▒▒▒n▒T▒▒Nw\s▒y▒+f▒▒
▒▒▒▒
_▒}▒eth2▒#▒#N▒V2Z▒▒eth1▒R
N▒
loeth0eth1eth2lo▒
tU▒+▒▒W▒IV▒▒0[VШ▒&dw@▒▒▒▒▒▒▒nT4▒▒▒T4▒Nw\s▒y▒-|▒▒
▒▒▒
▒▒}▒eth2▒#▒#N▒0WV2▒▒▒eth1▒R

Great O/P …. ☹☹

He He He …. We can’t open it directly, must use sar to view it.

[root@rhel7-server ~]# sar -A -f test.txt


sar è sadc è sysstat

So, sysstat package is base for all these sar thing.

Sometimes, it might be possible that we don’t have “sar” command by default.

Don’t take “sysstat” lightly, along with sar it also responsible for followings,

sar: collects and reports system activity information
iostat: reports CPU utilization and disk I/O statistics
mpstat: reports global and per-processor statistics
pidstat: reports statistics for Linux tasks (processes)
sadf: displays data collected by sar in various formats


[root@rhel6-server ~]# sar
bash: sar: command not found
[root@rhel6-server ~]# iostat
bash: iostat: command not found
[root@rhel6-server ~]# mpstat
bash: mpstat: command not found
[root@rhel6-server ~]# pidstat
bash: pidstat: command not found
[root@rhel6-server ~]# whereis sadf
sadf:

In such case we have to find for “sysstat” package.

[root@rhel6-server ~]# rpm -qa |grep sysstat

Nothing in o/p, means no sysstat, lets install.

[root@rhel6-server ~]# yum -y install sysstat
[root@rhel6-server ~]# sar
Cannot open /var/log/sa/sa11: No such file or directory

Why above error message,

[root@rhel6-server ~]# ls -l /var/log/sa
total 0

There is no file in /var/log/sa, because I just installed sysstat package and in next 10 minutes we will get our first file…

Great, But HOW ………

Config file for sysstat,

[root@rhel6-server ~]# cat /etc/sysconfig/sysstat
# sysstat-9.0.4 configuration file.

# 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=7

# Compress (using gzip or bzip2) sa and sar files older than (in days):
COMPRESSAFTER=10

# Parameters for the system activity data collector (see sadc manual page)
# which are used for the generation of log files.
SADC_OPTIONS="-S DISK"

Cron entry for sysstat,

[root@rhel6-server ~]# 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


There are two scripts here,

SA1 & SA2.

SA1,
Periodically invoked by cron via the file sysstat, which is located in /etc/cron.d/. The sa1 script invokes sadc for a single one-second measuring interval. By default, cron runs sa1 every 10 minutes, adding the data collected during each interval to the current /var/log/sa/sa<dd> file.

SA2,
Periodically invoked by cron via the file sysstat, which is located in /etc/cron.d/. By default, cron runs sa2 once a day at 23:53, allowing it to produce a report for the entire day's data.

OK, enough of theory now. Let’s make the sar in action.


No comments:

Post a Comment