Learn And Life.

linux的10个命令

先看下这个10个命令:
uptime
dmesg | tail
vmstat 1
mpstat -P ALL 1
pidstat 1
iostat -xz 1
free -m
sar -n DEV 1
sar -n TCP,ETCP 1
top

下面讲解下这个10个命令都是用来做什么的,怎么用

uptime

1
2
chenjingxiu:~ kivmi$ uptime
00:23上午 up 6 days 1:53, 3 users, load average: 1.96, 1.70, 1.70

uptime – show how long system has been running
DESCRIPTION
The uptime utility displays the current time, the length of time the system has been up, the number of users, and the load average of the system over the
last 1, 5, and 15 minutes.
该命令用来查看系统的运行时间和负载情况,分别对应以下列
当前时间 启动运行时间 系统启动时间 当前系统用户数 系统最近1分钟、5分钟、15分钟系统的负载情况

dmesg | tail

1
2
3
4
5
6
7
8
9
10
11
chenjingxiu:~ kivmi$ sudo dmesg | tail
ARPT: 243830.149501: DequeueTime: 0x1906f048 LastTxTime: 0x1ff947d1 PHYTxErr: 0x0000 RxAckRSSI: 0x0000 RxAckSQ: 0x0000
ARPT: 243830.149527: Raw[0] 1 Valid
ARPT: 243830.149536: [2] 0 IM
ARPT: 243830.149541: [3] 1 PM
ARPT: 243830.149545: [7-4] 0 Suppr
ARPT: 243830.149550: [14:8] 1 Ncons
ARPT: 243830.149555: [15] 0 Acked
ARPT: 243830.149561: txpktpend AC_BK 0 AC_BE 0 AC_VI 0 AC_VO 1 BCMC 0 ATIM 0
SmartBattery: finished polling type 4
UserEventAgent is not entitledUserEventAgent is not entitledloginwindow is not entitledloginwindow is not entitledUserEventAgent is not entitledUserEventAgent is not entitledloginwindow is not entitledloginwindow is not entitledUserEventAgent is not entitledUserEventAgent is not entitledloginwindow is not entitledloginwindow is not entitledSmartBattery: finished polling type 4

dmesg – display the system message buffer
DESCRIPTION
Dmesg displays the contents of the system message buffer. This command needs to be run as root.
该命令用来显示linux内核的环形缓冲区(kernel ring buffer)信息,从中获得诸如系统架构、cpu、挂载的硬件,RAM等多个运行级别的大量的系统信息,当计算机启动时,系统内核(操作系统的核心部分)将会被加载到内存中,在加载的过程中会显示很多的信息,在这些信息中我们可以看到内核检测硬件设备,主要是硬件检测,包括磁盘sda,hda,usb等

vmstat 2 1
每两秒采集一次服务器的状态 2 时间间隔 1 次数

1
2
3
4
5
6
[chenjingxiu@op ~]$ vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 5564792 408260 20643368 0 0 0 27 1 1 1 2 97 0 0
0 0 0 5562248 408260 20643372 0 0 0 0 2609 3087 1 2 98 0 0
6 0 0 5530268 408260 20643380 0 0 0 0 4354 4287 4 6 90 0 0

NAME
vmstat - Report virtual memory statistics

SYNOPSIS
vmstat [-a] [-n] [-t] [-S unit] [delay [ count ]]
vmstat [-s] [-n] [-S unit]
vmstat [-m] [-n] [delay [ count ]]
vmstat [-d] [-n] [delay [ count ]]
vmstat [-p disk partition] [-n] [delay [ count ]]
vmstat [-f]
vmstat [-V]

DESCRIPTION
vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory
reports are instantaneous in either case.

DESCRIPTION FOR VM MODE

Procs
r: The number of processes waiting for run time.(在运行队列中等待cpu进程数)
b: The number of processes in uninterruptible sleep.(等待I/O的进程数)

Memory
swpd: the amount of virtual memory used.(切换到内存交换区的内存数量,如果swpd比较大,但是si,so一直为0,系统性能也是正常的)
free: the amount of idle memory.
buff: the amount of memory used as buffers.(一般对块设备的读写进行缓存)
cache: the amount of memory used as cache.(page cache数量,一般作为文件系统的缓存,如果cache比较大,说明用到cache的文件比较多,如果I/O的bi比较小,说明文件系统效率比较好)
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)

Swap
si: Amount of memory swapped in from disk (/s).(从磁盘交换进内存的页数量)
so: Amount of memory swapped to disk (/s).(从内存交换到磁盘的页数量)

IO
bi: Blocks received from a block device (blocks/s).(从磁盘读到内存的块数)
bo: Blocks sent to a block device (blocks/s).(从内存写入磁盘的块数)

System
in: The number of interrupts per second, including the clock.(每秒设备中断数)
cs: The number of context switches per second.(每秒产生的上下文切换次数,cs正常情况下,应小于I/O的包传输速率)

CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time) (用户进程占用cpu的时间比)
sy: Time spent running kernel code. (system time) (系统进程占用cpu的时间比)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.(中央处理器空闲时间占用比)
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

FIELD DESCRIPTION FOR DISK MODE

Reads
total: Total reads completed successfully
merged: grouped reads (resulting in one I/O)
sectors: Sectors read successfully
ms: milliseconds spent reading

Writes
total: Total writes completed successfully
merged: grouped writes (resulting in one I/O)
sectors: Sectors written successfully
ms: milliseconds spent writing

IO
cur: I/O in progress
s: seconds spent for I/O
ms: milliseconds spent writing

IO
cur: I/O in progress
s: seconds spent for I/O

FIELD DESCRIPTION FOR DISK PARTITION MODE

reads: Total number of reads issued to this partition read sectors: Total read sectors for partition
writes : Total number of writes issued to this partition
requested writes: Total number of write requests made for partition

FIELD DESCRIPTION FOR SLAB MODE

cache: Cache name
num: Number of currently active objects
total: Total number of available objects
size: Size of each object
pages: Number of pages with at least one active object
totpages: Total number of allocated pages
pslab: Number of pages per slab

如果r经常大于4 ,且id经常小于40,表示中央处理器的负荷很重。 如果bi,bo 长期不等于0,表示物理内存容量太小

mpstat -P ALL 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[chenjingxiu@op ~]$ mpstat -P ALL 1
Linux 2.6.32-279.19.1.el6.centos.plus.x86_64 (op.liebaopay.com) 12/11/2016 _x86_64_ (8 CPU)
06:49:57 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
06:49:58 AM all 0.50 0.00 1.00 0.50 0.00 0.00 0.00 0.00 97.99
06:49:58 AM 0 1.01 0.00 1.01 1.01 0.00 0.00 0.00 0.00 96.97
06:49:58 AM 1 1.00 0.00 1.00 3.00 0.00 0.00 0.00 0.00 95.00
06:49:58 AM 2 0.00 0.00 2.02 0.00 0.00 0.00 0.00 0.00 97.98
06:49:58 AM 3 0.99 0.00 0.99 0.00 0.00 0.00 0.00 0.00 98.02
06:49:58 AM 4 0.99 0.00 0.99 0.00 0.00 0.00 0.00 0.00 98.02
06:49:58 AM 5 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 99.00
06:49:58 AM 6 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 99.00
06:49:58 AM 7 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 99.00
06:49:58 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
06:49:59 AM all 0.50 0.00 1.51 0.00 0.00 0.00 0.00 0.00 97.99
06:49:59 AM 0 2.97 0.00 5.94 0.00 0.00 0.00 0.00 0.00 91.09
06:49:59 AM 1 0.00 0.00 1.02 0.00 0.00 0.00 0.00 0.00 98.98
06:49:59 AM 2 0.99 0.00 1.98 0.00 0.00 0.00 0.00 0.00 97.03
06:49:59 AM 3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
06:49:59 AM 4 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
06:49:59 AM 5 0.00 0.00 1.01 0.00 0.00 0.00 0.00 0.00 98.99
06:49:59 AM 6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
06:49:59 AM 7 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 99.00

NAME
mpstat - Report processors related statistics.

DESCRIPTION
The mpstat command writes to standard output activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed. If no activity has been selected, then the default report is the CPU utilization report.
The interval parameter specifies the amount of time in seconds between each report. A value of 0 (or no parameters at all) indicates that processors statistics are to be reported for the time since system startup (boot). The count parameter can be specified in conjunction with the interval parameter if this one is not set to zero. The value of count determines the number of reports generated at interval seconds apart. If the interval parameter is speci-fied without the count parameter, the mpstat command generates reports continuously.

OPTIONS
-A This option is equivalent to specifying -I ALL -u -P ALL
-P { cpu [,…] | ON | ALL }
Indicate the processor number for which statistics are to be reported. cpu is the processor number. Note that processor 0 is the first processor.The ON keyword indicates that statistics are to be reported for every online processor, whereas the ALL keyword indicates that statistics are to be reported for all processors.
-u Report CPU utilization. The following values are displayed:

CPU Processor number. The keyword all indicates that statistics are calculated as averages among all processors.
%usr Show the percentage of CPU utilization that occurred while executing at the user level (application).
%nice Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.
%sys Show the percentage of CPU utilization that occurred while executing at the system level (kernel). Note that this does not include time spent servicing hardware and software interrupts.
%iowait Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%irq Show the percentage of time spent by the CPU or CPUs to service hardware interrupts.
%soft Show the percentage of time spent by the CPU or CPUs to service software interrupts.
%steal Show  the  percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual proces-sor.
%guest Show the percentage of time spent by the CPU or CPUs to run a virtual processor.
%idle Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.

ipdstat 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[chenjingxiu@op ~]$ pidstat 1
Linux 2.6.32-279.19.1.el6.centos.plus.x86_64 (op.liebaopay.com) 12/11/2016 _x86_64_ (8 CPU)
07:01:34 AM PID %usr %system %guest %CPU CPU Command
07:01:35 AM 3294 0.00 0.84 0.00 0.84 3 python2.7
07:01:35 AM 14733 0.84 0.00 0.00 0.84 0 sshd
07:01:35 AM 15959 4.20 11.76 0.00 15.97 0 pidstat
07:01:35 AM 30156 0.00 0.84 0.00 0.84 1 tmux
07:01:35 AM PID %usr %system %guest %CPU CPU Command
07:01:36 AM 36 0.00 1.00 0.00 1.00 1 events/1
07:01:36 AM 14733 0.00 1.00 0.00 1.00 0 sshd
07:01:36 AM 15959 5.00 13.00 0.00 18.00 0 pidstat
07:01:36 AM 29962 1.00 0.00 0.00 1.00 0 python

NAME
pidstat - Report statistics for Linux tasks.

DESCRIPTION
The pidstat command is used for monitoring individual tasks currently being managed by the Linux kernel. It writes to standard output activities for every task selected with option -p or for every task managed by the Linux kernel if option -p ALL has been used. Not selecting any tasks is equivalent to speci-fying -p ALL but only active tasks (tasks with non-zero statistics values) will appear in the report.

The pidstat command can also be used for monitoring the child processes of selected tasks. Read about option -T below.

The interval parameter specifies the amount of time in seconds between each report. A value of 0 (or no parameters at all) indicates that tasks statistics are to be reported for the time since system startup (boot). The count parameter can be specified in conjunction with the interval parameter if this one is not set to zero. The value of count determines the number of reports generated at interval seconds apart. If the interval parameter is specified without the count parameter, the pidstat command generates reports continuously.

You can select information about specific task activities using flags. Not specifying any flags selects only CPU activity.

EXAMPLES

pidstat 2 5
Display five reports of CPU statistics for every active task in the system at two second intervals.

pidstat -r -p 1643 2 5
Display five reports of page faults and memory statistics for PID 1643 at two second intervals.

pidstat -T CHILD -r 2 5
Display five reports of page faults statistics at two second intervals for the child processes of all tasks in the system. Only child processes with non-zero statistics values are displayed.

iostat -xz 1
iostat主要用于监控系统设备的IO负载情况

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
chenjingxiu:~ kivmi$ iostat -d -K 1 10
disk0 disk2 disk3
KB/t tps MB/s KB/t tps MB/s KB/t tps MB/s
52.04 6 0.31 14.14 0 0.00 14.03 0 0.00
4.00 9 0.04 0.00 0 0.00 0.00 0 0.00
6.67 3 0.02 0.00 0 0.00 0.00 0 0.00
4.00 1 0.00 0.00 0 0.00 0.00 0 0.00
394.00 2 0.77 0.00 0 0.00 0.00 0 0.00
[chenjingxiu@op ~]$ iostat -xz 1
Linux 2.6.32-279.19.1.el6.centos.plus.x86_64 (op.liebaopay.com) 12/11/2016 _x86_64_ (8 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
1.08 0.00 1.92 0.13 0.01 96.86
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvda 0.00 0.09 0.03 7.72 0.89 62.49 8.18 0.05 6.19 1.23 0.95
xvdi 0.00 9.52 0.03 6.74 2.13 130.09 19.52 0.09 12.73 0.51 0.34
xvdb 0.00 0.00 0.01 0.12 0.12 9.44 73.96 0.04 304.96 2.07 0.03
xvdf 0.00 0.01 0.06 3.31 3.25 229.37 69.16 0.03 8.61 0.17 0.06
avg-cpu: %user %nice %system %iowait %steal %idle
0.38 0.00 0.75 0.25 0.13 98.50
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvda 0.00 0.00 1.00 0.00 16.00 0.00 16.00 0.02 17.00 17.00 1.70

NAME
iostat - Report Central Processing Unit (CPU) statistics and input/output statistics for devices, partitions and network filesystems (NFS).

DESCRIPTION
The iostat command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates. The iostat command generates reports that can be used to change system configuration to better balance the input/output load between physical disks.

The first report generated by the iostat command provides statistics concerning the time since the system was booted. Each subsequent report covers the time since the previous report. All statistics are reported each time the iostat command is run. The report consists of a CPU header row followed by a row of CPU statistics. On multiprocessor systems, CPU statistics are calculated system-wide as averages among all processors. A device header row is displayed followed by a line of statistics for each device that is configured. When option -n is used, an NFS header row is displayed followed by a line of statistics for each network filesystem that is mounted.

The interval parameter specifies the amount of time in seconds between each report. The first report contains statistics for the time since system startup (boot). Each subsequent report contains statistics collected during the interval since the previous report. The count parameter can be specified in conjunction with the interval parameter. If the count parameter is specified, the value of count determines the number of reports generated at interval seconds apart. If the interval parameter is specified without the count parameter, the iostat command generates reports continuously.

REPORTS
The iostat command generates three types of reports, the CPU Utilization report, the Device Utilization report and the Network Filesystem report.

CPU Utilization Report
The first report generated by the iostat command is the CPU Utilization Report. For multiprocessor systems, the CPU values are global averages among all processors. The report has the following format:
%user
Show the percentage of CPU utilization that occurred while executing at the user level (application).

%nice
Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.

%system
Show the percentage of CPU utilization that occurred while executing at the system level (kernel).

%iowait
Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.

%steal
Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.

%idle
Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.

Device Utilization Report
The second report generated by the iostat command is the Device Utilization Report. The device report provides statistics on a per physical device or par-tition basis. Block devices for which statistics are to be displayed may be entered on the command line. Partitions may also be entered on the command line providing that option -x is not used. If no device nor partition is entered, then statistics are displayed for every device used by the system, and providing that the kernel maintains statistics for it. If the ALL keyword is given on the command line, then statistics are displayed for every device defined by the system, including those that have never been used. The report may show the following fields, depending on the flags used.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
tps: 每秒传输的次数,一次传输即一次I/O请求(多个逻辑请求可以合并为一次I/O请求)
kB_read/s: 每秒从设备读取的数据量
kB_wrtn/s: 每秒向设备写入的数据量
kB_read: 读取的总数据量
kB_wrtn: 写入的总数据量
rrqm/s:每秒这个设备相关的读取请求有多少被Merge了
wrqm/s:每秒这个设备相关的写入请求有多少被Merge了
rsec/s:每秒读取的扇区数
wsec/:每秒写入的扇区数
rKB/s:The number of read requests that were issued to the device per second
wKB/s:The number of write requests that were issued to the device per second
avgrq-sz:平均请求扇区的大小
avgqu-sz:平均请求队列的长度
await:每一个IO请求的处理的平均时间(单位是微秒毫秒),即IO的响应时间,一般情况下,await大于svctm,两者差值越小,则说明队列时间越短,反之差值越大,队列时间越长,说明系统出问题了,await一般低于5ms
svctm:表示平均每次设备I/O操作的服务时间(以毫秒为单位),如果svctm的值与await很接近,表示几乎没有I/O等待,磁盘性能很好,如果await的值远高于svctm的值,则表示I/O队列等待太长,系统上运行的应用程序将变慢
%util: 在统计时间内所有处理IO时间,除以总共统计时间,预示设备的繁忙程度,如果该参数是100%表示设备已经接近满负荷运行了

Network Filesystem report
The Network Filesystem (NFS) report provides statistics for each mounted network filesystem. The report shows the following fields

OPTIONS
-c Display the CPU utilization report.
-d Display the device utilization report.(显示磁盘的使用状态)
-K 对块设备,强制使用Kilobytes为单位
-x Display extended statistics. This option works with post 2.5 kernels since it needs /proc/diskstats file or a mounted sysfs to get the statistics. This option may also work with older kernels (e.g. 2.4) only if extended statistics are available in /proc/partitions (the kernel needs to be patched for that).(显示I/O相关的扩展数据)
-n Display the network filesystem (NFS) report. This option works only with kernel 2.6.17 and later.
-p [ { device [,…] | ALL } ]
The -p option displays statistics for block devices and all their partitions that are used by the system. If a device name is entered on the command line, then statistics for it and all its partitions are displayed. Last, the ALL keyword indicates that statistics have to be displayed for all the block devices and partitions defined by the system, including those that have never been used. Note that this option works only with post 2.5 kernels.

EXAMPLES

iostat
Display a single history since boot report for all CPU and Devices.
iostat -d 2
Display a continuous device report at two second intervals.
iostat -d 2 6
Display six reports at two second intervals for all devices.
iostat -x hda hdb 2 6
Display six reports of extended statistics at two second intervals for devices hda and hdb.
iostat -p sda 2 6
Display six reports at two second intervals for device sda and all its partitions (sda1, etc.)

主要看await和%util的值,await是否大于5ms,%util是否大于80%

free -m

1
2
3
4
5
[chenjingxiu@op ~]$ free -m
total used free shared buffers cached
Mem: 30100 24655 5445 0 398 20166
-/+ buffers/cache: 4089 26010
Swap: 0 0 0

NAME
free - Display amount of free and used memory in the system
DESCRIPTION
free displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The shared memory column should be ignored; it is obsolete.

sar -n DEV 1

1
2
3
4
5
6
7
8
9
10
[chenjingxiu@op ~]$ sar -n DEV 1
Linux 2.6.32-279.19.1.el6.centos.plus.x86_64 (op.liebaopay.com) 12/11/2016 _x86_64_ (8 CPU)
07:26:36 AM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
07:26:37 AM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
07:26:37 AM eth0 150.51 152.53 29.42 21.03 0.00 0.00 0.00
07:26:37 AM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
07:26:38 AM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
07:26:38 AM eth0 107.00 103.00 24.87 14.36 0.00 0.00 0.00

NAME
sar - Collect, report, or save system activity information.

DESCRIPTION
The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters, writes information the specified number of times spaced at the specified intervals in seconds. If the interval parameter is set to zero, the sar command displays the average statistics for the time since the system was started. If the interval parameter is specified without the count parameter, then reports are generated continuously. The collected data can also be saved in the file specified by the -o file-name flag, in addition to being displayed onto the screen. If filename is omitted, sar uses the standard system activity daily data file, the /var/log/sa/sadd file, where the dd parameter indicates the current day. By default all the data available from the kernel are saved in the data file.

The sar command extracts and writes to standard output records previously saved in a file. This file can be either the one specified by the -f flag or, by default, the standard system activity daily data file.

Without the -P flag, the sar command reports system-wide (global among all processors) statistics, which are calculated as averages for values expressed as percentages, and as sums otherwise. If the -P flag is given, the sar command reports activity which relates to the specified processor or processors. If -P ALL is given, the sar command reports statistics for each individual processor and global statistics among all processors.

You can select information about specific system activities using flags. Not specifying any flags selects only CPU activity. Specifying the -A flag is equivalent to specifying -bBdqrRSvwWy -I SUM -I XALL -n ALL -u ALL -P ALL.

The default version of the sar command (CPU utilization report) might be one of the first facilities the user runs to begin system activity investigation,because it monitors major system resources. If CPU utilization is near 100 percent (user + nice + system), the workload sampled is CPU-bound.If multiple samples and multiple reports are desired, it is convenient to specify an output file for the sar command. Run the sar command as a background process. The syntax for this is:

sar -o datafile interval count >/dev/null 2>&1 &

All data is captured in binary form and saved to a file (datafile).  The data can then be selectively displayed with the sar command using the  -f  option.Set the interval and count parameters to select count records at interval second intervals. If the count parameter is not set, all the records saved in the file will be selected.  Collection of data in this manner is useful to characterize system usage over a period of time and determine peak usage hours.

Indicate the number of transfers per second that were issued to the device. Multiple logical requests can be combined into a single I/O
request to the device. A transfer is of indeterminate size.

rd_sec/s
Number of sectors read from the device. The size of a sector is 512 bytes.

wr_sec/s
Number of sectors written to the device. The size of a sector is 512 bytes.

avgrq-sz
The average size (in sectors) of the requests that were issued to the device.

avgqu-sz
The average queue length of the requests that were issued to the device.

await
The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue
and the time spent servicing them.

svctm
The average service time (in milliseconds) for I/O requests that were issued to the device.

%util
Percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs
when this value is close to 100%.

sar -n TCP,ETCP 1

1
2
3
4
5
6
7
8
[chenjingxiu@op ~]$ sar -n TCP,ETCP 1
Linux 2.6.32-279.19.1.el6.centos.plus.x86_64 (op.liebaopay.com) 12/11/2016 _x86_64_ (8 CPU)
07:38:52 AM active/s passive/s iseg/s oseg/s
07:38:53 AM 0.00 0.00 122.22 114.14
07:38:52 AM atmptf/s estres/s retrans/s isegerr/s orsts/s
07:38:53 AM 0.00 0.00 0.00 0.00 0.00

top

1
2
3
4
5
6
7
8
9
top - 07:40:00 up 47 days, 23:57, 122 users, load average: 2.01, 2.03, 2.06
Tasks: 2185 total, 1 running, 2174 sleeping, 8 stopped, 2 zombie
Cpu(s): 0.9%us, 2.2%sy, 0.0%ni, 96.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 30822952k total, 25263368k used, 5559584k free, 408320k buffers
Swap: 0k total, 0k used, 0k free, 20652508k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
11028 chenjing 20 0 18732 2928 972 R 3.2 0.0 0:00.48 top
3294 ansible 20 0 635m 49m 2928 S 1.3 0.2 525:49.41 python2.7

NAME
top - display Linux tasks

a: PID – Process Id
The task’s unique process ID, which periodically wraps, though never restarting at zero.

b: PPID – Parent Process Pid
The process ID of a task’s parent.

c: RUSER – Real User Name
The real user name of the task’s owner.

d: UID – User Id
The effective user ID of the task’s owner.

e: USER – User Name
The effective user name of the task’s owner.

f: GROUP – Group Name
The effective group name of the task’s owner.

g: TTY – Controlling Tty
The name of the controlling terminal. This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input or output. However, a task need not be associated with a terminal, in which case you’ll see ’?’ displayed.

h: PR – Priority
The priority of the task.

i: NI – Nice value
The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field simply means priority will not be adjusted in determining a task’s dispatchability.

j: P – Last used CPU (SMP)
A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time).

k: %CPU – CPU usage
The task’s share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if ’Irixmode’ is Off, top will operate in ’Solaris mode’ where a task’s cpu usage will be divided by the total number of CPUs. You toggle ’Irix/Solaris’ modes with the ’I’ interactive command.

1
2
3
4
5
6
7
8
us 用户空间占用CPU百分比
sy 内核空间占用cpu百分比
ni 用户空间内改变优先级的进程占用cpu百分比
id cpu空闲占用百分比
wa 等待输入输出的cpu占用百分比
hi 硬件cpu中断占用百分比
si 软中断占用百分比
st 虚拟机占用百分比

l: TIME – CPU Time 进程使用cpu时间总计,单位秒
Total CPU time the task has used since it started. When ’Cumulative mode’ is On, each process is listed with the cpu time that it and its dead children has used. You toggle ’Cumulative mode’ with ’S’, which is a command-line option and an interactive command. See the ’S’ interactive command for addi-tional information regarding this mode.

m: TIME+ – CPU Time, hundredths 进程使用cpu时间总计, 单位1/100秒
The same as ’TIME’, but reflecting more granularity through hundredths of a second.

n: %MEM – Memory usage (RES) 使用物理内存占用比
A task’s currently used share of available physical memory.

o: VIRT – Virtual Image (kb)虚拟内存使用量
The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out. (Note: you can define the STATSIZE=1 environment variable and the VIRT will be calculated from the /proc/#/state VmSize field.)

p: SWAP – Swapped size (kb) 使用虚拟内存,被换出的大小
Per-process swap values are now taken from /proc/#/status VmSwap field.

q: RES – Resident size (kb) 进程使用的,未被还出的物理内存大小
The non-swapped physical memory a task has used.
RES = CODE + DATA.

r: CODE – Code size (kb) 可执行的代码占用物理内存的大小
The amount of physical memory devoted to executable code, also known as the ’text resident set’ size or TRS.

s: DATA – Data+Stack size (kb) 可执行代码以外的部分(数据段+棧)占用物理内存的大小
The amount of physical memory devoted to other than executable code, also known as the ’data resident set’ size or DRS.

t: SHR – Shared Mem size (kb) 共享内存大小
The amount of shared memory used by a task. It simply reflects memory that could be potentially shared with other processes.

u: nFLT – Page Fault count 页面错误次数
The number of major page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that

v: nDRT – Dirty Pages count 最后一次写入,未被修改的的页面数
The number of pages that have been modified since they were last written to disk. Dirty pages must be written to disk before the corresponding physical memory location can be used for some other virtual page.

w: S – Process Status 进程状态
The status of the task which can be one of:
’D’ = uninterruptible sleep()
’R’ = running
’S’ = sleeping
’T’ = traced or stopped
’Z’ = zombie(僵尸进程数)
Tasks shown as running should be more properly thought of as ’ready to run’ – their task_struct is simply represented on the Linux run-queue. Even without a true SMP machine, you may see numerous tasks in this state depending on top’s delay interval and nice value.

x: Command – Command line or Program name 命令名
Display the command line used to start a task or the name of the associated program. You toggle between command line and name with ’c’, which is both a command-line option and an interactive command.When you’ve chosen to display command lines, processes without a command line (like kernel threads) will be shown with only the program name in paren-theses, as in this example:
( mdrecoveryd )
Either form of display is subject to potential truncation if it’s too long to fit in this field’s current width. That width depends upon other fields selected, their order and the current screen width.
Note: The ’Command’ field/column is unique, in that it is not fixed-width. When displayed, this column will be allocated all remaining screen width (up to the maximum 512 characters) to provide for the potential growth of program names into command lines.

y: WCHAN – Sleeping in Function 睡眠状态的进程系统函数名
Depending on the availability of the kernel link map (’System.map’), this field will show the name or the address of the kernel function in which the task is currently sleeping. Running tasks will display a dash (’-’) in this column.
Note: By displaying this field, top’s own working set will be increased by over 700Kb. Your only means of reducing that overhead will be to stop and restart top.

z: Flags – Task Flags 任务标志
This column represents the task’s current scheduling flags which are expressed in hexadecimal notation and with zeros suppressed. These flags are offi-cially documented in . Less formal documentation can also be found on the ’Fields select’ and ’Order fields’ screens.

以上均摘录自手册,供大家参考,使用!