The SAR tool is used to get the running status of the system under Linux

Time:2020-9-13

SAR to find the bottleneck of the system
SAR is the abbreviation of system activity reporter. SAR tool will sample the current state of the system, and then express the current running state of the system by calculating the data and proportion. It can continuously sample the system and obtain a large number of sampling data; the sampling data and analysis results can be stored in files, and the load required is very small. SAR is one of the most comprehensive system performance analysis tools on Linux. It can report system activities from 14 aspects, including file reading and writing, system call usage, serial port, CPU efficiency, memory usage, process activity and IPC related activities, etc.

SAR is one of the most popular and convenient tools to view operating system report indicators;
1. Retrospective Statistics (default)
2. Check the current data periodically

install

If it is not installed, it is very convenient to install it.

Copy code

The code is as follows:

[[email protected] ~]# yum install sysstat

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.grandcloud.cn
* extras: mirrors.grandcloud.cn
* updates: mirrors.grandcloud.cn
addons                                                   | 1.9 kB     00:00    
base                                                     | 1.1 kB     00:00    
extras                                                   | 2.1 kB     00:00    
updates                                                  | 1.9 kB     00:00    
updates/primary_db                                       | 255 kB     00:01    
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package sysstat.i386 0:7.0.2-11.el5 set to be updated
–> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package           Arch           Version                  Repository      Size
================================================================================
Installing:
sysstat           i386           7.0.2-11.el5             base           182 k

Transaction Summary
================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 182 k
Is this ok [y/N]: y
Downloading Packages:
sysstat-7.0.2-11.el5.i386.rpm                            | 182 kB     00:01    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : sysstat                                                  1/1

Installed:
  sysstat.i386 0:7.0.2-11.el5                                                  

Complete!

After installation, turn on the switch of the performance collection tool

Copy code

The code is as follows:

</p>
<p>vi /etc/default/sysstat</p>
<p>ENABLED=”true”

Start this tool to collect system performance data:

Copy code

The code is as follows:

/etc/init.d/sysstat start

Note: SAR is the front-end display tool of SADC. After installing the package named “sysstat”, SADC will automatically collect reports from the kernel and save them.

The following is a summary of the general usage of SAR in order to remember it.

Sometimes it is necessary to combine several SAR commands to determine the bottleneck
If it is suspected that there is a bottleneck in CPU, SAR – U and SAR – Q can be used to check
If memory bottleneck is suspected, sar-b, sar-r and sar-w can be used to check
If I / O is suspected to be bottleneck, sar-b, sar-u and sar-d can be used to check

Looking back on the past statistics
By default, SAR displays data from the latest 0:00 am. If you want to continue to view the report of a day ago, you can view the SA log saved in / var / log / sysstat /;
Use the SAR tool to view:

Copy code

The code is as follows:

sar -f /var/log/sysstat/sa28 | head
sar -r -f /var/log/sysstat/sa28

20151227120003325.png (640×140)

View CPU usage

Copy code

The code is as follows:

sar -u 1 5

By default, the display of CPU utilization and other information is sar-u;
20151227120024046.png (640×118)

It can be seen that this machine uses virtualization technology and has corresponding time consumption;
The indicators of each column are as follows:
%user
The proportion of CPU time consumed in user mode;
%nice
The proportion of CPU time consumed in user mode is changed by nice
%system
The proportion of CPU time consumed in system mode;
%iowait
The ratio of idle state consumption caused by CPU waiting for disk I / O;
%steal
Using Xen and other operating system virtualization technology, waiting for other virtual CPU to calculate the proportion of time occupied;
%idle
CPU idle time ratio;

View average load

Copy code

The code is as follows:

sar -q

When – Q is specified, the number of processes in the running queue, the size of processes on the system, and the average load can be viewed;
 20151227120044386.png (640×117)

Runq SZ: length of the run queue (number of processes waiting to run)
Plist SZ: the number of processes and threads in the process list
Ldavg-1: average system load in the last minute
Ldavg-5: average system load in the past 5 minutes
Ldavg-15: average system load in the past 15 minutes

View memory usage

Copy code

The code is as follows:

sar -r

After – R is specified, you can check the memory usage in the room;
20151227120100933.png (640×149)

Kbmemfree: this value is basically consistent with the free value in the free command, so it does not include buffer and cache space
Kbmemused: this value is basically consistent with the used value in free command, so it includes buffer and cache space
%Memused: physical memory usage as a percentage of kbmemused and total memory (excluding swap)
Kbbuffers and kbcached: these two values are buffer and cache in the free command
Kbcommit: ensure the memory required by the current system, that is, the memory required to ensure that it does not overflow (RAM + swap)
%Commit: this value is a percentage of kbcommit to total memory (including swap)

View page swapping

Copy code

The code is as follows:

sar -W

When page swapping occurs, the throughput of the server will drop significantly; when the server is in poor condition, if you suspect that page swapping has occurred due to insufficient memory, you can use this command to confirm whether a large number of page swapping has occurred;
 20151227120116426.png (640×135)

Pswpin / s: the number of swap pages the system switches in per second
Pswpout / s: the number of swap pages swapped out by the system per second

SAR parameter description
Option function
-A summarize all the reports
-A report the use of file reading and writing
-B reports the usage of the additional cache
-B report cache usage
-C reports the usage of system calls
-D report disk usage
-G report the use of serial port
-H Reports Statistics on buffer usage
-M reports IPC message queue and semaphore usage
-N report the usage of named cache
-P reports on the use of paging activities
-Q reports the average length of the run and exchange queues
-R reports the activity of the process
-R reports unused memory pages and hard disk blocks
-U reports CPU utilization
-Report process, I node, file and lock table status
-W report system exchange activity status
-Y report TTY equipment activity status