Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of sar Command in Linux system

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "the usage of sar command in Linux system". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Command format

Sar (option) (parameter)

2. Option parameters

-A: show all report information

-b: displays the Istroke O rate

-B: display page change status

-c: show process creation activity

-d: displays the status of each block device

-e: sets the end time of the display report

-f: extract the report from the specified file

-I: sets the interval between status information refresh

-P: report the status of each CPU

-R: display memory statu

-u: show CPU utilization

-v: displays the status of inodes, files, and other kernel tables

-w: displays the status of the swap partition

-x: displays the status of a given process.

3. Use examples

Example 1: CPU resource monitoring

Sample every 5 seconds, sample twice in succession, observe the use of CPU, and store the sampling results in the file cpu.bin in the current directory in binary form.

[root@wjq] # sar-u 52-o cpu.bin

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:23:55 AM CPU user nice system iowait steal idle

11:24:00 AM all 0.61 0.00 0.61 0.00 0.00 98.78

11:24:05 AM all 0.41 0.00 0.41 0.20 0.00 98.98

Average: all 0.51 0.00 0.51 0.10 0.00 98.88

[root@ wjq ~] # ll cpu.bin

-rw-r--r-- 1 root root 27556 Oct 30 11:24 cpu.bin

To view the contents of the binary file cpu.bin, use the following command

[root@wjq] # sar-u-f cpu.bin

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:23:55 AM CPU user nice system iowait steal idle

11:24:00 AM all 0.61 0.00 0.61 0.00 0.00 98.78

11:24:05 AM all 0.41 0.00 0.41 0.20 0.00 98.98

Average: all 0.51 0.00 0.51 0.10 0.00 98.88

Description:

CPU:all indicates that the statistics are the average of all CPU.

% user: displays the percentage of total time spent using CPU running at the user level (application).

% nice: the percentage of total CPU time spent on nice operations displayed at the user level.

% system: the percentage of total time spent running CPU at the core level (kernel).

% iowait: displays the percentage of total CPU time spent waiting for the IUnip O operation.

% steal: the percentage that the hypervisor (hypervisor) waits for the virtual CPU while serving another virtual process.

% idle: displays the percentage of total CPU time occupied by CPU idle time.

Note:

1. If the value of% iowait is too high, it indicates that there is a bottleneck in the hard disk.

two。 If the value of% idle is high but the system response is slow, it is possible that CPU is waiting to allocate memory. At this time, the memory capacity should be increased.

3. If the value of% idle is consistently lower than 1, the CPU processing capacity of the system is relatively low, indicating that the resource that needs to be solved most in the system is CPU.

Example 2: inode, file and other kernel table monitoring

Sampling every 10 seconds, sampling 3 times in a row to observe the state of the core table

[root@wjq bin] # sar-v 5 3

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:22:57 AM dentunusd file-nr inode-nr pty-nr

11:23:02 AM 66756 7424 63501 2

11:23:07 AM 66750 7232 63489 2

11:23:12 AM 66749 7200 63488 2

Average: 66752 7285 63493 2

Description:

Dentunusd: the number of unused entries in the directory cache

File-nr: number of file handles (file handle) used

Inode-nr: number of index node handles (inode handle) used

Pty-nr: number of pty used

Example 3: memory and swap space monitoring

Sampling every 5 seconds, sampling 3 times in a row, monitoring memory paging

[root@wjq bin] # sar-r 5 3

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:21:47 AM kbmemfree kbmemused memused kbbuffers kbcached kbcommit commit kbactive kbinact kbdirty

11:21:52 AM 653656 2415236 78.70 0 1632600 3353300 53.96 1216508 893016 0

11:21:57 AM 653656 2415236 78.70 0 1632600 3353300 53.96 1216516 893016 0

11:22:02 AM 659516 2409376 78.51 0 1632584 3338224 53.72 1211496 892996 0

Average: 655609 2413283 78.64 0 1632595 3348275 53.88 1214840 893009 0

Description:

Kbmemfree: this value is basically the same as the free value in the free command, so it does not include buffer and cache space.

Kbmemused: this value is basically the same as the used value in the free command, so it includes buffer and cache space.

% memused: this value is a percentage of kbmemused and total memory (excluding swap).

Kbbuffers and kbcached: these two values are buffer and cache in the free command.

Kbcommit: guarantee the memory needed by the current system, that is, the memory needed to ensure that it does not overflow (RAM+swap).

% commit: this value is a percentage of kbcommit to total memory (including swap).

Kbactive: amount of active memory (in kilobytes) (most recently used memory is not usually recovered unless absolutely necessary)

Kbinact: the amount of inactive memory (kilobytes of memory (the most recently used memory) is more eligible for other purposes.

Kbdirty: the amount of memory in KB waiting to be written to disk

Example 4: memory paging monitoring

Sample every 5 seconds, sampling 3 times in a row to check the use of memory paging

[root@wjq] # sar-B 5 3

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:35:00 AM pgpgin/s pgpgout/s fault/s majflt/s pgfree/s pgscank/s pgscand/s pgsteal/s vmeff

11:35:05 AM 1.64 18.85 93.44 0.00 352.05 0.00 0.00 0.00

11:35:10 AM 0.00 6.53 7.35 0.00 9.18 0.00 0.00 0.00

11:35:15 AM 0.00 13.65 4.48 0.00 7.94 0.00 0.00 0.00

Average: 0.54 13.00 34.99 0.00 122.67 0.00 0.00 0.00

Description:

Pgpgin/s: indicates the number of bytes per second from disk or SWAP to memory (KB)

Pgpgout/s: indicates the number of bytes per second from memory to disk or SWAP (KB)

Fault/s: the number of missing pages generated by the system per second, that is, the sum of primary and secondary missing pages (major + minor)

Majflt/s: the number of main missing pages generated per second.

Pgfree/s: the number of pages placed in the idle queue per second

Pgscank/s: number of pages scanned by kswapd per second

Pgscand/s: the number of pages directly scanned per second

Pgsteal/s: the number of pages cleared from cache per second to meet memory requirements

% vmeff: percentage of pages cleared per second (pgsteal) to total scanned pages (pgscank+pgscand)

Example 5: Icano and transfer rate monitoring

Sampling every 5 seconds, sampling 3 times in a row to report buffer usage

[root@wjq] # sar-b 5 3

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:38:16 AM tps rtps wtps bread/s bwrtn/s

11:38:21 AM 0.41 0.00 0.41 0.00 13.06

11:38:26 AM 0.82 0.00 0.82 0.00 26.23

11:38:31 AM 0.82 0.00 0.82 0.00 26.18

Average: 0.68 0.00 0.68 0.00 21.81

Description:

Tps: the total amount of Istroke O transmissions per second of physical devices

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 a physical device per second, in blocks per second

Bwrtn/s: the amount of data written to the physical device per second, in blocks per second

Example 6: process queue length and average load status monitoring

Sample every 5 seconds for 3 consecutive times to monitor the queue length and average load status of the process.

[root@wjq] # sar-Q 5 3

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:39:52 AM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked

11:39:57 AM 0 328 0.04 0.03 0.05 0

11:40:02 AM 0 328 0.04 0.03 0.05 0

11:40:07 AM 0 326 0.03 0.03 0.05 0

Average: 0 327 0.04 0.03 0.05 0

Description:

Runq-sz: length of the run queue (number of processes waiting to run)

Plist-sz: number of processes (processes) and threads (threads) in the process list

Ldavg-1: average system load in the last minute (System load average)

Ldavg-5: average system load over the past 5 minutes

Ldavg-15: average system load over the past 15 minutes

Blocked: the number of tasks currently blocked, waiting for I / O to complete

Example 7: system exchange activity information monitoring

Sampling every 5 seconds, sampling 3 times in a row, and the monitoring system exchanges activity information.

[root@wjq] # sar-W 5 3

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:43:17 AM pswpin/s pswpout/s

11:43:22 AM 0.00 0.00

11:43:27 AM 0.00 0.00

11:43:32 AM 0.00 0.00

Average: 0.00 0.00

Description:

Pswpin/s: the number of swap pages (swap page) swapped in by the system per second

Pswpout/s: the number of swap pages (swap page) swapped out by the system per second

Example 8: equipment usage monitoring

Sample every 5 seconds, sample 3 times in succession, and report the use of the equipment.

[root@wjq] # sar-d 5 3

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:44:43 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm util

11:44:48 AM dev11-0 0.00 0.00 0.00

11:44:48 AM dev8-0 0.82 0.00 26.18 32.00 0.00 0.00 0.00

11:44:48 AM dev253-0 0.82 0.00 26.18 32.00 0.00 0.00 0.00

11:44:48 AM dev253-1 0.00 0.00 0.00

11:44:48 AM dev253-2 0.00 0.00 0.00

11:44:48 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm util

11:44:53 AM dev11-0 0.00 0.00 0.00

11:44:53 AM dev8-0 0.81 0.00 26.07 32.00 0.00 0.50 0.50 0.04

11:44:53 AM dev253-0 0.81 0.00 26.07 32.00 0.00 0.50 0.50 0.04

11:44:53 AM dev253-1 0.00 0.00 0.00

11:44:53 AM dev253-2 0.00 0.00 0.00

11:44:53 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm util

11:44:58 AM dev11-0 0.00 0.00 0.00

11:44:58 AM dev8-0 0.41 0.00 13.03 32.00 0.00 0.50 0.50 0.02

11:44:58 AM dev253-0 0.41 0.00 13.03 32.00 0.00 0.50 0.50 0.02

11:44:58 AM dev253-1 0.00 0.00 0.00

11:44:58 AM dev253-2 0.00 0.00 0.00

Average: DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm% util

Average: dev11-0 0.00 0.00 0.00

Average: dev8-0 0.68 0.00 21.75 32.00 0.00 0.30 0.30 0.02

Average: dev253-0 0.68 0.00 21.75 32.00 0.00 0.30 0.30 0.02

Average: dev253-1 0.00 0.00 0.00

Average: dev253-2 0.00 0.00 0.00

[root@wjq] # sar-d 53-p

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

11:45:06 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm util

11:45:11 AM sr0 0.00 0.00 0.00

11:45:11 AM sda 0.81 0.00 26.07 32.00 0.00 0.50 0.50 0.04

11:45:11 AM cl-root 0.81 0.00 26.07 32.00 0.00 0.50 0.50 0.04

11:45:11 AM cl-swap 0.00 0.00 0.00

11:45:11 AM cl-home 0.00 0.00 0.00

11:45:11 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm util

11:45:16 AM sr0 0.00 0.00 0.00

11:45:16 AM sda 0.61 0.00 14.49 23.67 0.00 0.33 0.33 0.02

11:45:16 AM cl-root 0.61 0.00 14.49 23.67 0.00 0.33 0.33 0.02

11:45:16 AM cl-swap 0.00 0.00 0.00

11:45:16 AM cl-home 0.00 0.00 0.00

11:45:16 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm util

11:45:21 AM sr0 0.00 0.00 0.00

11:45:21 AM sda 0.81 0.00 26.02 32.00 0.00 0.25 0.25 0.02

11:45:21 AM cl-root 0.81 0.00 26.02 32.00 0.00 0.25 0.25 0.02

11:45:21 AM cl-swap 0.00 0.00 0.00

11:45:21 AM cl-home 0.00 0.00 0.00

Average: DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm% util

Average: sr0 0.00 0.00 0.00

Average: sda 0.75 0.00 22.20 29.73 0.00 0.36 0.36 0.03

Average: cl-root 0.75 0.00 22.20 29.73 0.00 0.36 0.36 0.03

Average: cl-swap 0.00 0.00 0.00

Average: cl-home 0.00 0.00 0.00

Description:

The parameter-p can print out the disk device names such as sda,hdc. If the parameter-p is not used, the device node may be dev8-0dev22-0.

Tps: the number of times per second from the physical disk. Multiple logical requests will be merged into a single disk request, and the size of a transfer is uncertain.

Rd_sec/s: the number of times sectors are read per second.

Wr_sec/s: the number of times sectors are written per second.

Avgrq-sz: the average data size (sector) of each device Istroke O operation.

Avgqu-sz: the average length of the disk request queue.

Await: the average elapsed time of each request, including the waiting time of the request queue, from the request disk operation to the completion of the system processing, in milliseconds (1 second = 1000 milliseconds).

Svctm: the average time the system processes each request, excluding the time spent in the request queue.

% util:I/O requests as a percentage of CPU, the higher the ratio, the more saturated it is.

Note:

1. When the value of avgqu-sz is low, the utilization of the device is higher.

two。 When the value of% util is close to 1%, the device bandwidth is full.

Example 9: statistics for network interfaces

Sample every 5 seconds, sample 3 times in succession, and report the use of the equipment.

[root@wjq] # sar 5 3-n DEV

Linux 3.10.0-514.el7.x86_64 (wjq.comsys.com) 10Accord 30 Universe 2017 _ x86 inch 641 CPU)

12:07:51 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s

12:07:56 PM lo 0.82 0.82 0.05 0.05 0.00 0.00 0.00

12:07:56 PM virbr0-nic 0.00 0.00 0.00

12:07:56 PM virbr0 0.00 0.00 0.00

12:07:56 PM ens160 0.41 0.20 0.06 0.04 0.00 0.00 0.00

12:07:56 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s

12:08:01 PM lo 0.82 0.82 0.05 0.05 0.00 0.00 0.00

12:08:01 PM virbr0-nic 0.00 0.00 0.00

12:08:01 PM virbr0 0.00 0.00 0.00

12:08:01 PM ens160 7.17 0.20 0.63 0.12 0.00 0.00 0.00

12:08:01 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s

12:08:06 PM lo 1.43 1.43 0.26 0.26 0.00 0.00 0.00

12:08:06 PM virbr0-nic 0.00 0.00 0.00

12:08:06 PM virbr0 0.00 0.00 0.00

12:08:06 PM ens160 0.82 0.20 0.07 0.12 0.00 0.00 0.00

Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s

Average: lo 1.02 1.02 0.12 0.12 0.00 0.00 0.00

Average: virbr0-nic 0.00 0.00 0.00

Average: virbr0 0.00 0.00 0.00

Average: ens160 2.79 0.20 0.25 0.10 0.00 0.00 0.00

Description:

Possible keywords are DEV, EDEV, NFS, NFSD, SOCK, IP, EIP, ICMP, EICMP, TCP, ETCP, UDP, SOCK6, IP6,EIP6, ICMP6, EICMP6 and UDP6

IFACE: name of the network interface on which statistics are reported

Rxpck/s: total number of packets received per second

Txpck/s: the total number of messages transmitted per second

RxkB/s: total kilobytes received per second

TxkB/s: total kilobytes transmitted per second

Rxcmp/s: number of compressed packets received per second

Txcmp/s: number of compressed packets transmitted per second

Rxmcst/s: number of multicast packets received per second

4. Operation and maintenance expansion:

To determine the bottleneck of the system, it sometimes requires a combination of several sar command options

(1) it is suspected that there is a bottleneck in CPU. You can check it with sar-u and sar-Q.

(2) memory bottleneck is suspected, which can be checked by sar-B, sar-r and sar-W

(3) it is suspected that there is a bottleneck in iAccord O, which can be checked by sar-b, sar-u and sar-d.

This is the end of the introduction to the usage of the sar command in the Linux system. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report