


Detailed explanation of Linux sar command and analysis of system performance case
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.
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!

This guide explains how to automatically mount a USB drive on boot in Linux, saving you time and effort. Step 1: Identify Your USB Drive Use the lsblk command to list all block devices. Your USB drive will likely be labeled /dev/sdb1, /dev/sdc1, etc

Cross-platform applications have revolutionized software development, enabling seamless functionality across operating systems like Linux, Windows, and macOS. This eliminates the need to switch apps based on your device, offering consistent experien

Artificial Intelligence (AI) is rapidly transforming numerous sectors, from healthcare and finance to creative fields like art and music. Linux, with its open-source nature, adaptability, and performance capabilities, has emerged as a premier platfo

Looking for a fast, minimal, and efficient Linux distribution without a graphical user interface (GUI)? Lightweight, GUI-less Linux distros are perfect for older hardware or specialized tasks like servers and embedded systems. They consume fewer res

Wine 10.0 stable version release: Running Windows applications on Linux to a higher level Wine, this open source and free application, allows Linux users to run Windows software and games on Unix/Linux operating systems, ushering in the release of the 10.0 stable version! This version has been provided with source code and binary package downloads, and supports various distributions such as Linux, Windows and Mac. This edition embodies a year of hard work and over 8,600 improvements, bringing many exciting improvements. Key highlights include: Enhanced support for Bluetooth devices. Improve support for HID input devices. Optimized performance of 32-bit and 64-bit applications.

This tutorial guides you through installing SQL Server 2022 on RHEL 8.x or 9.x, connecting via the sqlcmd command-line tool, database creation, and basic querying. Prerequisites Before beginning, ensure: A supported RHEL version (RHEL 8 or 9). Sudo

Mozilla Thunderbird 135: Powerful cross-platform mail client Mozilla Thunderbird is a free, open source, cross-platform email, calendar, news, chat and contact management client designed to efficiently handle multiple email accounts and news sources. On February 5, 2025, Mozilla released the Thunderbird 135 version, introducing a number of new features, performance improvements and security fixes. Thunderbird 135 main features: XZ Packaging for Linux Binaries: Smaller files, faster unpacking, and better integration with modern distributions. Cookie storage support: when creating space

This guide demonstrates how to protect files on Linux from accidental renaming or deletion using simple commands. We'll use the file important.txt in /home/user/ as an example. Method 1: Using chattr for Immutability The chattr command modifies fil


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools
