[Linux] Introduction to common options of sar

sar use

install sysstat

apt-get install sysstat -y
#或
yum install sysstat -y

options

Usage: sar [options] [ <time interval> [ <number of times>] ]
Options:
[ -A ] [ -B ] [ -b ] [ -C ] [ -D ] [ -d ] [ -F [ MOUNT ] ] [ -H ] [ -h ]
[ -p ] [ -q ] [ -r [ ALL ] ] [ -S ] [ -t ] [ -u [ ALL ] ] [ -V ] [ -v ] [
-W ] [ -w ] [ -y ] [ -z ]
[ -I { <interrupt list> | SUM | ALL } ] [ -P { <cpu_list> | ALL } ] [
-m { <keyword> [,… ] | ALL } ] [ -n { <keyword> [,…] | ALL } ]
[ --dev=<list of devices> ] [ --fs=<list of filesystems> ] [ --iface=<iface_ list> ]
[ --dec={ 0 | 1 | 2 } ] [ --help ] [ --human ] [ --sadc ]
[ -j { ID | LABEL | PATH | UUID | ... } ]
[ -f [ <filename> ] | -o [ <filename> ] | -[0-9]+ ]
[ -i <time interval> ] [ -s [ <hour:minute[:second]> ] ] [ -e [ <hour:minute[:second]> ] ]

$ sar --help
用法: sar [ 选项 ] [ <时间间隔> [ <次数> ] ]
主要选项和报告(报告名以方括号分隔):
        -B      分页状况 [A_PAGE]
        -b      I/O 和传输速率信息状况 [A_IO]
        -d      块设备状况 [A_DISK]
        -F [ MOUNT ]
                文件系统统计信息 [A_FS]
        -H      巨大页面利用率 [A_HUGE]
        -I {
    
     <中断列表> | SUM | ALL }
                中断信息状况 [A_IRQ]
        -m {
    
     <关键字> [,...] | ALL }
                电源管理统计信息 [A_PWR_...]
                关键字:
                CPU     CPU 瞬时时钟频率
                FAN     风扇速度
\t\tFREQ\tCPU 平均时钟频率
                IN      输入电压
                TEMP    设备温度
\t\tUSB\t连接的 USB 设备
        -n {
    
     <关键字> [,...] | ALL }
                网络统计信息 [A_NET_...]
                关键字:
                DEV     网络接口
                EDEV    网络接口(错误)
                NFS     NFS 客户端
                NFSD    NFS 服务端
                SOCK    Sockets (v4)
                IP      IP 流   (v4)
                EIP     IP 流   (v4)(错误)
                ICMP    ICMP 流 (v4)
                EICMP   ICMP 流 (v4)(错误)
                TCP     TCP 流  (v4)
                ETCP    TCP 流  (v4) (错误)
                UDP     UDP 流  (v4)
                SOCK6   Sockets (v6)
                IP6     IP 流   (v6)
                EIP6    IP 流   (v6)(错误)
                ICMP6   ICMP 流 (v6)
                EICMP6  ICMP 流 (v6) (错误)
                UDP6    UDP 流  (v6)
                FC      Fibre channel HBAs
                SOFT    基于软件的网络处理

        -q      队列长度和平均负载统计信息 [A_QUEUE]
        -r [ ALL ]
                内存利用率信息 [A_MEMORY]
        -S      交换空间利用率信息 [A_MEMORY]
        -u [ ALL ]
                CPU 利用率信息 [A_CPU]
        -v      内核表统计信息 [A_KTABLES]
        -W      交换信息 [A_SWAP]
        -w      任务创建与系统切换信息 [A_PCSW]
        -y      TTY 设备信息 [A_SERIAL]

-A: sum of all reports

-b: Display I/O and transfer rate statistics

-B: display page change status

-d: output the usage information of each disk

-e: Set the end time for displaying the report

-f: read the report from the specified file

-i: Set the interval for status information refresh

-P: report the status of each CPU

-R: display memory status

–u: output cpu usage and statistics

–v: Display status of inodes, files and other kernel tables

-w: display the status of the swap partition

-x: Display the installation of a given process

-r: Report memory utilization statistics

cpu usage sar -u
$ sar 1 3 
#或
$ sar -u 1 3

$ sar 1 3
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时36分59秒     CPU     %user     %nice   %system   %iowait    %steal     %idle
11时37分00秒     all      0.38      0.00      0.19      0.00      0.00     99.44
11时37分01秒     all      0.50      0.00      0.44      0.00      0.00     99.06
11时37分02秒     all      0.38      0.00      0.19      0.00      0.00     99.44
平均时间:     all      0.42      0.00      0.27      0.00      0.00     99.31

%user CPU usage in user space

%nice CPU usage of processes whose priority has been changed

CPU usage of %system kernel space

%iowait The percentage of CPU waiting for IO

The CPU used by the virtual machine CPU of the %steal virtual machine

%idle idle CPU

In the above display, mainly look at %iowait and %idle. If %iowait is too high, it means that there is an I/O bottleneck, that is, disk IO cannot meet business needs. If %idle is too low, it means that the CPU usage is serious, and it needs to be combined with memory usage, etc. The situation determines whether the CPU is a bottleneck.

Save the file, and read the file sar -o | sar -f
sar -o filename 1 3  ## 保存 
sar -f filename   ## 查看
sar -f filename -r ALL  ## 查看内存状态 
sar -f filename -u ALL  ## 查看cpu状态
View load average sar -q
$sar -q 1 3 
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时41分00秒   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15   blocked
11时41分01秒         0      1886      0.16      0.43      0.54         0
11时41分02秒         0      1886      0.15      0.42      0.53         0
11时41分03秒         0      1886      0.15      0.42      0.53         0
平均时间:         0      1886      0.15      0.42      0.53         0

runq-sz The length of the running queue (the number of processes waiting to run, the CP of each core cannot exceed 3)

The number of processes and threads in the plist-sz process list

ldavg-1 The average CPU load in the last minute, which is the average value obtained by adding the load of the multi-core CPU in the past minute and dividing it by the number of cores, and so on for 5 minutes and 15 minutes

ldavg-5 CPU load average for the last 5 minutes

ldavg-15 CPU load average for the last 15 minutes

blocked

memory usage sar -r
$ sar -r 1 3 
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时43分18秒 kbmemfree   kbavail kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
11时43分19秒    364224  10025276   5702624     34.94   2242692   7342612  24669220     74.54   5592872   9422092       532                                                                                                  
11时43分20秒    365112  10026208   5701544     34.94   2242692   7342860  24669220     74.54   5592872   9421532       636                                                                                                  
11时43分21秒    365576  10026672   5701080     34.93   2242692   7342860  24669220     74.54   5592872   9421824       672                                                                                                  
平均时间:    364971  10026052   5701749     34.94   2242692   7342777  24669220     74.54   5592872   9421816       613    

kbmemfree free physical memory size

kbmemused physical memory size in use

%memused physical memory usage

kbbuffers The physical memory size used as a buffer in the kernel, kbbuffers and kbcached: these two values ​​​​are the buffer and cache in the free command.

The file size of the kbcached cache

kbcommit guarantees the minimum memory required for the normal operation of the current system, that is, the minimum memory required to ensure that the memory does not overflow (physical memory + Swap partition)

commit This value is a percentage value of kbcommit and the total amount of memory (physical memory + swap partition)

kbactive

kbinact

kbdirty

View swap partition statistics sar -W
$ sar -W 1 3 
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时44分31秒  pswpin/s pswpout/s
11时44分32秒      0.00      0.00
11时44分33秒      0.00      0.00
11时44分34秒      0.00      0.00
平均时间:      0.00      0.00

pswpin/s The number of swap pages (swap pages) from the swap partition to the system per second

pswpott/s The number of swap pages (swap pages) swapped from the system to swap per second

View IO and transfer rate sar -b
$ sar -b 1 3 
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时45分44秒       tps      rtps      wtps   bread/s   bwrtn/s
11时45分45秒      0.00      0.00      0.00      0.00      0.00
11时45分46秒      0.00      0.00      0.00      0.00      0.00
11时45分47秒      0.00      0.00      0.00      0.00      0.00
平均时间:      0.00      0.00      0.00      0.00      0.00

Tps The total number of IOs per second of the disk, equal to tps in iostat

rtps The total number of IOs read from disk per second

wtps The total number of IOs written to disk per second

bread/s total number of blocks read from disk per second

bwrtn/s total number of blocks written to disk per second

View disk usage sar -d
$ sar -d 1 3 
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时48分17秒       DEV       tps     rkB/s     wkB/s   areq-sz    aqu-sz     await     svctm     %util
11时48分18秒  dev259-0     14.00      0.00     96.00      6.86      0.00      0.07      0.57      0.80
11时48分18秒    dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

11时48分18秒       DEV       tps     rkB/s     wkB/s   areq-sz    aqu-sz     await     svctm     %util
11时48分19秒  dev259-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
11时48分19秒    dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

11时48分19秒       DEV       tps     rkB/s     wkB/s   areq-sz    aqu-sz     await     svctm     %util
11时48分20秒  dev259-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
11时48分20秒    dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

平均时间:       DEV       tps     rkB/s     wkB/s   areq-sz    aqu-sz     await     svctm     %util
平均时间:  dev259-0      4.67      0.00     32.00      6.86      0.00      0.07      0.57      0.27
平均时间:    dev8-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

DEV The name of the disk device, if you do not add -p, it will display a device name similar to dev253-0, so the name displayed with -p is more direct

tps The total number of I/O transfers per second

rd_sec/s total number of sectors read per second

wr_sec/s Total number of sectors written per second

avgrq-sz Average data size (sectors) of each disk I/O operation

avgqu-sz The average length of the disk request queue

await The average consumption time of each request from requesting disk operation to system completion processing, including request queue waiting time, in milliseconds (1 second equals 1000 milliseconds), equal to seek time + queue time + service time

The service processing time of svctm I/O, that is, the time in the request queue is not included

%util CPU percentage occupied by I/O requests, the higher the value, the slower the I/O

Statistical network information sar -n

-n { <keywords> [,…] | ALL }
Keywords can be :
DEV network card
EDEV network card (error)
NFS NFS client
NFSD NFS server
SOCK Sockets (v4)
IP IP stream (v4)
EIP IP Stream (v4) (Error)
ICMP ICMP Stream (v4)
EICMP ICMP Stream (v4) (Error)
TCP TCP Stream (v4)
ETCP TCP Stream (v4) (Error)
UDP UDP Stream (v4)
SOCK6 Sockets (Sockets ) (v6)
IP6 IP Flow (v6)
EIP6 IP Flow (v6) (Error)
ICMP6 ICMP Flow (v6)
EICMP6 ICMP Flow (v6) (Error)
UDP6 UDP Flow (v6)

Network interface information sar -n DEV
$ sar -n DEV 1 3
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时49分59秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
11时50分00秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
11时50分00秒    enp5s0     22.00     14.00      6.22      1.81      0.00      0.00      3.00      0.01
11时50分00秒  macvtap0      4.00      0.00      0.23      0.00      0.00      0.00      4.00      0.00

11时50分00秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
11时50分01秒        lo      7.00      7.00      2.18      2.18      0.00      0.00      0.00      0.00
11时50分01秒    enp5s0     15.00     13.00      5.35      4.44      0.00      0.00      2.00      0.00
11时50分01秒  macvtap0      4.00      1.00      0.23      0.06      0.00      0.00      4.00      0.00

11时50分01秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
11时50分02秒        lo      2.00      2.00      0.31      0.31      0.00      0.00      0.00      0.00
11时50分02秒    enp5s0      8.00      4.00      0.82      0.53      0.00      0.00      1.00      0.00
11时50分02秒  macvtap0      3.00      1.00      0.18      0.33      0.00      0.00      3.00      0.00

平均时间:     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
平均时间:        lo      3.00      3.00      0.83      0.83      0.00      0.00      0.00      0.00
平均时间:    enp5s0     15.00     10.33      4.13      2.26      0.00      0.00      2.00      0.00
平均时间:  macvtap0      3.67      0.67      0.21      0.13      0.00      0.00      3.67      0.00

IFACE The name of the local NIC interface

rxpck/s packets received per second

txpck/s database sent per second

rxKB/S The size of data packets accepted per second, in KB

txKB/S The size of data packets sent per second, in KB

rxcmp/s compressed packets received per second

txcmp/s compressed packets sent per second

rxmcst/s Multicast packets received per second

Network device unified trust failure information sar -n EDEV
sar -n EDEV 1 3
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时50分53秒     IFACE   rxerr/s   txerr/s    coll/s  rxdrop/s  txdrop/s  txcarr/s  rxfram/s  rxfifo/s  txfifo/s
11时50分54秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00                                                                                                            
11时50分54秒    enp5s0      0.00      0.00      0.00      3.00      0.00      0.00      0.00      0.00      0.00                                                                                                            
11时50分54秒  macvtap0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00                                                                                                            

11时50分54秒     IFACE   rxerr/s   txerr/s    coll/s  rxdrop/s  txdrop/s  txcarr/s  rxfram/s  rxfifo/s  txfifo/s
11时50分55秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00                                                                                                            
11时50分55秒    enp5s0      0.00      0.00      0.00      1.00      0.00      0.00      0.00      0.00      0.00                                                                                                            
11时50分55秒  macvtap0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00                                                                                                            

11时50分55秒     IFACE   rxerr/s   txerr/s    coll/s  rxdrop/s  txdrop/s  txcarr/s  rxfram/s  rxfifo/s  txfifo/s
11时50分56秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00                                                                                                            
11时50分56秒    enp5s0      0.00      0.00      0.00      1.00      0.00      0.00      0.00      0.00      0.00                                                                                                            
11时50分56秒  macvtap0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00                                                                                                            

平均时间:     IFACE   rxerr/s   txerr/s    coll/s  rxdrop/s  txdrop/s  txcarr/s  rxfram/s  rxfifo/s  txfifo/s
平均时间:        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
平均时间:    enp5s0      0.00      0.00      0.00      1.67      0.00      0.00      0.00      0.00      0.00
平均时间:  macvtap0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

IFACE network card name

rxerr/s Corrupted packets received per second

txerr/s Number of packet errors sent per second

coll/s When sending data packets, the number of collisions (collisions) per second, this is only available in half-duplex mode

rxdrop/s When the buffer is full, the number of network packets dropped by the receiving end of the network card device per second

txdrop/s The number of network packets dropped by the sender of the network device per second when the buffer is full

txcarr/s The number of carrier errors per second when sending packets

rxfram/s When receiving data packets, the number of frame alignment errors that occur per second

rxfifo/s When receiving packets, the number of buffer overflow errors per second

txfifo/s When a packet occurs, the number of buffer overflow errors per second

Statistics socket link information sar -n SOCK
$ sar -n SOCK 1 3
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时51分56秒    totsck    tcpsck    udpsck    rawsck   ip-frag    tcp-tw
11时51分57秒      1598        15         3         0         0        13
11时51分58秒      1598        15         3         0         0        13
11时51分59秒      1598        15         3         0         0        13
平均时间:      1598        15         3         0         0        13

totsck total number of sockets currently in use

tcpsck total number of TCP sockets currently being used

udpsck The total number of UDP sockets currently being used

rawsck Total number of skckets currently being used for RAW

if-frag The current number of IP fragments

tcp-tw The number of connections in the TIME-WAIT state in the TCP socket

Statistics of TCP connections sar -n TCP
$ sar -n TCP 1 3
Linux 5.10.0-amd64-desktop (uos-PC)     2022年07月26日  _x86_64_        (16 CPU)

11时52分44秒  active/s passive/s    iseg/s    oseg/s
11时52分45秒      0.00      0.00      0.00      0.00
11时52分46秒      0.00      0.00      0.00      0.00
11时52分47秒      0.00      0.00      3.00      3.00
平均时间:      0.00      0.00      1.00      1.00

active/s new active connection

passive/s new passive connection

Segments accepted by iseg/s

Segments of oseg/s output

Use summary

Default monitoring: sar 1 1 # CPU and IOWAIT statistics status

  • sar -b 1 1 # IO transfer rate

  • sar -B 1 1 # page exchange rate

  • sar -c 1 1 # process creation rate

  • sar -d 1 1 # Active information of block devices

  • sar -n DEV 1 1 # Status information of network devices

  • sar -n SOCK 1 1 # Usage of SOCK

  • sar -n ALL 1 1 # All network status information

  • sar -P ALL 1 1 # The usage status information and IOWAIT statistics status of each CPU

  • sar -q 1 1 # length of queue (number of processes waiting to run) and status of load

  • sar -r 1 1 # memory and swap space usage

  • sar -R 1 1 # Memory statistics (allocation and release of memory pages, memory pages used by the system as BUFFER per second, memory pages cached per second)

  • sar -u 1 1 # CPU usage and IOWAIT information (same as default monitoring)

  • sar -v 1 1 # Status information of inode, file and other kernel tablesd

  • sar -w 1 1 # number of context switches per second

  • sar -W 1 1 # SWAP exchange statistics (monitoring status is the same as iostat's si so)

  • sar -x 2906 1 1 # Display the statistical information of the specified process (2906), including: errors caused by the process, user-level and system-level user CPU usage, and which CPU it is running on

  • sar -y 1 1 # Active state of TTY device

  • will output to file (-o) and read record information (-f)

Guess you like

Origin blog.csdn.net/imliuqun123/article/details/130149834