Linux sar command using basic tutorial

  
 

The usage of SAR commands under linux and Unix is ​​very helpful for machine performance detection. dmesg can directly check the CPU frequency. To view the CPU and memory usage, you can use sar! Common format of the sar command line: sar [options] [-A] [-o file] t [n] In the command line, the two parameters n and t are combined to define the sampling interval and number of times, t is the sampling interval, it is necessary Some parameters, n is the number of samples, is optional, the default value is 1, -o file means to store the command results in a binary format in the file, file is not a keyword here, is the file name. Options are command line options. There are many options for the sar command. Only the common options are listed below: -A: The sum of all reports. -u: CPU utilization -v: Process, I node, file, and lock table status. -d: Hard disk usage report. -r: Memory page and hard disk block not used. -g: Serial I/O. -b: Buffer usage. -a: File read and write. -c: System call situation. -R: The activity of the process. -y: Terminal device activity. -w: System exchange activity. An example will be given below. Example 1: Use the command line sar -utn for example, sample every 60 seconds, sample 5 times in a row, observe the CPU usage, and store the sampling result in binary form in the file zhou in the current directory. You need to 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 display includes: %usr:CPU The percentage of time in user mode. %sys: The percentage of time the CPU is in system mode. %wio: The percentage of time the CPU waits for input and output completion time. %idle: Percentage of CPU idle time. In all the displays, we should mainly pay attention to %wio and %idle, the value of %wio is too high, indicating that the hard disk has an I/O bottleneck, and the %idle value is high, indicating that the CPU is idle, if the %idle value is high but the system responds slowly. At the same time, it is possible that the CPU is waiting to allocate memory. At this time, the memory capacity should be increased. If the %idle value lasts below 10, the system's CPU processing capacity is relatively low, indicating that the most needed resource 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 is visible, the sar command can be sampled in real time, and the previous sampling results can be queried. Example 2: Using the sar-vtn, for example, sampling every 30 seconds, sampling 5 times in a row, observing the state 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 contents include: proc-sz: number of 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 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 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 record-locked entries currently being used or allocated in the core, controlled by the core parameter MAX-FLCKRE. The display format is the actual use of the table item /the number of table items that can be used to display the content representation, the core usage is completely normal, the three tables do not have overflow phenomenon, the core parameters do not need to be adjusted, if there is an overflow, the corresponding core parameters are adjusted, The number of corresponding entries has increased. Example 3: Using the sar-dtn, for example, sampling every 30 seconds, sampling 5 times in a row, reporting the 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 The display includes: the name of the block device that the device: sar command is monitoring. %busy: The percentage of time the request was transferred when the device was busy. Avque: The average number of outstanding 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 blocks transferred per second, 512 bytes each. Avwait: The average time the transfer request waits for the queue to be idle when the queue is full. Avserv: Average time (in milliseconds) required to complete a transfer request. In the displayed content, wd-0 is the name of the hard disk, the value of %busy is relatively small, indicating that the effective time for processing the transfer request is too small, the file system efficiency is not high, in general, the %busy value is higher, avque The value is lower, the file system is more efficient. If the %busy and avque values ​​are relatively high, the hard disk transmission speed is too slow and needs to be adjusted. Example 4: Using the lifeline 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:

Copyright © Windows knowledge All Rights Reserved