Learn a Linux command every day (107): SAR

Time:2021-9-18

Command introduction

The SAR command is used to comprehensively obtain the performance data of the system, such as CPU, run queue, disk I / O, paging (swap area), memory, CPU interrupt and network.

Syntax format

sar -[ options ] time_interval number_of_tines_to_display

Option description

-A   # Summarize all reports
-a   # View file read / write usage
-B   # View the usage of the attached cache
-b   # View cache usage
-c   # View the usage of system calls
-d   # View disk usage
-g   # View the usage of serial port
-h   # View statistics on buffer usage
-m   # View IPC message queue and semaphore usage
-n   # View the usage of named cache
-p   # View the usage of paging activities
-q   # View average load
-R   # View the activity of the process
-r   # View unused memory pages and hard disk blocks
-u   # View CPU utilization
-v   # View the status of processes, I nodes, files, and lock tables
-w   # View system exchange activity
-y   # View TTY device activity

Application examples

View usage information of memory swap space

[[email protected] ~]# sar -r
Linux 3.10.0-1127.18.2.el7.x86_64 (centos7)  03/28/2021  _x86_64_ (1 CPU)
11:10:02 AM kbmemfree kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
11:20:01 AM    532544    463140     46.51      2108    313176    232184      7.51    216412    134456         0
11:30:01 AM    532504    463180     46.52      2108    313180    232184      7.51    216436    134412         0
Average:       532524    463160     46.52      2108    313178    232184      7.51    216424    134434         0

Output result field description

kbmemfree   # Amount of free physical memory
kbmemused   # Amount of physical memory in use
%memused    # Physical memory usage
kbbuffers   # The amount of physical memory used as a buffer in the kernel
kbcacheed   # The amount of physical memory used as a cache in the kernel
kbswpfree   # Free capacity of switching area
kbswpused   # Swap capacity in use

View CPU usage

[[email protected] ~]# sar -u
Linux 3.10.0-1127.18.2.el7.x86_64 (centos7)  03/28/2021  _x86_64_ (1 CPU)
11:10:02 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
11:20:01 AM     all      0.03      0.00      0.18      0.02      0.00     99.77
11:30:01 AM     all      0.03      0.00      0.17      0.02      0.00     99.78
Average:        all      0.03      0.00      0.18      0.02      0.00     99.77

View average load

[[email protected] ~]# sar -q
Linux 3.10.0-1127.18.2.el7.x86_64 (centos7)  03/28/2021  _x86_64_ (1 CPU)
11:10:02 AM   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15   blocked
11:20:01 AM         1       108      0.00      0.01      0.05         0
11:30:01 AM         1       108      0.00      0.01      0.05         0
Average:            1       108      0.00      0.01      0.05         0

View the occurrence of page exchange

[[email protected] ~]# sar -w
Linux 3.10.0-1127.18.2.el7.x86_64 (centos7)  03/28/2021  _x86_64_ (1 CPU)
11:10:02 AM    proc/s   cswch/s
11:20:01 AM      0.02     19.10
11:30:01 AM      0.03     19.92
11:40:01 AM      0.02     19.45
Average:         0.02     19.49

View I / O and transfer rate statistics

[[email protected] ~]# sar -b
Linux 3.10.0-1127.18.2.el7.x86_64 (centos7)  03/28/2021  _x86_64_ (1 CPU)
11:10:02 AM       tps      rtps      wtps   bread/s   bwrtn/s
11:20:01 AM      0.06      0.00      0.06      0.00      0.74
11:30:01 AM      0.03      0.00      0.03      0.00      0.40
Average:         0.05      0.00      0.05      0.00      0.57

Output field description

tps        # Of physical devices per second   I/O   Total transmission 
rtps       # The total amount of data read from the physical device per second 
wtps       # The total amount of data written to the physical device per second 
bread/s    # The amount of data read from the physical device per second, in   Block / S 
bwrtn/s    # The amount of data written to the physical device per second, in seconds   Block / S

View network status information

[[email protected] ~]# sar -n DEV
Linux 3.10.0-1127.18.2.el7.x86_64 (centos7)  03/28/2021  _x86_64_ (1 CPU)
11:10:02 AM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s
11:20:01 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
11:20:01 AM     ens33      0.83      0.54      0.06      0.05      0.00      0.00      0.00
11:30:01 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
11:30:01 AM     ens33      1.07      0.69      0.08      0.06      0.00      0.00      0.00
11:40:01 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
11:40:01 AM     ens33      0.91      0.60      0.07      0.05      0.00      0.00      0.00
Average:           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:        ens33      0.94      0.61      0.07      0.05      0.00      0.00 

Learn a Linux command every day (107): SAR