Home  >  Article  >  System Tutorial  >  Detailed explanation of Linux sar command and analysis of system performance case

Detailed explanation of Linux sar command and analysis of system performance case

WBOY
WBOYforward
2024-01-12 12:24:16835browse

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:

  • -o filename: where filename is the file name, this option means to store the command results in a file in binary format;
  • interval: Indicates the sampling interval, this parameter must be set manually;
  • count: indicates the number of sampling times, is an optional parameter, and its default value is 1;
  • options: These are command line options. Since the sar command provides many options, we will not introduce them one by one here. We only list some commonly used options and corresponding functions, as shown in Table 1.

Table 1 sar command line options and functions
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:

  • %user: used to indicate the proportion of CPU time consumed in user mode;
  • %nice: The proportion of CPU time consumed in user mode by processes whose process scheduling priority has been changed through nice;
  • %system: Proportion of CPU time consumed in system mode;
  • %iowait: The proportion of time spent in idle state caused by CPU waiting for disk I/O;
  • %steal: Use operating system virtualization technology such as Xen to wait for the proportion of time occupied by other virtual CPU calculations;
  • %idle: CPU idle time ratio.

【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:

  • tps: The number of I/Os from the physical disk per second. Note that multiple logical requests will be merged into one I/O disk request, and the size of a transfer is uncertain;
  • rd_sec/s: Number of sectors read per second;
  • wr_sec/s: Number of sectors written per second;
  • avgrq-sz: Average data size (sectors) per device 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, unit is milliseconds (1 second = 1000 milliseconds);
  • svctm: The average time the system takes to process each request, excluding the time spent in the request queue;
  • %util: I/O requests account for the percentage of CPU. The larger the ratio, the more saturated it is.

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!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete