Linux sar usage and installation: download and install wget logs. Common Format of sar command line: sar [options] [-A] [-o file] t [n] in command line, the n and t parameters are combined to define the sampling interval and number of times. t indicates the sampling interval, which is a required parameter. n indicates the number of samples and is optional. The default value is 1, -o file: stores command results in binary format. file is not a keyword but a file name. Options is the command line option, and there are many options for the sar command. below, only common options are listed:-A: total of all reports. -N: Network Interface Information. -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. -O file name: print the file name to the screen and save the sample result in binary format to the file in the current directory. -F file name: view the previously saved binary file. The following is an example. -------------------------------------------- Example 1: Use the command line sar-u t n www.2cto.com. For example, sample every 60 seconds and sample every 5 consecutive times to observe the CPU usage, save the sample result to the zhou file in the current directory in binary format. Enter the following command: # sar-u-o zhou 60 5 on the screen: 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 93 14:46:50 0 2 96 14:47:50 0 2 5 93 14:48:50 0 2 2 96 Average 0 2 4 94 on display content includes: % usr: percentage of time when the CPU is 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 value of % idle is high, indicating that the CPU is idle, if the % idle value is high but the system response is slow, it may be that the CPU is waiting for memory allocation. In this case, the memory capacity should be increased. If the value of % idle is lower than 10, the CPU processing capability of the system is relatively low, indicating that the most important resource to be solved in the system is the CPU. To view the content in the binary file zhou, type the following sar command: # sar-u-f zhou visible. The sar command can sample data in real time, you can also query previous sampling results. Www.2cto.com ---------------------------------------------- Example 2: Use the command line sar-v t n. For example, sample 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 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 308 10:35:23 /321 0 1338/2764 0 1592/1706 0 37/128 10:35:53 308/321 0 1335/2764 0 1591/1706 display content includes: proc-sz: number of entries in the table currently being used or allocated in the core, controlled by core parameter MAX-PROC. Inod-sz: the number of table items in the I node table that is currently being used or allocated in the core, which is controlled by the core parameter MAX-INODE. File-sz: the 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, controlled by the core parameter MAX-FLCKRE. The display format of www.2cto.com is as follows: the actual use of table items/The number of table items that can be used indicates that the core usage is completely normal. The three tables do not experience overflow and the core parameters do not need to be adjusted, in case of overflow, adjust the corresponding core parameters to increase the number of corresponding table items. ------------------------------------------- Example 3: Use the command line sar-d t n. For example, sample once every 30 seconds and sample 5 times continuously to report device usage. Enter the following command: # sar-d 30 5 screen display: www.2cto.com 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 11:07:43 wd-0 3.14 0.43 18.77 3.07 8.66 25.11 11:08:13 wd-0 1.41 0.77 2.78 2.77 7.26 4.94 2.77 11:08:43 wd-0 1.10 11.18 4.1 0 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 displays the name of the block device being monitored by the device: 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, % busy value is relatively small, indicating that the effective time for processing the transfer request is too small, the file system efficiency is not high, generally speaking, the % busy value is higher, the avque value is lower, and the file system efficiency is higher. 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 the command line sar-B t n. For example, sample once every 30 seconds and sample 5 times consecutively. To report the usage of the buffer zone, 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 5 25 79 0 0 14:56:29 4 100 98 8 58 86 0 0 14:56:59 0 232 125 5 23 76 0 0 14:57:29 0 89 100 4 12 66 0 0 Verage 1 156 99 5 28 80 0 0 display content includes: www.2cto.com 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. Among the displayed content, the most important columns are % cache and % wcache. Their values reflect the buffer usage efficiency, % rcache is less than 90 or % wcache is less than 65. The number of system buffers should be increased as appropriate. The number of buffers is controlled by the core parameter NBUF, so that % rcache reaches 90, % wcache reaches about 80. However, the value of the buffer parameter affects the I/O efficiency. To increase the buffer, the system efficiency should not be improved if the memory is large. ------------------------------------- Example 5: Use the command line sar-g t n. For example, sample once every 30 seconds and sample 5 times consecutively to report the operation of serial port I/O. 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 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 17:09:33 0.00 0.00 0.00 0.00 0.00 Average 0.00 0.00 0.00 display 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 values in each column are zero, indicating that serial port I/O overflow does not occur in the system during the sampling time. Many sar commands are used. To judge a problem, you need to use several sar commands in combination. For example, if you suspect that the CPU has a bottleneck, you can use sar-u and sar-q, i/O bottlenecks are suspected, which can be viewed by sar-B, sar-u, and sar-d. Www.2cto.com --------------------------------------- Example 6: Network statistics sar provides four different syntax options to display network information. The-n option uses four different switches: DEV, EDEV, SOCK, and FULL. DEV displays network interface information, EDEV displays statistics about network errors, SOCK displays socket information, and FULL displays all three switches. They can be used independently or together. Sar-n DEV 1 3 screen: 05: 27: 44 pm iface rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s05: 27: 45 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.0005: 27: 45 PM eth1 0.00 0.00 0.00 0.00 0.00 0.00: 27: 45 PM eth0 10.00 3.00 946.00 536.00 0.00 0.00 0.00 www.2cto.com sar-n DEV field: iface lan interface rxpck/s packet received per second txpck/s packet sent per second rxbyt/s number of bytes received per second txbyt/s number of bytes sent per second rxcmp/s compressed data packets received per second txcmp/s compressed data packets sent per second rxmcst/s multicast data packets received per second www.2cto.com sar-n EDEV field: iface lan interface rxerr/s bad packets received per second txerr/s bad packets sent per second coll/s number of conflicts per second rxdrop/s because the buffer is full, number of received packets discarded per second txdrop/s because the buffer is full, the number of sent packets discarded per second when txcarr/s sends packets, number of carrier errors per second rxfram/s Frame alignment errors of received packets per second rxfifo/s received packets per second FIFO transmission errors of txfifo/s sent packets per second FIFO transmission error count www.2cto.com sar-n SOCK Field: total number of sockets used by totsck tcpsck number of TCP sockets used by udpsck number of UDP sockets used by rawsck number of raw sockets used by ip-number of IP segments used by frag author wang7dao