How to use SAR in UNIX Maintenance

Source: Internet
Author: User
Tags disk usage
How to use SAR in UNIX Maintenance
Http://www.douzhe.com Author: mzd73 published on: 20:57:35
System Maintenance using SAR commands in UNIX

In the process of using a UNIX operating system, we often use a variety of problems, such as the system running speed
Suddenly slow down, the system is prone to crashes, or the terminal of the host Often crashes. At this time, we often guess that it is hard
Is the disk space too small or is the memory insufficient? Is there a bottleneck in I/O, or is there a problem with the system's core parameters? At this time,
We should consider using the sar command provided by the system to understand the system. This command is system maintenance.
Is an important tool to help us understand the usage of system resources, especially the memory and CPU usage,
It is one of the tools that Unix users should master.
Common formats of SAR command lines:

SAR [Options] [-A] [-o file] T [N]

In the command line, the N and T parameters are combined to define the sampling interval and number of times. t indicates the sampling interval, which must be
N is the number of samples and is optional. The default value is 1.-o file indicates that the command result is in binary format.
Stored in a file. The file is not a keyword but a file name. Options is the command line option, sar command
There are many options, and only common options are listed below:

-A: total of all reports.
-U: CPU usage
-V: process, I node, file, and lock table status.
-D: hard disk usage report.
-R: Memory pages and hard disk blocks that are not in use.
-G: serial port I/O.
-B: Buffer usage.
-A: file read/write status.
-C: System Call status.
-R: Process activity.
-Y: terminal device activity.
-W: system exchange activity.

The following is an example.

Example 1: Use the command line Sar-U T N

For example, sampling is performed once every 60 seconds. sampling is performed five times in a row to observe CPU usage. The sampling result is binary.
To store the file Zhou in the current directory, enter 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 displayed content includes:

% USR: Percentage of CPU time in user mode.
% SYS: Percentage of CPU time in system mode.
% WIO: Percentage of CPU waiting for input/output completion time.
% Idle: Percentage of idle CPU time.

In all the displays, we should pay attention to % WIO and % idle. The value of % WIO is too high, indicating that the hard disk has an I/O bottleneck,
The % idle value is high, indicating that the CPU is idle. If the % idle value is high but the system response is slow, the CPU may wait for memory allocation,
In this case, the memory capacity should be increased. % If the idle value is lower than 10, the CPU processing capability of the system is relatively low.
The most important resource in the system is the CPU.

To view the content in the binary file Zhou, type the following sar command:

# Sar-u-F Zhou

It can be seen that the sar command can sample data in real time and query the previous sampling results.

Example 2: Use alive Sar-V T N

For example, if you sample data every 30 seconds for five consecutive times and observe the status of the core table, enter 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

The displayed content includes:

Proc-SZ: Number of table items in the table currently being used or allocated in the core, controlled by the core parameter MAX-PROC.

Inod-SZ: the number of table items in the I-node table that are currently being used or allocated in the core.
MAX-INODE control.

File-SZ: Number of table items in the file table currently being used or allocated in the core, controlled by the core parameter MAX-FILE
.

Ov: the number of overflow times.

Lock-SZ: Number of table items that are currently being locked by or allocated records in the core, with the core parameter MAX-FLCKRE
Control.

The display format is

Actual use of table items/number of available table items

The displayed content indicates that the core is completely normal. The three tables do not have overflow and the core parameters do not need to be adjusted, as shown in figure
If overflow occurs, adjust the corresponding core parameters to increase the number of corresponding table items.

Example 3: Use life-line Sar-d t n

For example, if you want to sample the device every 30 seconds for five consecutive times and report the device usage, enter 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

The displayed content includes:

Device: the name of the block device being monitored by the sar command.
% Busy: percentage of requests sent when the device is busy.
Avque: the average number of incomplete requests when the queue is full.
R + w/s: the amount of data transferred to or from the device per second.
Blks/s: the number of transferred blocks per second, each of which is 512 bytes.
Avwait: the average time for sending requests to wait for the queue to be idle when the queue is full.
Avserv: Average time (in milliseconds) required to complete the transfer request ).

In the displayed content, the wd-0 is the name of the hard disk and % busy is smaller, indicating that
The efficiency is too small, and the file system efficiency is not high. Generally, the % busy value is higher, the avque value is lower, and the file system
If the % busy and avque values are relatively high, the hard disk transmission speed is too slow and needs to be adjusted.

Example 4: Use alive Sar-B T N

For example, if you sample the buffer every 30 seconds for five consecutive times and report the usage of the buffer, enter 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
4 14:56:29 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

The displayed content includes:

Bread/s: the number of physical blocks read from the hard disk to the System Buffer per second.
Lread/s: the average number of logical blocks read from the System Buffer per second.
% Rcache: Percentage of logical reads in buffer cache.
Bwrit/S: Average number of physical blocks written from the system buffer to the disk per second.
Lwrit/S: Average number of logical blocks written to the System Buffer per second.
% Wcache: Percentage of logical reads in buffer cache.
Pread/S: Average number of physical reads requested per second.
Pwrit/S: Average number of physical writes requested per second.

In the displayed content, the most important columns are % cache and % wcache. Their values reflect the buffer usage efficiency.
Rate, % rcache value is less than 90 or % wcache value is less than 65, should increase the number of System Buffer, Buffer
The number is controlled by the core parameter nbuf, so that % rcache reaches 90, and % wcache reaches 80. But the buffer Parameter
The value affects the I/O efficiency and increases the buffer. The large memory size should be applied; otherwise, the system efficiency will not be available.
Improve.

Example 5: Use alive Sar-G T N

For example, if you want to sample data every 30 seconds for five consecutive times and report the serial I/O operations, enter 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

The displayed content includes:

Ovsiohw/S: serial port I/O hardware overflow per second.

Ovsiodma/S: overflow in the cache of the direct input/output channel of the serial port I/O per second.

Ovclist/S: overflow of character queues per second.

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

Many SAR commands are used. Sometimes, to judge a problem, several SAR commands need to be used in combination. For example, suspect
There is a bottleneck on the CPU. From the perspective of SAR-U and Sar-Q, we suspect that I/O has a bottleneck. Sar-B, Sar-u, and
According to SAR-D, the five examples mentioned above are only part of them. If you are interested, try again.

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.