Use the Linux tool SAR

Source: Internet
Author: User

1 Installation
Tar zxvf xxx.tar.gz

./Configure

Make

Make install

2. Use

Pidstat:

Usage:/usr/local/sysstat/bin/pidstat [Options] [<interval> [<count>]

Options are:

[-C <command>] [-D] [-H] [-I] [-L] [-R] [-S]

[-T] [-u] [-V] [-W]

[-P {<pid> [,...] | self | all}] [-t {task | child | all}]

-C: Only displays information about the command process whose name contains the command.

-D: displays the IO information of a process.

-I: The CPU usage is displayed under multiple processors.

-P: displays information about the PID process.

-R: displays page errors and memory usage.

-S: displays the usage of the stack.

-U: Report CPU usage

-W: displays context switching information.

# Monitor the CPU resource usage of processes whose PID is 1 (init). Refresh and output every 3 seconds. After 3 times, the program exits.
/> Pidstat-P 1 2 3-l
07:18:58 am PID % USR % System % guest % CPU command
07:18:59 am 1 0.00 0.00 0.00 0.00 0/sbin/init
07:19:00 am 1 0.00 0.00 0.00 0.00 0/sbin/init
07:19:01 am 1 0.00 0.00 0.00 0.00 0/sbin/init
Average: 1 0.00 0.00 0.00-/sbin/init
% USR: CPU usage of the Process in user mode.
% SYSTEM: CPU usage of the Process in kernel mode (system level.
% CPU: The total CPU usage of the process. If it is in an SMP environment, the value is divided by the number of CPUs to show the data of each CPU.
CPU: the number of the CPU attached to the process (0 indicates the first CPU ).

# Monitor the device IO resource load of processes whose PID is 1 (init). Refresh and output every two seconds. After three times, the program exits.
/> Pidstat-P 1 2 3-D
07:24:49 am PID kb_rd/s kb_wr/s kb_ccwr/s command
07:24:51 am 1 0.00 0.00 0.00 init
07:24:53 am 1 0.00 0.00 0.00 init
07:24:55 am 1 0.00 0.00 0.00 init
Average: 1 0.00 0.00 0.00 init
Kb_rd/s: the number of bytes read by the process per second (KB ).
Kb_wr/s: the number of bytes written by the process per second (KB ).
Kb_ccwr/S: Number of disk writes canceled by this process per second (KB ).

# Monitor the memory usage of processes whose PID is 1 (init). Refresh and output every two seconds. After three times, the program exits.
/> Pidstat-P 1 2 3-R
07:29:56 am PID minflt/s majflt/s vsz RSS % mem command
07:29:58 am 1 0.00 0.00 2828 1368 init
07:30:00 am 1 0.00 0.00 2828 1368 init
07:30:02 am 1 0.00 0.00 2828 1368 init
Average: 1 0.00 0.00 2828 1368 0.13 init
% Mem: memory usage percentage of the process.

# Monitor the process task switching with a PID of 1 (init). Refresh and output every two seconds. After three times, the program exits.
/> Pidstat-P 1 2 3-W
07:32:15 am PID cswch/s nvcswch/s command
07:32:17 am 1 0.00 0.00 init
07:32:19 am 1 0.00 0.00 init
07:32:21 am 1 0.00 0.00 init
Average: 1 0.00 0.00 init
Cswch/s: the number of active (voluntary) context switches per second. Active switching means that when a task is in a blocking wait state, it will take the initiative to give up its CPU resources.
Nvcswch/s: the number of times the task is passive (not voluntary) to switch the context per second. Passive switching means that the time slice allocated by the CPU to a task has been used up, so the process will be forced to give up the CPU execution right.

# Monitor the process whose PID is 1 (init) and its internal thread memory (R Option) Usage. Refresh and output every two seconds. After three times, the program exits. Note that if the-T option is not followed by any other options, CPU resources are monitored by default. The yellow highlighted part of the result indicates that the process and its internal threads are displayed in a tree structure.
/> Pidstat-P 1 2 3-tr
Linux 2.6.32-71. el6.i686 (Stephen-PC) 11/16/2011 _ i686 _ (1 CPU)

07:37:04 am tgid TID minflt/s majflt/s vsz RSS % mem command
07:37:06 a.m.-0.00 0.00 2828 1368 0.13
Init
07:37:06 am-1 0.00 0.00 2828 1368
|__ Init

07:37:06 am tgid TID minflt/s majflt/s vsz RSS % mem command
07:37:08 a.m.-0.00 0.00 2828 1368 0.13
Init
07:37:08 am-1 0.00 0.00 2828 1368
|__ Init

07:37:08 am tgid TID minflt/s majflt/s vsz RSS % mem command
07:37:10 a.m.-0.00 0.00 2828 1368 0.13
Init
07:37:10 am-1 0.00 0.00 2828 1368
|__ Init

Average: tgid TID minflt/s majflt/s vsz RSS % mem command
Average: 1-0.00 0.00 2828 1368
Init
Average:-1 0.00 0.00 2828 1368
|__ Init
Tgid: ID of the thread group.
TID: thread ID.

SAR usage

SAR:

Usage:/usr/local/sysstat/bin/SAR [Options] [<interval> [<count>]

Options are:

[-A] [-B] [-B] [-C] [-D] [-H] [-H] [-p] [-q] [-R]

[-R] [-S] [-T] [-U [all] [-V] [-V] [-W] [-W] [-y]

[-I {<int> [,...] | sum | all | xall}] [-P {<CPU> [,...] | all}]

[-M {<keyword> [,...] | all}] [-N {<keyword> [,...] | all}]

[-O [<FILENAME>] |-f [<FILENAME>]

[-I <interval>] [-s [

-A: Display All Information (too much content, rarely used)

-B: displays IO statistics.

-B: displays page statistics.

-C: enables SAR to display comments when reading input data from a file.

-D: displays the activity information of the block device.

-I: {<int> [,...] | sum | all | xall}] [-P {<CPU> [,...] | all} displays information about interrupted activities.

-N: displays network statistics.

-P: displays statistics for each CPU.

-P: used with-D to display the device name elegantly.

-Q: displays the queue length.

-R: displays memory usage.

-R: displays memory statistics.

-S: displays the usage of swap partitions.

-U: displays CPU usage

-W: displays Process Creation and context switching information.

-W: Display page exchange information.

 

View CPU usage
SAR 25
// Display 5 times and CPU usage every 2 seconds

% 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.

Sar 1 10> data.txt

// Write data every 1second and save the CPU usage data to the data.txt file.

Sar 1 0-e 15:00:00> data.txt

// The usage of CPU is recorded every 1second. Data is saved to the data.txt file after. (The-e parameter indicates the end time. Note that the time format must be hh: mm: Ss)

Sar 1 0-r-e 15:00:00> data.txt // records the memory usage every 1second. Data is saved to the data.txt file.

Sar 1 0-N Dev-e 15:00:00> data.txt // records the network usage every 1second. Data is saved to the data.txt file.

13 route 31? 8 crepe iface rxpck/s txpck/s rxkb/s txkb/s rxcmp/s txcmp/s rxmcst/s
13 route 31? 0 crepe lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
13 route 31? 0 crepe Em1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
13 route 31? 0 crepe EM2 30.50 10.00 4.52 3.61 0.00 0.00 8.50
13 route 31? 0 crepe em3 0.00 0.00 0.00 0.00 0.00 0.00 0.00
13 route 31? 0 crepe em4 0.00 0.00 0.00 0.00 0.00 0.00 0.00

Network Description

Iface LAN interface

Rxpck/s packets received per second

Txpck/s packets sent per second

Rxbyt/s the 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

Multicast packet received by rxmcst/s per second

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.

 

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.