Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Unix sar command

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

In the process of using the UNIX operating system, we often use a variety of problems, such as the system suddenly slows down, the system is easy to crash, or the terminal brought by the host often crashes, we often guess, is the hard disk space is too small, or insufficient memory? Is there a bottleneck in Icano, or is there something wrong with the core parameters of the system? At this time, we should consider using the sar command provided by the system to understand the system. This command is an important tool for system maintenance, which mainly helps us to grasp the use of system resources, especially the use of memory and CPU. It is one of the tools that UNIX system users should master.

Common format of the sar command line:

Sar [options] [- A] [- o file] t [n]

In the command line, n and t are combined to define the sampling interval and number of times. T is the sampling interval, which is a necessary parameter, and n is the number of sampling, which is optional. The default value is 1m file, which means to store the command results in a file in binary format. File is not a keyword here, but a file name. Options is a command line option, and there are many options for the sar command. Only common options are listed below:

A: the sum of all the reports.

-u:CPU utilization

-v: process, I node, file, and lock table status.

-d: hard disk usage report.

-r: no memory pages and hard disk blocks are used.

-g: the case of serial port Imax O (not available in centos 5).

-b: buffer usage.

-a: the reading and writing of documents.

-c: system call situation.

-R: the activity of the process.

-y: terminal equipment activity.

-w: system exchange activity.

Example 1: use the command line sar-u t n

For example, to sample every 60 seconds, for five consecutive times, to observe the use of CPU, and to store the sampling results in the file zhou in the current directory in binary form, type the following command:

# sar-u-o zhou 60 5

SCO_SV scosysv 3.2v5.0.5 i80386 10/01/2001

14:43:50 usr sys wio idle (- u)

14:44:50 0 14 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:

The percentage of time usr:CPU spent in user mode.

The percentage of time sys:CPU spent in system mode.

Percentage of time that wio:CPU waits for input and output to complete.

% idle:CPU percentage of idle time.

In all the displays, we should mainly note that the values of% wio and% idle,%wio are too high, indicating that the hard disk has an I O bottleneck, and a high% idle value means that the CPU is idle. If the% idle value is high but the system response is slow, it is possible that the CPU is waiting to allocate memory, so the memory capacity should be increased at this time. If the% CPU value is consistently lower than 10, then the system's CPU processing capacity is relatively low, indicating that the resource that needs to be solved most in the system is CPU.

If you want to view the contents of the binary file zhou, type the following sar command:

# sar-u-f zhou

It can be seen that the sar command can not only sample in real time, but also query the previous sampling results.

Example 2: using life line sar-v t n

For example, to observe the status of the core table by sampling every 30 seconds for 5 consecutive times, type the following command:

# sar-v 30 5

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 display includes:

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

Inod-sz: the number of items 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 entries in the file table currently being used or allocated in the core, controlled by the core parameter MAX-FILE.

Ov: the number of overflow occurrences.

Lock-sz: the number of locked table items of records currently being used or allocated in the core, controlled by the core parameter MAX-FLCKRE.

Display format is: actual use of table items / number of table items that can be used

The display shows that the use of the core is completely normal, there is no overflow in the three tables, and the core parameters do not need to be adjusted. If there is an overflow, adjust the corresponding core parameters and increase the number of corresponding table items.

Example 3: using life line sar-d t n

For example, to report device usage by sampling every 30 seconds for 5 consecutive times, type the following command:

# sar-d 30 5

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 display includes:

Device: the name of the block device that the sar command is monitoring.

% busy: the percentage of time it takes to send a request when the device is busy.

Avque: the average number of outstanding requests when the queue is full.

R+w/s: the amount of data transmitted to or from a device per second.

Blks/s: the number of blocks transferred per second, 512 bytes per block.

Avwait: the average time that a delivery request waits for the queue to be idle when the queue is full.

Avserv: the average time (in milliseconds) it takes to complete the delivery request.

In the display, wd-0 is the name of the hard disk, and the value of% busy is relatively small, indicating that the valid time used to process transfer requests is too little, and the file system is not efficient. Generally speaking, the% busy value is higher, the avque value is lower, and the file system efficiency is higher. If the% bus and avque values are relatively high, it means that the hard disk transfer speed is too slow and needs to be adjusted.

Example 4: using life line sar-b t n

For example, to report buffer usage by sampling every 30 seconds for 5 consecutive times, type the following command:

# sar-b 30 5

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 00

14:55:59 0 186 100 5 25 79 00

14:56:29 4 232 98 8 58 86 0 0

14:56:59 0 125 100 5 23 76 00

14:57:29 0 89 100 4 12 66 00

Average 1 156 99 5 28 80 0 0

The display includes:

Bread/s: the number of physical blocks read from the hard disk into the system buffer buffer per second.

Lread/s: the average number of logical blocks read from the system buffer per second.

% rcache: percentage of logical reads in the buffer cache.

Bwrit/s: the average number of physical blocks written from the system buffer to disk per second.

Lwrit/s: the average number of logical blocks written to the system buffer per second.

% wcache: 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 requested per second.

Among the contents displayed, the most important columns are% cache and% wcache. Their values reflect the efficiency of the use of buffer. The value of% rcache is less than 90 or the value of% wcache is less than 65. The number of system buffer should be increased appropriately, and the number of buffer is controlled by the core parameter NBUF, so that% rcache is about 90 and% wcache is about 80. However, the number of buffer parameters affects the efficiency of buffer, which should be in the case of larger memory, otherwise the efficiency of the system can not be improved.

Example 5: use life line sar-g t n

For example, if you sample every 30 seconds for 5 consecutive times to report the operation of serial port Imax O, you need to type the following command:

# sar-g 30 5

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 display includes:

Ovsiohw/s: every second overflow on serial port iCompo hardware.

Ovsiodma/s: per second overflow in the direct input and output channel cache of serial port iMaple O.

Ovclist/s: overflow of character queues per second.

In the display, the value of each column is zero, indicating that there is no serial port Ihand O overflow in the system during the sampling time.

There are many uses of sar commands. Sometimes to judge a problem, you need a combination of several sar commands. For example, if you suspect that CPU has a bottleneck, you can use sar- u and sar- Q to see it, and you can use sar- b, sar- u and sar-d to see it.

For the oracle video tutorial, please follow: http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report