Detailed use of SAR in Linux

Source: Internet
Author: User
Tags cpu usage

In the process of using the UNIX operating system, we often use a variety of problems, such as the speed of the system is suddenly slow, the system is prone to panic or the terminal with the host often crashes, then we often guess, is the hard disk space is too small, or insufficient memory? I/O bottlenecks, or is there a problem with the core parameters of the system? At this point, we should consider using the system to provide us with the SAR command to understand the system, the command is an important tool for system maintenance, mainly to help us understand the use of system resources, especially memory and CPU usage, is a UNIX system users should master one of the tools.
Common formats for the SAR command line:

SAR [Options] [-A] [-o file] t [n]

In the command line, the N and t two parameters are combined to define the sampling interval and the number of times, T is the sampling interval, is a required parameter, n is the number of samples, is optional, the default value is 1,-o file means the command results in binary format in the file, where file is not the keyword, is the file name. Options is a command-line option, there are a number of choices for the SAR command, and only the common options are listed below:

-A: The sum of all reports.
-U:CPU Utilization
-V: Process, I node, file, and lock table state.
-D: Hard drive usage report.
-r: No memory pages and hard disk blocks used.
-G: Serial I/O condition.
-B: Buffer usage.
-A: File read and write.
-C: System call condition.
-R: The activity of the process.
-Y: Terminal equipment activity situation.
-W: System Exchange activity.

An example is shown below.

Example one: Using the command line Sar-u T n

For example, sampling every 60 seconds, sampling 5 times in a row, observing CPU usage, and storing the sampled results in binary form in the file Zhou in the current directory, type the following command:

# sar-u-O Zhou 60 5

Screen display:

SCO_SV scosysv 3.2v5.0.5 i80386 10/01/2001
14:43:50%usr%sys%wio%idle (-u)
14:44:50 0 1 4 94
14:45:50 0 2 4 93
14:46:50 0 2 2 96
14:47:50 0 2 5 93
14:48:50 0 2 2 96
Average 0 2 4 94

The contents of the display include:

%usr:cpu the percentage of time in user mode.
%sys:cpu the percentage of time in system mode.
%wio:cpu the percentage of time to wait for the input output to finish.
%IDLE:CPU idle time percentage.

In all the display, we should mainly note that the value of%wio and%idle,%wio is too high, indicating that there is an I/O bottleneck on the hard disk, the%idle value is high, the CPU is idle, if the%idle value is high but the system responds slowly, it is possible that the CPU waits to allocate memory.
You should increase your memory capacity at this time. If the%idle value continues below 10, the system's CPU processing power is relatively low, indicating that the most resource to be addressed in the system is the CPU.

If you want to view the contents of the binary file Zhou, you need to type the following SAR command:

# sar-u-F Zhou

As a result, SAR commands can be sampled in real time and the results of previous samples can be queried.

Example two: Using the life line SAR-V T n

For example, sampling every 30 seconds, sampling 5 times in a row, observing the status of the core table, you need to type the following command:

# SAR-V 30 5

Screen display:

SCO_SV scosysv 3.2v5.0.5 i80386 10/01/2001
10:33:23 proc-sz ov Inod-sz ov File-sz ov Lock-sz (-V)
10:33:53 305/321 0 1337/2764 0 1561/1706 0 40/128
10:34:23 308/321 0 1340/2764 0 1587/1706 0 37/128
10:34:53 305/321 0 1332/2764 0 1565/1706 0 36/128
10:35:23 308/321 0 1338/2764 0 1592/1706 0 37/128
10:35:53 308/321 0 1335/2764 0 1591/1706 0 37/128

Display content includes:

Proc-sz: The number of table entries in the process table currently being used or allocated in the core, controlled by the core parameter max-proc.

Inod-sz: The number of table entries in the I-node table currently being used or allocated in the core, controlled by the core parameter max-inode.

File-sz: The number of table entries in the file table currently being used or allocated in the core, controlled by the core parameter max-file.

OV: The number of times the overflow occurred.

Lock-sz: The number of table entries that are currently being used or allocated in the core are locked and controlled by the core parameters Max-flckre.

Display format is

Actual use of table entries/number of table entries that can be used

Display content representation, the core use is completely normal, three tables do not overflow phenomenon, the core parameters do not need to adjust, if overflow, to adjust the corresponding core parameters, the corresponding number of table items increased.

Example three: Using the life line sar-d T n

For example, sampling every 30 seconds, sampling 5 consecutive times, reporting device usage, you need to type the following command:

# sar-d 30 5

Screen display:

SCO_SV scosysv 3.2v5.0.5 i80386 10/01/2001
11:06:43 device%busy avque r+w/s blks/s avwait avserv (-D)
11:07:13 wd-0 1.47 2.75 4.67 14.73 5.50 3.14
11:07:43 wd-0 0.43 18.77 3.07 8.66 25.11 1.41
11:08:13 wd-0 0.77 2.78 2.77 7.26 4.94 2.77
11:08:43 wd-0 1.10 11.18 4.10 11.26 27.32 2.68
11:09:13 wd-0 1.97 21.78 5.86 34.06 69.66 3.35
Average wd-0 1.15 12.11 4.09 15.19 31.12 2.80

Display content includes:

The Device:sar command is monitoring the name of the block device.
%busy: The percentage of time that the transfer request takes up when the device is busy.
Avque: The average number of requests not completed when the queue is full.
R+W/S: The amount of data transmitted to or from the device per second.
BLKS/S: Number of blocks transmitted per second, 512 bytes per block.
Avwait: The average time that the transmit request waits for the queue to be idle when the queue is full.
Avserv: The average time (in milliseconds) required to complete the transfer request.

In the content displayed, wd-0 is the name of the hard disk, the value of%busy is small, indicating that the effective time for processing the transfer request is too small, the file system is not efficient, generally speaking, the%busy value is higher, the Avque value is lower, the file system efficiency is higher, if the%busy and Avque value is relatively high , which indicates that the drive speed is too slow to be adjusted.

Example four: Using the life line Sar-b T n

For example, sampling every 30 seconds, sampling 5 times in a row, reporting the use of the buffer, you need to type the following command:

# Sar-b 30 5

Screen display:

SCO_SV scosysv 3.2v5.0.5 i80386 10/01/2001
14:54:59 bread/s lread/s%rcache bwrit/s lwrit/s%wcache pread/s pwrit/s (-B)
14:55:29 0 147 100 5 21 78 0 0
14:55:59 0 186 100 5 25 79 0 0
14:56:29 4 232 98 8 58 86 0 0
14:56:59 0 125 100 5 23 76 0 0
14:57:29 0 89 100 4 12 66 0 0
Average 1 156 99 5 28 80 0 0

Display content includes:

BREAD/S: The number of physical blocks per second read from the hard disk into the system buffer.
LREAD/S: The average number of logical blocks read from the system buffer per second.
%rcache: The percentage of logical reads in the buffer cache.
BWRIT/S: The average number of physical blocks written to disk per second from the system buffer.
LWRIT/S: The average number of logical blocks per second written to the system buffer.
%wcache: The percentage of logical reads in the buffer cache.
PREAD/S: The average number of physical reads requested per second.
PWRIT/S: The average number of physical writes per second requested.

In the displayed content, the most important is the%cache and%wcache two columns, their values reflect the efficiency of the use of buffer, the value of%rcache less than 90 or the value of%wcache is less than 65, should increase the number of system buffer appropriately, Buffer number by the core parameter Nbuf control, so that the%rcache reached about 90,%wcache reached about 80. But the buffer parameter value of how much affect I/O efficiency, increase buffer, should be in the case of large memory, otherwise the system efficiency is not improved.

Example five: using SAR-G t n

For example, sampling every 30 seconds, continuously sampling 5 times, reporting the operation of serial I/O, you need to type the following command:

# SAR-G 30 5

Screen display:

SCO_SV scosysv 3.2v5.0.5 i80386 11/22/2001
17:07:03 ovsiohw/s ovsiodma/s ovclist/s (-G)
17:07:33 0.00 0.00 0.00
17:08:03 0.00 0.00 0.00
17:08:33 0.00 0.00 0.00
17:09:03 0.00 0.00 0.00
17:09:33 0.00 0.00 0.00
Average 0.00 0.00 0.00

Display content includes:

OVSIOHW/S: Overflow in serial I/O hardware per second.

OVSIODMA/S: Overflow in the direct input/output channel cache per second for serial I/O.

OVCLIST/S: The overflow of character queues per second.

In the displayed content, the value of each column is zero, indicating that no serial I/O overflow occurred in the system during the sampling time.

There are many uses of the SAR command, sometimes judging a problem, it takes several SAR commands to combine, for example, suspected CPU bottlenecks, available sar-u and sar-q, suspected I/O bottlenecks, can be seen in Sar-b, Sar-u and sar-d.

Detailed use of SAR in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.