The sar command is very powerful and is one of the important tools for analyzing system performance. Through this command, you can comprehensively obtain the system's CPU, run queue, disk read and write (I/O), partition (swap area), memory, CPU Interrupt and network performance data.
The basic format of the sar command is as follows:
[root@localhost ~]# sar [options] [-o filename] interval [count]
In this command format, the meaning of each parameter is as follows:
sar command options | Function |
---|---|
-A | Display the running status of all resource devices (CPU, memory, disk) in the system. |
-u | Display the load status of all CPUs in the system during the sampling time. |
-P | Display the usage of the specified CPU in the current system. |
-d | Display the usage status of all hard disk devices in the system during the sampling time. |
-r | Display the usage of system memory during the sampling time. |
-b | Display the buffer usage during the sampling time. |
-v | Display statistics for inode nodes, files, and other kernel tables. |
-n | Display network operating status, this option can be followed by DEV (display network interface information), EDEV (display network error statistics), SOCK (display socket information) and FULL (equivalent to using DEV, EDEV and SOCK ), etc. For more options, you can view them by executing the man sar command. |
-q | Display the number of processes in the running list, process size, system load average, etc. |
-R | Display the activity of the process during sampling. |
-y | Display the activities of the terminal device during the sampling time. |
-w | Display the status of system exchange activity during the sampling time. |
For more available options and functions of the sar command, you can view it by executing the man sar command.
【example 1】
If you want to check the system CPU load status, which is calculated every 3 seconds and 5 times, you can execute the following command:
[root@localhost ~]# sar -u 3 5 Linux 2.6.32-431.el6.x86_64 (localhost) 10/25/2019 _x86_64_(1 CPU) 06:18:23 AM CPU %user %nice %system %iowait%steal %idle 06:18:26 AM all 12.110.002.773.110.00 82.01 06:18:29 AM all6.550.002.070.000.00 91.38 06:18:32 AM all6.600.002.080.000.00 91.32 06:18:35 AM all 10.210.001.760.000.00 88.03 06:18:38 AM all8.710.001.740.000.00 89.55 Average:all8.830.002.090.630.00 88.46
In this output result, the meanings of each list item are as follows:
【Example 2】
If you want to check the read and write performance of the system disk, you can execute the following command:
[root@localhost ~]# sar -d 3 5 Linux 2.6.32-431.el6.x86_64 (localhost) 10/25/2019 _x86_64_(1 CPU) 06:36:52 AM DEV tpsrd_sec/swr_sec/savgrq-szavgqu-sz await svctm %util 06:36:55 AMdev8-03.380.00502.26148.440.08 24.114.561.54 06:36:55 AM DEV tpsrd_sec/swr_sec/savgrq-szavgqu-sz await svctm %util 06:36:58 AMdev8-01.490.00 29.85 20.000.001.750.750.11 06:36:58 AM DEV tpsrd_sec/swr_sec/savgrq-szavgqu-sz await svctm %util 06:37:01 AMdev8-0 68.266.9653982.61790.933.22 47.233.54 24.17 06:37:01 AM DEV tpsrd_sec/swr_sec/savgrq-szavgqu-sz await svctm %util 06:37:04 AMdev8-0111.69 3961.29154.84 36.851.059.423.44 38.43 06:37:04 AM DEV tpsrd_sec/swr_sec/savgrq-szavgqu-sz await svctm %util 06:37:07 AMdev8-01.67136.002.67 83.200.016.206.001.00 Average:DEV tpsrd_sec/swr_sec/savgrq-szavgqu-sz await svctm %util Average: dev8-0 34.45781.10 9601.22301.360.78 22.743.50 12.07
In this output result, the meaning of each list header is as follows:
In addition, if you want to check the system memory usage, you can execute the sar -r 5 3 command; if you want to check the network running status, you can execute the sar -n DEV 5 3 command, etc. Regarding the usage of other parameters, specific examples will not be given here. Interested readers can test it by themselves and observe the running results.
The above is the detailed content of Detailed explanation of Linux sar command and analysis of system performance case. For more information, please follow other related articles on the PHP Chinese website!