linux 常用命令介绍

来源:互联网 发布:斯维尔暖通负荷软件 编辑:程序博客网 时间:2024/04/30 03:23

TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最“敏感”的任务列表.该命令可以按CPU使用.内存使用和执行时间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定.
top - 12:38:33 up 50 days, 23:15,  7 users,  load average: 60.58, 61.14, 61.22

Tasks: 203 total,  60 running, 139 sleeping,   4 stopped,   0 zombie

Cpu(s)  : 27.0%us, 73.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:   1939780k total,  1375280k used,   564500k free,   109680k buffers

Swap:  4401800k total,   497456k used,  3904344k free,   848712k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                               

4338 oracle    25   0  627m 209m 207m R    0 11.0 297:14.76 oracle                               

4267 oracle    25   0  626m 144m 143m R    6  7.6  89:16.62 oracle                               

3458 oracle    25   0  672m 133m 124m R    0  7.1   1283:08 oracle                               

3478 oracle    25   0  672m 124m 115m R    0  6.6   1272:30 oracle                               

3395 oracle    25   0  672m 122m 113m R    0  6.5   1270:03 oracle                                

3480 oracle    25   0  672m 122m 109m R    8  6.4   1274:13 oracle                               

3399 oracle    25   0  672m 121m 110m R    0  6.4   1279:37 oracle                               

4261 oracle    25   0  634m 100m  99m R    0  5.3  86:13.90 oracle                               

25737 oracle    25   0  632m  81m  74m R    0  4.3 272:35.42 oracle                               

7072 oracle    25   0  626m  72m  71m R    0  3.8   6:35.68 oracle                               

16073 oracle    25   0  630m  68m  63m R    8  3.6 175:20.36 oracle                               

16140 oracle    25   0  630m  66m  60m R    0  3.5 175:13.42 oracle                               

16122 oracle    25   0  630m  66m  60m R    0  3.5 176:47.73 oracle                               

  786 oracle    25   0  627m  63m  63m R    0  3.4   1:54.93 oracle                               

4271 oracle    25   0  627m  59m  58m R    8  3.1  86:09.64 oracle                               

4273 oracle    25   0  627m  57m  56m R    8  3.0  84:38.20 oracle                               

22670 oracle    25   0  626m  50m  49m R    0  2.7  84:55.82 oracle    

一.  TOP前五行统计信息

统计信息区前五行是系统整体的统计信息。

1. 第一行是任务队列信息

同 uptime  命令的执行结果:

[root@localhost ~]# uptime

 13:22:30 up 8 min,  4 users,  load average: 0.14, 0.38, 0.25

其内容如下:

12:38:33
 当前时间
 
up 50days
 系统运行时间,格式为时:分
 
1 user
 当前登录用户数
 
load average: 0.06, 0.60, 0.48
 系统负载,即任务队列的平均长度。 三个数值分别为  1分钟、5分钟、15分钟前到现在的平均值。
 

2. 第二、三行为进程和CPU的信息

当有多个CPU时,这些内容可能会超过两行。内容如下:

Tasks: 29 total
 进程总数
 
1 running
 正在运行的进程数
 
28 sleeping
 睡眠的进程数
 
0 stopped
 停止的进程数
 
0 zombie
 僵尸进程数
 
Cpu(s): 0.3% us
 用户空间占用CPU百分比
 
1.0% sy
 内核空间占用CPU百分比
 
0.0% ni
 用户进程空间内改变过优先级的进程占用CPU百分比
 
98.7% id
 空闲CPU百分比
 
0.0% wa
 等待输入输出的CPU时间百分比
 
0.0% hi
 
0.0% si
 

3. 第四五行为内存信息。

内容如下:

Mem: 191272k total
 物理内存总量
 
173656k used
 使用的物理内存总量
 
17616k free
 空闲内存总量
 
22052k buffers
 用作内核缓存的内存量
 
Swap: 192772k total
 交换区总量
 
0k used
 使用的交换区总量
 
192772k free
 空闲交换区总量
 
123988k cached
 缓冲的交换区总量。 内存中的内容被换出到交换区,而后又被换入到内存,但使用过的交换区尚未被覆盖, 该数值即为这些内容已存在于内存中的交换区的大小。相应的内存再次被换出时可不必再对交换区写入。
 

二.  进程信息

列名
 含义
 
PID
 进程id
 
PPID
 父进程id
 
RUSER
 Real user name
 
UID
 进程所有者的用户id
 
USER
 进程所有者的用户名
 
GROUP
 进程所有者的组名
 
TTY
 启动进程的终端名。不是从终端启动的进程则显示为 ?
 
PR
 优先级
 
NI
 nice值。负值表示高优先级,正值表示低优先级
 
P
 最后使用的CPU,仅在多CPU环境下有意义
 
%CPU
 上次更新到现在的CPU时间占用百分比
 
TIME
 进程使用的CPU时间总计,单位秒
 
TIME+
 进程使用的CPU时间总计,单位1/100秒
 
%MEM
 进程使用的物理内存百分比
 
VIRT
 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
 
SWAP
 进程使用的虚拟内存中,被换出的大小,单位kb。
 
RES
 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
 
CODE
 可执行代码占用的物理内存大小,单位kb
 
DATA
 可执行代码以外的部分(数据段+栈)占用的物理内存大小,单位kb
 
SHR
 共享内存大小,单位kb
 
nFLT
 页面错误次数
 
nDRT
 最后一次写入到现在,被修改过的页面数。
 
S
 进程状态。
            D=不可中断的睡眠状态
            R=运行
            S=睡眠
            T=跟踪/停止
            Z=僵尸进程
 
COMMAND
 命令名/命令行
 
WCHAN
 若该进程在睡眠,则显示睡眠中的系统函数名
 
Flags
 任务标志,参考 sched.h
 

top 的man 命令解释如下:

    Listed below are top's available fields.  They are always associated with the  letter  shown,  regardless  of the position you may have established for them with the 'o' (Order fields) interactive command.Any field is selectable as the sort field, and you control whether they are  sorted high-to-low  or  low-to-high.   For  additional  information on sort provisions see  topic 3c. TASK Area Commands.

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  oroutput.   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 'Irix mode' 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.

l: TIME  --  CPU Time

       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 additional information regarding this mode.

m: TIME+  --  CPU Time, hundredths

       The same as 'TIME', but reflecting more granularity through hundredths of a sec          ond.

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

       VIRT = SWAP + RES.

p: SWAP  --  Swapped size (kb)

       The swapped out portion of a task's total virtual memory image.

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 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  is not  currently  present  in  its address space.  A major page fault is when disk access is involved in making that page available.

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  parentheses, 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 officially documented in <linux/sched.h>.  Less formal documentation can also be  found  on the 'Fields select' and 'Order fields' screens.

       默认情况下仅显示比较重要的  PID、USER、PR、NI、VIRT、RES、SHR、S、%CPU、%MEM、TIME+、COMMAND  列。

2.1 用快捷键更改显示内容。
(1)更改显示内容通过 f键可以选择显示的内容。

       按 f 键之后会显示列的列表,按 a-z  即可显示或隐藏对应的列,最后按回车键确定。

(2)按o键可以改变列的显示顺序。

       按小写的 a-z 可以将相应的列向右移动,而大写的 A-Z  可以将相应的列向左移动。最后按回车键确定。

       按大写的 F 或 O 键,然后按 a-z 可以将进程按照相应的列进行排序。而大写的  R 键可以将当前的排序倒转。

       设置完按回车返回界面。

三.  命令使用

详细内容可以参考MAN 帮助文档。这里列举部分内容:

命令格式:

top [-] [d] [p] [q] [c] [C] [S]    [n]

参数说明:

d:  指定每两次屏幕信息刷新之间的时间间隔。当然用户可以使用s交互命令来改变之。

p:  通过指定监控进程ID来仅仅监控某个进程的状态。

q:该选项将使top没有任何延迟的进行刷新。如果调用程序有超级用户权限,那么top将以尽可能高的优先级运行。

S: 指定累计模式

s : 使top命令在安全模式中运行。这将去除交互命令所带来的潜在危险。

i:  使top不显示任何闲置或者僵死进程。

c:  显示整个命令行而不只是显示命令名

在top命令的显示窗口,我们还可以输入以下字母,进行一些交互:

帮助文档如下:

Help for Interactive Commands - procps version 3.2.7

Window 1:Def: Cumulative mode Off.  System: Delay 4.0 secs; Secure mode Off.

  Z,B       Global: 'Z' change color mappings; 'B' disable/enable bold

  l,t,m     Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info

  1,I       Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode

  f,o     . Fields/Columns: 'f' add or remove; 'o' change display order

  F or O  . Select sort field

  <,>     . Move sort field: '<' next col left; '>' next col right

  R,H     . Toggle: 'R' normal/reverse sort; 'H' show threads

  c,i,S   . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time

  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks

  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')

  u       . Show specific user only

  n or #  . Set maximum tasks displayed

  k,r       Manipulate tasks: 'k' kill; 'r' renice

  d or s    Set update interval

  W         Write configuration file

  q         Quit

          ( commands shown with '.' require a visible task display window )

Press 'h' or '?' for help with Windows,

h或者?  : 显示帮助画面,给出一些简短的命令总结说明。

k  :终止一个进程。系统将提示用户输入需要终止的进程PID,以及需要发送给该进程什么样的信号。一般的终止进程可以使用15信号;如果不能正常结束那就使用信号9强制结束该进程。默认值是信号15。在安全模式中此命令被屏蔽。

i:忽略闲置和僵死进程。这是一个开关式命令。

q:  退出程序。

r:  重新安排一个进程的优先级别。系统提示用户输入需要改变的进程PID以及需要设置的进程优先级值。输入一个正值将使优先级降低,反之则可以使该进程拥有更高的优先权。默认值是10。

S:切换到累计模式。

s :  改变两次刷新之间的延迟时间。系统将提示用户输入新的时间,单位为s。如果有小数,就换算成ms。输入0值则系统将不断刷新,默认值是5 s。需要注意的是如果设置太小的时间,很可能会引起不断刷新,从而根本来不及看清显示的情况,而且系统负载也会大大增加。

f或者F :从当前显示中添加或者删除项目。

o或者O  :改变显示项目的顺序。

l: 切换显示平均负载和启动时间信息。即显示影藏第一行

m: 切换显示内存信息。即显示影藏内存行

t : 切换显示进程和CPU状态信息。即显示影藏CPU行

c:  切换显示命令名称和完整命令行。 显示完整的命令。 这个功能很有用。

M : 根据驻留内存大小进行排序。

P:根据CPU使用百分比大小进行排序。

T: 根据时间/累计时间进行排序。

W:  将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。

 

Linux系统出现了性能问题,一般我们可以通过top、iostat、free、vmstat等命令来查看初步定位问题。其中iostat可以给我们提供丰富的IO状态数据。

基本使用

$iostat -d -k 1 10
参数 -d 表示,显示设备(磁盘)使用状态;-k某些使用block为单位的列强制使用Kilobytes为单位;1 10表示,数据显示每隔1秒刷新一次,共显示10次。

 

# iostat -x 1 10
Linux 2.6.18-92.el5xen    02/03/2009
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.10    0.00    4.82   39.54    0.07   54.46
Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     3.50  0.40  2.50     5.60    48.00    18.48     0.00    0.97   0.97   0.28
sdb               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sdc               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sdd               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sde               0.00     0.10  0.30  0.20     2.40     2.40     9.60     0.00    1.60   1.60   0.08
sdf              17.40     0.50 102.00  0.20 12095.20     5.60   118.40     0.70    6.81   2.09  21.36
sdg             232.40     1.90 379.70  0.50 76451.20    19.20   201.13     4.94   13.78   2.45  93.16
rrqm/s:   每秒进行 merge 的读操作数目。即 delta(rmerge)/s
wrqm/s:  每秒进行 merge 的写操作数目。即 delta(wmerge)/s
r/s:           每秒完成的读 I/O 设备次数。即 delta(rio)/s
w/s:         每秒完成的写 I/O 设备次数。即 delta(wio)/s
rsec/s:    每秒读扇区数。即 delta(rsect)/s
wsec/s:  每秒写扇区数。即 delta(wsect)/s
rkB/s:      每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节。(需要计算)
wkB/s:    每秒写K字节数。是 wsect/s 的一半。(需要计算)
avgrq-sz: 平均每次设备I/O操作的数据大小 (扇区)。delta(rsect+wsect)/delta(rio+wio)
avgqu-sz: 平均I/O队列长度。即 delta(aveq)/s/1000 (因为aveq的单位为毫秒)。
await:    平均每次设备I/O操作的等待时间 (毫秒)。即 delta(ruse+wuse)/delta(rio+wio)
svctm:   平均每次设备I/O操作的服务时间 (毫秒)。即 delta(use)/delta(rio+wio)
%util:      一秒中有百分之多少的时间用于 I/O 操作,或者说一秒中有多少时间 I/O 队列是非空的。即 delta(use)/s/1000 (因为use的单位为毫秒)

如果 %util 接近 100%,说明产生的I/O请求太多,I/O系统已经满负荷,该磁盘
可能存在瓶颈。
idle小于70% IO压力就较大了,一般读取速度有较多的wait.

同时可以结合vmstat 查看查看b参数(等待资源的进程数)和wa参数(IO等待所占用的CPU时间的百分比,高过30%时IO压力高)

另外还可以参考
一般:
svctm < await (因为同时等待的请求的等待时间被重复计算了),
svctm的大小一般和磁盘性能有关:CPU/内存的负荷也会对其有影响,请求过多也会间接导致 svctm 的增加。
await: await的大小一般取决于服务时间(svctm) 以及 I/O 队列的长度和 I/O 请求的发出模式。
如果 svctm 比较接近 await,说明I/O 几乎没有等待时间;
如果 await 远大于 svctm,说明 I/O队列太长,应用得到的响应时间变慢,
如果响应时间超过了用户可以容许的范围,这时可以考虑更换更快的磁盘,调整内核 elevator算法,优化应用,或者升级 CPU。
队列长度(avgqu-sz)也可作为衡量系统 I/O 负荷的指标,但由于 avgqu-sz 是按照单位时间的平均值,所以不能反映瞬间的 I/O 洪水。

  别人一个不错的例子.(I/O 系统 vs. 超市排队)
举一个例子,我们在超市排队 checkout 时,怎么决定该去哪个交款台呢? 首当是看排的队人数,5个人总比20人要快吧?除了数人头,我们也常常看看前面人购买的东西多少,如果前面有个采购了一星期食品的大妈,那么可以考虑换个队排了。还有就是收银员的速度了,如果碰上了连钱都点不清楚的新手,那就有的等了。另外,时机也很重要,可能 5分钟前还人满为患的收款台,现在已是人去楼空,这时候交款可是很爽啊,当然,前提是那过去的 5 分钟里所做的事情比排队要有意义(不过我还没发现什么事情比排队还无聊的)。
I/O 系统也和超市排队有很多类似之处:
r/s+w/s 类似于交款人的总数
平均队列长度(avgqu-sz)类似于单位时间里平均排队人的个数
平均服务时间(svctm)类似于收银员的收款速度
平均等待时间(await)类似于平均每人的等待时间
平均I/O数据(avgrq-sz)类似于平均每人所买的东西多少
I/O 操作率 (%util)类似于收款台前有人排队的时间比例。
我们可以根据这些数据分析出 I/O 请求的模式,以及 I/O 的速度和响应时间。
下面是别人写的这个参数输出的分析
# iostat -x 1
avg-cpu:  %user   %nice    %sys   %idle
16.24    0.00    4.31   79.44
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
/dev/cciss/c0d0
0.00  44.90  1.02 27.55    8.16  579.59     4.08   289.80    20.57    22.35   78.21   5.00  14.29
/dev/cciss/c0d0p1
0.00  44.90  1.02 27.55    8.16  579.59     4.08   289.80    20.57    22.35   78.21   5.00  14.29
/dev/cciss/c0d0p2
0.00   0.00  0.00  0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
上面的 iostat 输出表明秒有 28.57 次设备 I/O 操作: 总IO(io)/s = r/s(读) +w/s(写) = 1.02+27.55 = 28.57 (次/秒) 其中写操作占了主体 (w:r = 27:1)。
平均每次设备 I/O 操作只需要 5ms 就可以完成,但每个 I/O 请求却需要等上 78ms,为什么? 因为发出的 I/O 请求太多 (每秒钟约 29 个),假设这些请求是同时发出的,那么平均等待时间可以这样计算:
平均等待时间 = 单个 I/O 服务时间 * ( 1 + 2 + ... + 请求总数-1) / 请求总数
应用到上面的例子: 平均等待时间 = 5ms * (1+2+...+28)/29 = 70ms,和 iostat 给出的78ms 的平均等待时间很接近。这反过来表明 I/O 是同时发起的。
每秒发出的 I/O 请求很多 (约 29 个),平均队列却不长 (只有 2 个 左右),这表明这 29 个请求的到来并不均匀,大部分时间 I/O 是空闲的。
一秒中有 14.29% 的时间 I/O 队列中是有请求的,也就是说,85.71% 的时间里 I/O 系统无事可做,所有 29 个 I/O 请求都在142毫秒之内处理掉了。
delta(ruse+wuse)/delta(io) = await = 78.21 => delta(ruse+wuse)/s=78.21 * delta(io)/s = 78.21*28.57 =2232.8,表明每秒内的I/O请求总共需要等待2232.8ms。所以平均队列长度应为 2232.8ms/1000ms = 2.23,而iostat 给出的平均队列长度 (avgqu-sz) 却为 22.35,为什么?! 因为 iostat 中有 bug,avgqu-sz值应为 2.23,而不是 22.35。

 

 

Input Output statistics (  iostat )

  iostat反映了终端、磁盘I/O情况和CPU活动。输出结果的第一行是从系统启动到现在为止的这段时间的结果,接下去的每一行是interval时

间段内的结果。Kernel里有一组计数器用来跟踪这些值。
  iostat的默认参数是tdc(terminal,  disk, and CPU)。如果任何其他的选项被指定,这个默认参数将被完全替代,例如,iostat -d将只反

映磁盘的统计结果。

语法:

基本语法: iostat  <options>;   interval  count

option - 让你指定所需信息的设备,像磁盘、cpu或者终端(-d , -c , -t  or -tdc ) 。x 选项给出了完整的统计结果(gives the extended

statistic)。

interval -  在两个samples之间的时间(秒)。

count  - 就是需要统计几次

例子:

$ iostat -xtc 5 2
                          extended disk statistics       tty         cpu
     disk r/s  w/s Kr/s Kw/s wait actv svc_t  %w  %b  tin tout us sy wt id
     sd0   2.6 3.0 20.7 22.7 0.1  0.2  59.2   6   19   0   84  3  85 11 0
     sd1   4.2 1.0 33.5  8.0 0.0  0.2  47.2   2   23
     sd2   0.0 0.0  0.0  0.0 0.0  0.0   0.0   0    0
     sd3  10.2 1.6 51.4 12.8 0.1  0.3  31.2   3   31


     The fields have the following meanings:

      disk    name of the disk
      r/s     reads per second
      w/s     writes per second
      Kr/s    kilobytes read per second
      Kw/s    kilobytes written per second
      wait    average number of transactions waiting for service (Q length)
      actv    average number of transactions  actively 
              being serviced (removed  from  the
              queue but not yet
              completed)
      %w      percent of time there are transactions  waiting
              for service (queue non-empty)
      %b      percent of time the disk is busy  (transactions
                  in progress)

 


Results and Solutions:

从iostat输出结果中需要注意的值:

Reads/writes  per second (r/s , w/s)
Percentage busy (%b)
Service time (svc_t)

如果磁盘显示长时间的高reads/writes,并且磁盘的percentage busy (%b)也远大于5%,同时average service time  (svc_t)也远大于30

milliseconds,这以下的措施需要被执行:
1.)调整应用,令其使用磁盘i/o更加有效率,可以通过修改磁盘队列、使用应用服务器的cache

2.)将文件系统分布到2个或多个磁盘上,并使用volume manager/disksuite的条带化特点

3.) 增加系统参数值,如inode cache  , ufs_ninode。Increase the system parameter values for  inode cache  , ufs_ninode ,  which

is  Number of inodes to be held in memory. Inodes are cached globally (for UFS), not on a per-file system basis 

4.) 将文件系统移到更快的磁盘/控制器,或者用更好的设备来代替

vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存、进程、CPU活动进行监控。他是对系统的整体情况进行统计,不足之处是无法对某个进程进行深入分析。通常使用vmstat 5 5(表示在5秒时间内进行5次采样)命令测试。将得到一个数据汇总他能够反映真正的系统情况。
#vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b   swpd   free   buff cache   si   so    bi    bo   in    cs us sy id wa
1 0 62792   3460   9116 88092    6   30   189    89 1061   569 17 28 54 2
0 0 62792   3400   9124 88092    0    00    14 884   434 4 14 81 0
0 0 62792   3400   9132 88092    0    00    14 877   424 4 15 81 0
1 0 62792   3400   9140 88092    0    00    14 868   418 6 20 74 0
1 0 62792   3400   9148 88092    0    00    15 847   400 9 25 67 0
Linux 内存监控vmstat命令输出分成六个部分:


(1)进程procs:
r:在运行队列中等待的进程数 。
b:在等待io的进程数 。


(2)Linux 内存监控内存memoy:
swpd:现时可用的交换内存(单位KB)。
free:空闲的内存(单位KB)。
buff: 缓冲去中的内存数(单位:KB)。
cache:被用来做为高速缓存的内存数(单位:KB)。


(3) Linux 内存监控swap交换页面
si: 从磁盘交换到内存的交换页数量,单位:KB/秒。
so: 从内存交换到磁盘的交换页数量,单位:KB/秒。


(4)Linux 内存监控 io块设备:
bi: 发送到块设备的块数,单位:块/秒。
bo: 从块设备接收到的块数,单位:块/秒。


(5)Linux 内存监控system系统:
in: 每秒的中断数,包括时钟中断。
cs: 每秒的环境(上下文)转换次数。


(6)Linux 内存监控cpu中央处理器:
cs:用户进程使用的时间 。以百分比表示。
sy:系统进程使用的时间。 以百分比表示。
id:中央处理器的空闲时间 。以百分比表示。


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

 

free命令用来显示内存使用情况。display information about free and used memory on the system。

常用参数
b 以字节为单位显示。
-k 以K字节为单位显示。默认显示。
-m 以兆字节为单位显示。

 

-s <seconds> 每隔多少秒重复执行。可编写一个脚本用于监控。

使用示例
示例一
[root@sunrise root]# free
                    total        used        free     shared    buffers     cached
Mem:       4091428    4073120      18308          0     112784    2564792
-/+ buffers/cache:    1395544    2695884
Swap:      8385888          0    8385888
[root@sunrise root]#

 

 

数值的单位是KBytes。


Mem开头的行:

total是指内存总数。比如这台机器4G内存,实际上已经扣除掉了作为显存的部分。

used是指操作系统已经使用的内存数。这部分既包括操作系统本身使用的部分,也包括应用程序已经使用的部分,还包括缓存的部分。

free是指操作系统还没有使用的内存数。我们通常看到这部分比较小。

shared已经废弃不用,总是显示0。

buffers和cached是指作为缓存的内存数。


-/+ buffers/cache开头的行:(重点看这行)

used列是指应用程序总共使用的内存数。等于Mem.used-Mem.buffers-Mem.cached。

free列是指应用程序还未使用的内存数。这个数据才是我们需要关注的空闲可用内存数。等于Mem.free+Mem.buffers+Mem.cached。

如果此行中free列的数据太小,那么就需要优化程序或者增加物理内存了。

 

示例二
[root@bbqztweb root]# free -s 60
             total       used       free     shared    buffers     cached
Mem:       1016532     996320      20212          0      97964     166716
-/+ buffers/cache:     731640     284892
Swap:      2040244     281544    1758700

             total       used       free     shared    buffers     cached
Mem:       1016532     996328      20204          0      97964     166724
-/+ buffers/cache:     731640     284892
Swap:      2040244     281544    1758700

             total       used       free     shared    buffers     cached
Mem:       1016532     996460      20072          0      97964     166724
-/+ buffers/cache:     731772     284760
Swap:      2040244     281544    1758700

             total       used       free     shared    buffers     cached
Mem:       1016532     996316      20216          0      97964     166740
-/+ buffers/cache:     731612     284920
Swap:      2040244     281544    1758700


[root@bbqztweb root]#

 

示例三
free命令实际上是根据/proc/meminfo生成的。-/+ buffers/cache:这行是计算出来的。

[root@bbqztweb root]# free -b; cat /proc/meminfo
             total       used       free     shared    buffers     cached
Mem:    1040928768 1017909248   23019520          0  100220928  172040192
-/+ buffers/cache:  745648128  295280640
Swap:   2089209856  288301056 1800908800
        total:    used:    free:  shared: buffers:  cached:
Mem:  1040928768 1017909248 23019520        0 100220928 371302400
Swap: 2089209856 288301056 1800908800
MemTotal:      1016532 kB
MemFree:         22480 kB
MemShared:           0 kB
Buffers:         97872 kB
Cached:         168008 kB
SwapCached:     194592 kB
Active:         667076 kB
ActiveAnon:     510760 kB
ActiveCache:    156316 kB
Inact_dirty:    125964 kB
Inact_laundry:   20508 kB
Inact_clean:     17308 kB
Inact_target:   166168 kB
HighTotal:      122044 kB
HighFree:         5564 kB
LowTotal:       894488 kB
LowFree:         16916 kB
SwapTotal:     2040244 kB
SwapFree:      1758700 kB
CommitLimit:   2548508 kB
Committed_AS:  1063004 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     2048 kB
[root@bbqztweb root]#

 

示例四
[root@bbqztweb root]# free -b -s 1 | grep 'buffers/cache:'
-/+ buffers/cache:  745574400  295354368
-/+ buffers/cache:  745574400  295354368
-/+ buffers/cache:  745574400  295354368
Ctrl+C
[root@bbqztweb root]# free -b -s 1 | grep 'buffers/cache:' | awk '{print $4}'
Ctrl+C

怪哉,没有显示任何输出。但下面的是可以输出东西的,难道管道线多了就不灵了?why?

[root@bbqztweb root]# free -b -s 1 | awk '{print $4}'                        
shared
22200320
295211008
1800908800

shared
22200320
295211008
1800908800


Netstat命令用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。
       在Internet RFC标准中,Netstat的定义是: Netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告。

 

检查2222 端口的相关信息:

[root@singledb ~]# netstat -an |grep 2222

tcp        0      0 :::2222                     :::*                        LISTEN    

tcp        0      0 ::ffff:192.168.3.200:2222   ::ffff:192.168.3.115:53516  ESTABLISHED

     

 

该命令的帮助文档如下:

[root@singledb ~]# netstat -h

usage: netstat [-veenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}

       netstat [-vnNcaeol] [<Socket> ...]

       netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [delay]

 

        -r, --route                display routing table

        -I, --interfaces=[<Iface>] display interface table for <Iface>

        -i, --interfaces           display interface table

        -g, --groups               display multicast group memberships

        -s, --statistics           display networking statistics (like SNMP)

        -M, --masquerade           display masqueraded connections

        -v, --verbose              be verbose

        -n, --numeric              don't resolve names

        --numeric-hosts            don't resolve host names

        --numeric-ports            don't resolve port names

        --numeric-users            don't resolve user names

        -N, --symbolic             resolve hardware names

        -e, --extend               display other/more information

        -p, --programs             display PID/Program name for sockets

        -c, --continuous           continuous listing

        -l, --listening            display listening server sockets

        -a, --all, --listening     display all sockets (default: connected)

        -o, --timers               display timers

        -F, --fib            display Forwarding Information Base (default)

        -C, --cache                display routing cache instead of FIB

        -T, --notrim               stop trimming long addresses

        -Z, --context              display SELinux security context for sockets

 

  <Iface>: Name of interface to monitor/list.

  <Socket>={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom

  <AF>=Use '-A <af>' or '--<af>'; default: inet

  List of possible address families (which support routing):

    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)

    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)

    x25 (CCITT X.25)

     

       在上面的命令里讲了一个参数的意思。 如果想查看更详细的内容,可以使用man命令。 这个可以显示的更详细。

 

 

Netstat的一些常用选项 :

       netstat -s: 按照各个协议分别显示其统计数据。

       netstat -r: 显示关于路由表的信息。

netstat -a: 显示一个所有的有效连接信息列表.

       netstat -n: 显示所有已建立的有效连接。

 

 

[root@singledb ~]# netstat -a

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address               Foreign Address             State    

tcp        0      0 localhost.localdomain:2208  *:*                         LISTEN       

tcp        0      0 192.168.122.1:domain        *:*                         LISTEN     

tcp        0      0 ::ffff:192.168.3.200:ssh    ::ffff:192.168.3.115:51710  ESTABLISHED

tcp        0      0 ::ffff:192.16:rockwell-csp2 ::ffff:192.168.3.115:53516  ESTABLISHED

udp        0      0 *:48902                     *:*                                   

udp        0      0 192.168.122.1:domain        *:*                                                                     

udp        0      0 *:mdns                      *:*                                   

Active UNIX domain sockets (servers and established)

Proto RefCnt Flags       Type       State         I-Node Path

unix  2      [ ACC ]     STREAM     LISTENING     6166   @ISCSIADM_ABSTRACT_NAMESPACE

unix  28     [ ]         DGRAM                    6709   /dev/log

unix  2      [ ACC ]     STREAM     LISTENING     9022   /dev/gpmctl

unix  2      [ ACC ]     STREAM     LISTENING     6702   /var/run/audispd_events

 

以其中一条做说明:

tcp        0      0 ::ffff:192.168.3.200:ssh    ::ffff:192.168.3.115:51710  ESTABLISHED

 

协议(Proto):TCP,指是传输层通讯协议。

有关TCP, 可以参考Blog:

       网络七层协议 说明

       http://blog.csdn.net/tianlesoftware/archive/2010/11/16/6012976.aspx

 

Local  Address:::ffff:192.168.3.200:ssh,本地的IP地址,和用于连接的端口, 这里写成ssh了。 指的是SSH 端口。 

Foreign Address: ffff:192.168.3.115:51710, 远程机器的的IP地址和连接的端口。

State:ESTABLISHED。 连接状态。可有一下几种状态:

                     LISTEN  :在监听状态中。 

                     ESTABLISHED:已建立联机的联机情况。

                     TIME_WAIT:该联机在目前已经是等待的状态。

 

 

[root@singledb ~]# netstat -n

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State    

tcp        0    132 ::ffff:192.168.3.200:22     ::ffff:192.168.3.115:51710  ESTABLISHED

tcp        0      0 ::ffff:192.168.3.200:2222   ::ffff:192.168.3.115:53516  ESTABLISHED

--刚才这里显示的SSH。 现在显示成对应的端口了。

Active UNIX domain sockets (w/o servers)

Proto RefCnt Flags       Type       State         I-Node Path

unix  28     [ ]         DGRAM                    6709   /dev/log

unix  2      [ ]         DGRAM                    1413   @/org/kernel/udev/udevd

unix  2      [ ]         DGRAM                    7379   @/org/freedesktop/hal/udev_event

unix  2      [ ]         DGRAM                    15309

unix  2      [ ]         DGRAM                    13877

unix  2      [ ]         DGRAM                    13005

unix  3      [ ]         STREAM     CONNECTED     12935

unix  3      [ ]         STREAM     CONNECTED     12934

unix  2      [ ]         DGRAM                    12930

 

 

Netstat -n基本上是-a参数的数字形式,-a 和 -n 是最常用的两个,其中

       (1)-n 显示用数字化主机名,即IP地址

       (2)-n 只显示TCP连接

 

 

[root@singledb ~]# netstat -r

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

192.168.3.0     *               255.255.255.0   U         0 0          0 bond0

192.168.122.0   *               255.255.255.0   U         0 0          0 virbr0

169.254.0.0     *               255.255.0.0     U         0 0          0 bond0

default         192.168.3.1     0.0.0.0         UG        0 0          0 bond0  

 

 

[root@singledb ~]# netstat -s

Ip:

    63105 total packets received

    0 forwarded

    0 incoming packets discarded

    41834 incoming packets delivered

    33322 requests sent out

Icmp:

    1377 ICMP messages received

    0 input ICMP message failed.

    ICMP input histogram:

        destination unreachable: 1377

    1377 ICMP messages sent

    0 ICMP messages failed

    ICMP output histogram:

        destination unreachable: 1377

IcmpMsg:

        InType3: 1377

        OutType3: 1377

Tcp:

    147 active connections openings

    33 passive connection openings

    0 failed connection attempts

    0 connection resets received

    2 connections established

    31684 segments received

    31347 segments send out

    393 segments retransmited

    0 bad segments received.

    0 resets sent

Udp:

    132 packets received

    1 packets to unknown port received.

    0 packet receive errors

    201 packets sent

TcpExt:

    23 TCP sockets finished time wait in fast timer

    7032 delayed acks sent

    10 delayed acks further delayed because of locked socket

    Quick ack mode was activated 8137 times

    2 packets directly queued to recvmsg prequeue.

    2 packets directly received from prequeue

    3496 packets header predicted

    2325 acknowledgments not containing data received

    7805 predicted acknowledgments

    6 times recovered from packet loss due to SACK data

    TCPDSACKUndo: 3

    12 congestion windows recovered after partial ack

    3 TCP data loss events

    5 fast retransmits

    3 retransmits in slow start

    137 other TCP timeouts

    2 sack retransmits failed

    8137 DSACKs sent for old packets

    24 DSACKs received

IpExt:

    InMcastPkts: 36

    OutMcastPkts: 40

    InBcastPkts: 8617

[root@singledb ~]#


 


TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最“敏感”的任务列表.该命令可以按CPU使用.内存使用和执行时间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定.
top - 12:38:33 up 50 days, 23:15,  7 users,  load average: 60.58, 61.14, 61.22

Tasks: 203 total,  60 running, 139 sleeping,   4 stopped,   0 zombie

Cpu(s)  : 27.0%us, 73.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:   1939780k total,  1375280k used,   564500k free,   109680k buffers

Swap:  4401800k total,   497456k used,  3904344k free,   848712k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                               

4338 oracle    25   0  627m 209m 207m R    0 11.0 297:14.76 oracle                               

4267 oracle    25   0  626m 144m 143m R    6  7.6  89:16.62 oracle                               

3458 oracle    25   0  672m 133m 124m R    0  7.1   1283:08 oracle                               

3478 oracle    25   0  672m 124m 115m R    0  6.6   1272:30 oracle                               

3395 oracle    25   0  672m 122m 113m R    0  6.5   1270:03 oracle                                

3480 oracle    25   0  672m 122m 109m R    8  6.4   1274:13 oracle                               

3399 oracle    25   0  672m 121m 110m R    0  6.4   1279:37 oracle                               

4261 oracle    25   0  634m 100m  99m R    0  5.3  86:13.90 oracle                               

25737 oracle    25   0  632m  81m  74m R    0  4.3 272:35.42 oracle                               

7072 oracle    25   0  626m  72m  71m R    0  3.8   6:35.68 oracle                               

16073 oracle    25   0  630m  68m  63m R    8  3.6 175:20.36 oracle                               

16140 oracle    25   0  630m  66m  60m R    0  3.5 175:13.42 oracle                               

16122 oracle    25   0  630m  66m  60m R    0  3.5 176:47.73 oracle                               

  786 oracle    25   0  627m  63m  63m R    0  3.4   1:54.93 oracle                               

4271 oracle    25   0  627m  59m  58m R    8  3.1  86:09.64 oracle                               

4273 oracle    25   0  627m  57m  56m R    8  3.0  84:38.20 oracle                               

22670 oracle    25   0  626m  50m  49m R    0  2.7  84:55.82 oracle    

一.  TOP前五行统计信息

统计信息区前五行是系统整体的统计信息。

1. 第一行是任务队列信息

同 uptime  命令的执行结果:

[root@localhost ~]# uptime

 13:22:30 up 8 min,  4 users,  load average: 0.14, 0.38, 0.25

其内容如下:

12:38:33
 当前时间
 
up 50days
 系统运行时间,格式为时:分
 
1 user
 当前登录用户数
 
load average: 0.06, 0.60, 0.48
 系统负载,即任务队列的平均长度。 三个数值分别为  1分钟、5分钟、15分钟前到现在的平均值。
 

2. 第二、三行为进程和CPU的信息

当有多个CPU时,这些内容可能会超过两行。内容如下:

Tasks: 29 total
 进程总数
 
1 running
 正在运行的进程数
 
28 sleeping
 睡眠的进程数
 
0 stopped
 停止的进程数
 
0 zombie
 僵尸进程数
 
Cpu(s): 0.3% us
 用户空间占用CPU百分比
 
1.0% sy
 内核空间占用CPU百分比
 
0.0% ni
 用户进程空间内改变过优先级的进程占用CPU百分比
 
98.7% id
 空闲CPU百分比
 
0.0% wa
 等待输入输出的CPU时间百分比
 
0.0% hi
 
0.0% si
 

3. 第四五行为内存信息。

内容如下:

Mem: 191272k total
 物理内存总量
 
173656k used
 使用的物理内存总量
 
17616k free
 空闲内存总量
 
22052k buffers
 用作内核缓存的内存量
 
Swap: 192772k total
 交换区总量
 
0k used
 使用的交换区总量
 
192772k free
 空闲交换区总量
 
123988k cached
 缓冲的交换区总量。 内存中的内容被换出到交换区,而后又被换入到内存,但使用过的交换区尚未被覆盖, 该数值即为这些内容已存在于内存中的交换区的大小。相应的内存再次被换出时可不必再对交换区写入。
 

二.  进程信息

列名
 含义
 
PID
 进程id
 
PPID
 父进程id
 
RUSER
 Real user name
 
UID
 进程所有者的用户id
 
USER
 进程所有者的用户名
 
GROUP
 进程所有者的组名
 
TTY
 启动进程的终端名。不是从终端启动的进程则显示为 ?
 
PR
 优先级
 
NI
 nice值。负值表示高优先级,正值表示低优先级
 
P
 最后使用的CPU,仅在多CPU环境下有意义
 
%CPU
 上次更新到现在的CPU时间占用百分比
 
TIME
 进程使用的CPU时间总计,单位秒
 
TIME+
 进程使用的CPU时间总计,单位1/100秒
 
%MEM
 进程使用的物理内存百分比
 
VIRT
 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
 
SWAP
 进程使用的虚拟内存中,被换出的大小,单位kb。
 
RES
 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
 
CODE
 可执行代码占用的物理内存大小,单位kb
 
DATA
 可执行代码以外的部分(数据段+栈)占用的物理内存大小,单位kb
 
SHR
 共享内存大小,单位kb
 
nFLT
 页面错误次数
 
nDRT
 最后一次写入到现在,被修改过的页面数。
 
S
 进程状态。
            D=不可中断的睡眠状态
            R=运行
            S=睡眠
            T=跟踪/停止
            Z=僵尸进程
 
COMMAND
 命令名/命令行
 
WCHAN
 若该进程在睡眠,则显示睡眠中的系统函数名
 
Flags
 任务标志,参考 sched.h
 

top 的man 命令解释如下:

    Listed below are top's available fields.  They are always associated with the  letter  shown,  regardless  of the position you may have established for them with the 'o' (Order fields) interactive command.Any field is selectable as the sort field, and you control whether they are  sorted high-to-low  or  low-to-high.   For  additional  information on sort provisions see  topic 3c. TASK Area Commands.

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  oroutput.   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 'Irix mode' 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.

l: TIME  --  CPU Time

       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 additional information regarding this mode.

m: TIME+  --  CPU Time, hundredths

       The same as 'TIME', but reflecting more granularity through hundredths of a sec          ond.

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

       VIRT = SWAP + RES.

p: SWAP  --  Swapped size (kb)

       The swapped out portion of a task's total virtual memory image.

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 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  is not  currently  present  in  its address space.  A major page fault is when disk access is involved in making that page available.

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  parentheses, 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 officially documented in <linux/sched.h>.  Less formal documentation can also be  found  on the 'Fields select' and 'Order fields' screens.

       默认情况下仅显示比较重要的  PID、USER、PR、NI、VIRT、RES、SHR、S、%CPU、%MEM、TIME+、COMMAND  列。

2.1 用快捷键更改显示内容。
(1)更改显示内容通过 f键可以选择显示的内容。

       按 f 键之后会显示列的列表,按 a-z  即可显示或隐藏对应的列,最后按回车键确定。

(2)按o键可以改变列的显示顺序。

       按小写的 a-z 可以将相应的列向右移动,而大写的 A-Z  可以将相应的列向左移动。最后按回车键确定。

       按大写的 F 或 O 键,然后按 a-z 可以将进程按照相应的列进行排序。而大写的  R 键可以将当前的排序倒转。

       设置完按回车返回界面。

三.  命令使用

详细内容可以参考MAN 帮助文档。这里列举部分内容:

命令格式:

top [-] [d] [p] [q] [c] [C] [S]    [n]

参数说明:

d:  指定每两次屏幕信息刷新之间的时间间隔。当然用户可以使用s交互命令来改变之。

p:  通过指定监控进程ID来仅仅监控某个进程的状态。

q:该选项将使top没有任何延迟的进行刷新。如果调用程序有超级用户权限,那么top将以尽可能高的优先级运行。

S: 指定累计模式

s : 使top命令在安全模式中运行。这将去除交互命令所带来的潜在危险。

i:  使top不显示任何闲置或者僵死进程。

c:  显示整个命令行而不只是显示命令名

在top命令的显示窗口,我们还可以输入以下字母,进行一些交互:

帮助文档如下:

Help for Interactive Commands - procps version 3.2.7

Window 1:Def: Cumulative mode Off.  System: Delay 4.0 secs; Secure mode Off.

  Z,B       Global: 'Z' change color mappings; 'B' disable/enable bold

  l,t,m     Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info

  1,I       Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode

  f,o     . Fields/Columns: 'f' add or remove; 'o' change display order

  F or O  . Select sort field

  <,>     . Move sort field: '<' next col left; '>' next col right

  R,H     . Toggle: 'R' normal/reverse sort; 'H' show threads

  c,i,S   . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time

  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks

  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')

  u       . Show specific user only

  n or #  . Set maximum tasks displayed

  k,r       Manipulate tasks: 'k' kill; 'r' renice

  d or s    Set update interval

  W         Write configuration file

  q         Quit

          ( commands shown with '.' require a visible task display window )

Press 'h' or '?' for help with Windows,

h或者?  : 显示帮助画面,给出一些简短的命令总结说明。

k  :终止一个进程。系统将提示用户输入需要终止的进程PID,以及需要发送给该进程什么样的信号。一般的终止进程可以使用15信号;如果不能正常结束那就使用信号9强制结束该进程。默认值是信号15。在安全模式中此命令被屏蔽。

i:忽略闲置和僵死进程。这是一个开关式命令。

q:  退出程序。

r:  重新安排一个进程的优先级别。系统提示用户输入需要改变的进程PID以及需要设置的进程优先级值。输入一个正值将使优先级降低,反之则可以使该进程拥有更高的优先权。默认值是10。

S:切换到累计模式。

s :  改变两次刷新之间的延迟时间。系统将提示用户输入新的时间,单位为s。如果有小数,就换算成ms。输入0值则系统将不断刷新,默认值是5 s。需要注意的是如果设置太小的时间,很可能会引起不断刷新,从而根本来不及看清显示的情况,而且系统负载也会大大增加。

f或者F :从当前显示中添加或者删除项目。

o或者O  :改变显示项目的顺序。

l: 切换显示平均负载和启动时间信息。即显示影藏第一行

m: 切换显示内存信息。即显示影藏内存行

t : 切换显示进程和CPU状态信息。即显示影藏CPU行

c:  切换显示命令名称和完整命令行。 显示完整的命令。 这个功能很有用。

M : 根据驻留内存大小进行排序。

P:根据CPU使用百分比大小进行排序。

T: 根据时间/累计时间进行排序。

W:  将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。

 

Linux系统出现了性能问题,一般我们可以通过top、iostat、free、vmstat等命令来查看初步定位问题。其中iostat可以给我们提供丰富的IO状态数据。

基本使用

$iostat -d -k 1 10
参数 -d 表示,显示设备(磁盘)使用状态;-k某些使用block为单位的列强制使用Kilobytes为单位;1 10表示,数据显示每隔1秒刷新一次,共显示10次。

 

# iostat -x 1 10
Linux 2.6.18-92.el5xen    02/03/2009
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.10    0.00    4.82   39.54    0.07   54.46
Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     3.50  0.40  2.50     5.60    48.00    18.48     0.00    0.97   0.97   0.28
sdb               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sdc               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sdd               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sde               0.00     0.10  0.30  0.20     2.40     2.40     9.60     0.00    1.60   1.60   0.08
sdf              17.40     0.50 102.00  0.20 12095.20     5.60   118.40     0.70    6.81   2.09  21.36
sdg             232.40     1.90 379.70  0.50 76451.20    19.20   201.13     4.94   13.78   2.45  93.16
rrqm/s:   每秒进行 merge 的读操作数目。即 delta(rmerge)/s
wrqm/s:  每秒进行 merge 的写操作数目。即 delta(wmerge)/s
r/s:           每秒完成的读 I/O 设备次数。即 delta(rio)/s
w/s:         每秒完成的写 I/O 设备次数。即 delta(wio)/s
rsec/s:    每秒读扇区数。即 delta(rsect)/s
wsec/s:  每秒写扇区数。即 delta(wsect)/s
rkB/s:      每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节。(需要计算)
wkB/s:    每秒写K字节数。是 wsect/s 的一半。(需要计算)
avgrq-sz: 平均每次设备I/O操作的数据大小 (扇区)。delta(rsect+wsect)/delta(rio+wio)
avgqu-sz: 平均I/O队列长度。即 delta(aveq)/s/1000 (因为aveq的单位为毫秒)。
await:    平均每次设备I/O操作的等待时间 (毫秒)。即 delta(ruse+wuse)/delta(rio+wio)
svctm:   平均每次设备I/O操作的服务时间 (毫秒)。即 delta(use)/delta(rio+wio)
%util:      一秒中有百分之多少的时间用于 I/O 操作,或者说一秒中有多少时间 I/O 队列是非空的。即 delta(use)/s/1000 (因为use的单位为毫秒)

如果 %util 接近 100%,说明产生的I/O请求太多,I/O系统已经满负荷,该磁盘
可能存在瓶颈。
idle小于70% IO压力就较大了,一般读取速度有较多的wait.

同时可以结合vmstat 查看查看b参数(等待资源的进程数)和wa参数(IO等待所占用的CPU时间的百分比,高过30%时IO压力高)

另外还可以参考
一般:
svctm < await (因为同时等待的请求的等待时间被重复计算了),
svctm的大小一般和磁盘性能有关:CPU/内存的负荷也会对其有影响,请求过多也会间接导致 svctm 的增加。
await: await的大小一般取决于服务时间(svctm) 以及 I/O 队列的长度和 I/O 请求的发出模式。
如果 svctm 比较接近 await,说明I/O 几乎没有等待时间;
如果 await 远大于 svctm,说明 I/O队列太长,应用得到的响应时间变慢,
如果响应时间超过了用户可以容许的范围,这时可以考虑更换更快的磁盘,调整内核 elevator算法,优化应用,或者升级 CPU。
队列长度(avgqu-sz)也可作为衡量系统 I/O 负荷的指标,但由于 avgqu-sz 是按照单位时间的平均值,所以不能反映瞬间的 I/O 洪水。

  别人一个不错的例子.(I/O 系统 vs. 超市排队)
举一个例子,我们在超市排队 checkout 时,怎么决定该去哪个交款台呢? 首当是看排的队人数,5个人总比20人要快吧?除了数人头,我们也常常看看前面人购买的东西多少,如果前面有个采购了一星期食品的大妈,那么可以考虑换个队排了。还有就是收银员的速度了,如果碰上了连钱都点不清楚的新手,那就有的等了。另外,时机也很重要,可能 5分钟前还人满为患的收款台,现在已是人去楼空,这时候交款可是很爽啊,当然,前提是那过去的 5 分钟里所做的事情比排队要有意义(不过我还没发现什么事情比排队还无聊的)。
I/O 系统也和超市排队有很多类似之处:
r/s+w/s 类似于交款人的总数
平均队列长度(avgqu-sz)类似于单位时间里平均排队人的个数
平均服务时间(svctm)类似于收银员的收款速度
平均等待时间(await)类似于平均每人的等待时间
平均I/O数据(avgrq-sz)类似于平均每人所买的东西多少
I/O 操作率 (%util)类似于收款台前有人排队的时间比例。
我们可以根据这些数据分析出 I/O 请求的模式,以及 I/O 的速度和响应时间。
下面是别人写的这个参数输出的分析
# iostat -x 1
avg-cpu:  %user   %nice    %sys   %idle
16.24    0.00    4.31   79.44
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
/dev/cciss/c0d0
0.00  44.90  1.02 27.55    8.16  579.59     4.08   289.80    20.57    22.35   78.21   5.00  14.29
/dev/cciss/c0d0p1
0.00  44.90  1.02 27.55    8.16  579.59     4.08   289.80    20.57    22.35   78.21   5.00  14.29
/dev/cciss/c0d0p2
0.00   0.00  0.00  0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
上面的 iostat 输出表明秒有 28.57 次设备 I/O 操作: 总IO(io)/s = r/s(读) +w/s(写) = 1.02+27.55 = 28.57 (次/秒) 其中写操作占了主体 (w:r = 27:1)。
平均每次设备 I/O 操作只需要 5ms 就可以完成,但每个 I/O 请求却需要等上 78ms,为什么? 因为发出的 I/O 请求太多 (每秒钟约 29 个),假设这些请求是同时发出的,那么平均等待时间可以这样计算:
平均等待时间 = 单个 I/O 服务时间 * ( 1 + 2 + ... + 请求总数-1) / 请求总数
应用到上面的例子: 平均等待时间 = 5ms * (1+2+...+28)/29 = 70ms,和 iostat 给出的78ms 的平均等待时间很接近。这反过来表明 I/O 是同时发起的。
每秒发出的 I/O 请求很多 (约 29 个),平均队列却不长 (只有 2 个 左右),这表明这 29 个请求的到来并不均匀,大部分时间 I/O 是空闲的。
一秒中有 14.29% 的时间 I/O 队列中是有请求的,也就是说,85.71% 的时间里 I/O 系统无事可做,所有 29 个 I/O 请求都在142毫秒之内处理掉了。
delta(ruse+wuse)/delta(io) = await = 78.21 => delta(ruse+wuse)/s=78.21 * delta(io)/s = 78.21*28.57 =2232.8,表明每秒内的I/O请求总共需要等待2232.8ms。所以平均队列长度应为 2232.8ms/1000ms = 2.23,而iostat 给出的平均队列长度 (avgqu-sz) 却为 22.35,为什么?! 因为 iostat 中有 bug,avgqu-sz值应为 2.23,而不是 22.35。

 

 

Input Output statistics (  iostat )

  iostat反映了终端、磁盘I/O情况和CPU活动。输出结果的第一行是从系统启动到现在为止的这段时间的结果,接下去的每一行是interval时

间段内的结果。Kernel里有一组计数器用来跟踪这些值。
  iostat的默认参数是tdc(terminal,  disk, and CPU)。如果任何其他的选项被指定,这个默认参数将被完全替代,例如,iostat -d将只反

映磁盘的统计结果。

语法:

基本语法: iostat  <options>;   interval  count

option - 让你指定所需信息的设备,像磁盘、cpu或者终端(-d , -c , -t  or -tdc ) 。x 选项给出了完整的统计结果(gives the extended

statistic)。

interval -  在两个samples之间的时间(秒)。

count  - 就是需要统计几次

例子:

$ iostat -xtc 5 2
                          extended disk statistics       tty         cpu
     disk r/s  w/s Kr/s Kw/s wait actv svc_t  %w  %b  tin tout us sy wt id
     sd0   2.6 3.0 20.7 22.7 0.1  0.2  59.2   6   19   0   84  3  85 11 0
     sd1   4.2 1.0 33.5  8.0 0.0  0.2  47.2   2   23
     sd2   0.0 0.0  0.0  0.0 0.0  0.0   0.0   0    0
     sd3  10.2 1.6 51.4 12.8 0.1  0.3  31.2   3   31


     The fields have the following meanings:

      disk    name of the disk
      r/s     reads per second
      w/s     writes per second
      Kr/s    kilobytes read per second
      Kw/s    kilobytes written per second
      wait    average number of transactions waiting for service (Q length)
      actv    average number of transactions  actively 
              being serviced (removed  from  the
              queue but not yet
              completed)
      %w      percent of time there are transactions  waiting
              for service (queue non-empty)
      %b      percent of time the disk is busy  (transactions
                  in progress)

 


Results and Solutions:

从iostat输出结果中需要注意的值:

Reads/writes  per second (r/s , w/s)
Percentage busy (%b)
Service time (svc_t)

如果磁盘显示长时间的高reads/writes,并且磁盘的percentage busy (%b)也远大于5%,同时average service time  (svc_t)也远大于30

milliseconds,这以下的措施需要被执行:
1.)调整应用,令其使用磁盘i/o更加有效率,可以通过修改磁盘队列、使用应用服务器的cache

2.)将文件系统分布到2个或多个磁盘上,并使用volume manager/disksuite的条带化特点

3.) 增加系统参数值,如inode cache  , ufs_ninode。Increase the system parameter values for  inode cache  , ufs_ninode ,  which

is  Number of inodes to be held in memory. Inodes are cached globally (for UFS), not on a per-file system basis 

4.) 将文件系统移到更快的磁盘/控制器,或者用更好的设备来代替

vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存、进程、CPU活动进行监控。他是对系统的整体情况进行统计,不足之处是无法对某个进程进行深入分析。通常使用vmstat 5 5(表示在5秒时间内进行5次采样)命令测试。将得到一个数据汇总他能够反映真正的系统情况。
#vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b   swpd   free   buff cache   si   so    bi    bo   in    cs us sy id wa
1 0 62792   3460   9116 88092    6   30   189    89 1061   569 17 28 54 2
0 0 62792   3400   9124 88092    0    00    14 884   434 4 14 81 0
0 0 62792   3400   9132 88092    0    00    14 877   424 4 15 81 0
1 0 62792   3400   9140 88092    0    00    14 868   418 6 20 74 0
1 0 62792   3400   9148 88092    0    00    15 847   400 9 25 67 0
Linux 内存监控vmstat命令输出分成六个部分:


(1)进程procs:
r:在运行队列中等待的进程数 。
b:在等待io的进程数 。


(2)Linux 内存监控内存memoy:
swpd:现时可用的交换内存(单位KB)。
free:空闲的内存(单位KB)。
buff: 缓冲去中的内存数(单位:KB)。
cache:被用来做为高速缓存的内存数(单位:KB)。


(3) Linux 内存监控swap交换页面
si: 从磁盘交换到内存的交换页数量,单位:KB/秒。
so: 从内存交换到磁盘的交换页数量,单位:KB/秒。


(4)Linux 内存监控 io块设备:
bi: 发送到块设备的块数,单位:块/秒。
bo: 从块设备接收到的块数,单位:块/秒。


(5)Linux 内存监控system系统:
in: 每秒的中断数,包括时钟中断。
cs: 每秒的环境(上下文)转换次数。


(6)Linux 内存监控cpu中央处理器:
cs:用户进程使用的时间 。以百分比表示。
sy:系统进程使用的时间。 以百分比表示。
id:中央处理器的空闲时间 。以百分比表示。


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

 

free命令用来显示内存使用情况。display information about free and used memory on the system。

常用参数
b 以字节为单位显示。
-k 以K字节为单位显示。默认显示。
-m 以兆字节为单位显示。

 

-s <seconds> 每隔多少秒重复执行。可编写一个脚本用于监控。

使用示例
示例一
[root@sunrise root]# free
                    total        used        free     shared    buffers     cached
Mem:       4091428    4073120      18308          0     112784    2564792
-/+ buffers/cache:    1395544    2695884
Swap:      8385888          0    8385888
[root@sunrise root]#

 

 

数值的单位是KBytes。


Mem开头的行:

total是指内存总数。比如这台机器4G内存,实际上已经扣除掉了作为显存的部分。

used是指操作系统已经使用的内存数。这部分既包括操作系统本身使用的部分,也包括应用程序已经使用的部分,还包括缓存的部分。

free是指操作系统还没有使用的内存数。我们通常看到这部分比较小。

shared已经废弃不用,总是显示0。

buffers和cached是指作为缓存的内存数。


-/+ buffers/cache开头的行:(重点看这行)

used列是指应用程序总共使用的内存数。等于Mem.used-Mem.buffers-Mem.cached。

free列是指应用程序还未使用的内存数。这个数据才是我们需要关注的空闲可用内存数。等于Mem.free+Mem.buffers+Mem.cached。

如果此行中free列的数据太小,那么就需要优化程序或者增加物理内存了。

 

示例二
[root@bbqztweb root]# free -s 60
             total       used       free     shared    buffers     cached
Mem:       1016532     996320      20212          0      97964     166716
-/+ buffers/cache:     731640     284892
Swap:      2040244     281544    1758700

             total       used       free     shared    buffers     cached
Mem:       1016532     996328      20204          0      97964     166724
-/+ buffers/cache:     731640     284892
Swap:      2040244     281544    1758700

             total       used       free     shared    buffers     cached
Mem:       1016532     996460      20072          0      97964     166724
-/+ buffers/cache:     731772     284760
Swap:      2040244     281544    1758700

             total       used       free     shared    buffers     cached
Mem:       1016532     996316      20216          0      97964     166740
-/+ buffers/cache:     731612     284920
Swap:      2040244     281544    1758700


[root@bbqztweb root]#

 

示例三
free命令实际上是根据/proc/meminfo生成的。-/+ buffers/cache:这行是计算出来的。

[root@bbqztweb root]# free -b; cat /proc/meminfo
             total       used       free     shared    buffers     cached
Mem:    1040928768 1017909248   23019520          0  100220928  172040192
-/+ buffers/cache:  745648128  295280640
Swap:   2089209856  288301056 1800908800
        total:    used:    free:  shared: buffers:  cached:
Mem:  1040928768 1017909248 23019520        0 100220928 371302400
Swap: 2089209856 288301056 1800908800
MemTotal:      1016532 kB
MemFree:         22480 kB
MemShared:           0 kB
Buffers:         97872 kB
Cached:         168008 kB
SwapCached:     194592 kB
Active:         667076 kB
ActiveAnon:     510760 kB
ActiveCache:    156316 kB
Inact_dirty:    125964 kB
Inact_laundry:   20508 kB
Inact_clean:     17308 kB
Inact_target:   166168 kB
HighTotal:      122044 kB
HighFree:         5564 kB
LowTotal:       894488 kB
LowFree:         16916 kB
SwapTotal:     2040244 kB
SwapFree:      1758700 kB
CommitLimit:   2548508 kB
Committed_AS:  1063004 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     2048 kB
[root@bbqztweb root]#

 

示例四
[root@bbqztweb root]# free -b -s 1 | grep 'buffers/cache:'
-/+ buffers/cache:  745574400  295354368
-/+ buffers/cache:  745574400  295354368
-/+ buffers/cache:  745574400  295354368
Ctrl+C
[root@bbqztweb root]# free -b -s 1 | grep 'buffers/cache:' | awk '{print $4}'
Ctrl+C

怪哉,没有显示任何输出。但下面的是可以输出东西的,难道管道线多了就不灵了?why?

[root@bbqztweb root]# free -b -s 1 | awk '{print $4}'                        
shared
22200320
295211008
1800908800

shared
22200320
295211008
1800908800


Netstat命令用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。
       在Internet RFC标准中,Netstat的定义是: Netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告。

 

检查2222 端口的相关信息:

[root@singledb ~]# netstat -an |grep 2222

tcp        0      0 :::2222                     :::*                        LISTEN    

tcp        0      0 ::ffff:192.168.3.200:2222   ::ffff:192.168.3.115:53516  ESTABLISHED

     

 

该命令的帮助文档如下:

[root@singledb ~]# netstat -h

usage: netstat [-veenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}

       netstat [-vnNcaeol] [<Socket> ...]

       netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [delay]

 

        -r, --route                display routing table

        -I, --interfaces=[<Iface>] display interface table for <Iface>

        -i, --interfaces           display interface table

        -g, --groups               display multicast group memberships

        -s, --statistics           display networking statistics (like SNMP)

        -M, --masquerade           display masqueraded connections

        -v, --verbose              be verbose

        -n, --numeric              don't resolve names

        --numeric-hosts            don't resolve host names

        --numeric-ports            don't resolve port names

        --numeric-users            don't resolve user names

        -N, --symbolic             resolve hardware names

        -e, --extend               display other/more information

        -p, --programs             display PID/Program name for sockets

        -c, --continuous           continuous listing

        -l, --listening            display listening server sockets

        -a, --all, --listening     display all sockets (default: connected)

        -o, --timers               display timers

        -F, --fib            display Forwarding Information Base (default)

        -C, --cache                display routing cache instead of FIB

        -T, --notrim               stop trimming long addresses

        -Z, --context              display SELinux security context for sockets

 

  <Iface>: Name of interface to monitor/list.

  <Socket>={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom

  <AF>=Use '-A <af>' or '--<af>'; default: inet

  List of possible address families (which support routing):

    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)

    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)

    x25 (CCITT X.25)

     

       在上面的命令里讲了一个参数的意思。 如果想查看更详细的内容,可以使用man命令。 这个可以显示的更详细。

 

 

Netstat的一些常用选项 :

       netstat -s: 按照各个协议分别显示其统计数据。

       netstat -r: 显示关于路由表的信息。

netstat -a: 显示一个所有的有效连接信息列表.

       netstat -n: 显示所有已建立的有效连接。

 

 

[root@singledb ~]# netstat -a

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address               Foreign Address             State    

tcp        0      0 localhost.localdomain:2208  *:*                         LISTEN       

tcp        0      0 192.168.122.1:domain        *:*                         LISTEN     

tcp        0      0 ::ffff:192.168.3.200:ssh    ::ffff:192.168.3.115:51710  ESTABLISHED

tcp        0      0 ::ffff:192.16:rockwell-csp2 ::ffff:192.168.3.115:53516  ESTABLISHED

udp        0      0 *:48902                     *:*                                   

udp        0      0 192.168.122.1:domain        *:*                                                                     

udp        0      0 *:mdns                      *:*                                   

Active UNIX domain sockets (servers and established)

Proto RefCnt Flags       Type       State         I-Node Path

unix  2      [ ACC ]     STREAM     LISTENING     6166   @ISCSIADM_ABSTRACT_NAMESPACE

unix  28     [ ]         DGRAM                    6709   /dev/log

unix  2      [ ACC ]     STREAM     LISTENING     9022   /dev/gpmctl

unix  2      [ ACC ]     STREAM     LISTENING     6702   /var/run/audispd_events

 

以其中一条做说明:

tcp        0      0 ::ffff:192.168.3.200:ssh    ::ffff:192.168.3.115:51710  ESTABLISHED

 

协议(Proto):TCP,指是传输层通讯协议。

有关TCP, 可以参考Blog:

       网络七层协议 说明

       http://blog.csdn.net/tianlesoftware/archive/2010/11/16/6012976.aspx

 

Local  Address:::ffff:192.168.3.200:ssh,本地的IP地址,和用于连接的端口, 这里写成ssh了。 指的是SSH 端口。 

Foreign Address: ffff:192.168.3.115:51710, 远程机器的的IP地址和连接的端口。

State:ESTABLISHED。 连接状态。可有一下几种状态:

                     LISTEN  :在监听状态中。 

                     ESTABLISHED:已建立联机的联机情况。

                     TIME_WAIT:该联机在目前已经是等待的状态。

 

 

[root@singledb ~]# netstat -n

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State    

tcp        0    132 ::ffff:192.168.3.200:22     ::ffff:192.168.3.115:51710  ESTABLISHED

tcp        0      0 ::ffff:192.168.3.200:2222   ::ffff:192.168.3.115:53516  ESTABLISHED

--刚才这里显示的SSH。 现在显示成对应的端口了。

Active UNIX domain sockets (w/o servers)

Proto RefCnt Flags       Type       State         I-Node Path

unix  28     [ ]         DGRAM                    6709   /dev/log

unix  2      [ ]         DGRAM                    1413   @/org/kernel/udev/udevd

unix  2      [ ]         DGRAM                    7379   @/org/freedesktop/hal/udev_event

unix  2      [ ]         DGRAM                    15309

unix  2      [ ]         DGRAM                    13877

unix  2      [ ]         DGRAM                    13005

unix  3      [ ]         STREAM     CONNECTED     12935

unix  3      [ ]         STREAM     CONNECTED     12934

unix  2      [ ]         DGRAM                    12930

 

 

Netstat -n基本上是-a参数的数字形式,-a 和 -n 是最常用的两个,其中

       (1)-n 显示用数字化主机名,即IP地址

       (2)-n 只显示TCP连接

 

 

[root@singledb ~]# netstat -r

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

192.168.3.0     *               255.255.255.0   U         0 0          0 bond0

192.168.122.0   *               255.255.255.0   U         0 0          0 virbr0

169.254.0.0     *               255.255.0.0     U         0 0          0 bond0

default         192.168.3.1     0.0.0.0         UG        0 0          0 bond0  

 

 

[root@singledb ~]# netstat -s

Ip:

    63105 total packets received

    0 forwarded

    0 incoming packets discarded

    41834 incoming packets delivered

    33322 requests sent out

Icmp:

    1377 ICMP messages received

    0 input ICMP message failed.

    ICMP input histogram:

        destination unreachable: 1377

    1377 ICMP messages sent

    0 ICMP messages failed

    ICMP output histogram:

        destination unreachable: 1377

IcmpMsg:

        InType3: 1377

        OutType3: 1377

Tcp:

    147 active connections openings

    33 passive connection openings

    0 failed connection attempts

    0 connection resets received

    2 connections established

    31684 segments received

    31347 segments send out

    393 segments retransmited

    0 bad segments received.

    0 resets sent

Udp:

    132 packets received

    1 packets to unknown port received.

    0 packet receive errors

    201 packets sent

TcpExt:

    23 TCP sockets finished time wait in fast timer

    7032 delayed acks sent

    10 delayed acks further delayed because of locked socket

    Quick ack mode was activated 8137 times

    2 packets directly queued to recvmsg prequeue.

    2 packets directly received from prequeue

    3496 packets header predicted

    2325 acknowledgments not containing data received

    7805 predicted acknowledgments

    6 times recovered from packet loss due to SACK data

    TCPDSACKUndo: 3

    12 congestion windows recovered after partial ack

    3 TCP data loss events

    5 fast retransmits

    3 retransmits in slow start

    137 other TCP timeouts

    2 sack retransmits failed

    8137 DSACKs sent for old packets

    24 DSACKs received

IpExt:

    InMcastPkts: 36

    OutMcastPkts: 40

    InBcastPkts: 8617

[root@singledb ~]#


 


TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最“敏感”的任务列表.该命令可以按CPU使用.内存使用和执行时间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定.
top - 12:38:33 up 50 days, 23:15,  7 users,  load average: 60.58, 61.14, 61.22

Tasks: 203 total,  60 running, 139 sleeping,   4 stopped,   0 zombie

Cpu(s)  : 27.0%us, 73.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:   1939780k total,  1375280k used,   564500k free,   109680k buffers

Swap:  4401800k total,   497456k used,  3904344k free,   848712k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                               

4338 oracle    25   0  627m 209m 207m R    0 11.0 297:14.76 oracle                               

4267 oracle    25   0  626m 144m 143m R    6  7.6  89:16.62 oracle                               

3458 oracle    25   0  672m 133m 124m R    0  7.1   1283:08 oracle                               

3478 oracle    25   0  672m 124m 115m R    0  6.6   1272:30 oracle                               

3395 oracle    25   0  672m 122m 113m R    0  6.5   1270:03 oracle                                

3480 oracle    25   0  672m 122m 109m R    8  6.4   1274:13 oracle                               

3399 oracle    25   0  672m 121m 110m R    0  6.4   1279:37 oracle                               

4261 oracle    25   0  634m 100m  99m R    0  5.3  86:13.90 oracle                               

25737 oracle    25   0  632m  81m  74m R    0  4.3 272:35.42 oracle                               

7072 oracle    25   0  626m  72m  71m R    0  3.8   6:35.68 oracle                               

16073 oracle    25   0  630m  68m  63m R    8  3.6 175:20.36 oracle                               

16140 oracle    25   0  630m  66m  60m R    0  3.5 175:13.42 oracle                               

16122 oracle    25   0  630m  66m  60m R    0  3.5 176:47.73 oracle                               

  786 oracle    25   0  627m  63m  63m R    0  3.4   1:54.93 oracle                               

4271 oracle    25   0  627m  59m  58m R    8  3.1  86:09.64 oracle                               

4273 oracle    25   0  627m  57m  56m R    8  3.0  84:38.20 oracle                               

22670 oracle    25   0  626m  50m  49m R    0  2.7  84:55.82 oracle    

一.  TOP前五行统计信息

统计信息区前五行是系统整体的统计信息。

1. 第一行是任务队列信息

同 uptime  命令的执行结果:

[root@localhost ~]# uptime

 13:22:30 up 8 min,  4 users,  load average: 0.14, 0.38, 0.25

其内容如下:

12:38:33
 当前时间
 
up 50days
 系统运行时间,格式为时:分
 
1 user
 当前登录用户数
 
load average: 0.06, 0.60, 0.48
 系统负载,即任务队列的平均长度。 三个数值分别为  1分钟、5分钟、15分钟前到现在的平均值。
 

2. 第二、三行为进程和CPU的信息

当有多个CPU时,这些内容可能会超过两行。内容如下:

Tasks: 29 total
 进程总数
 
1 running
 正在运行的进程数
 
28 sleeping
 睡眠的进程数
 
0 stopped
 停止的进程数
 
0 zombie
 僵尸进程数
 
Cpu(s): 0.3% us
 用户空间占用CPU百分比
 
1.0% sy
 内核空间占用CPU百分比
 
0.0% ni
 用户进程空间内改变过优先级的进程占用CPU百分比
 
98.7% id
 空闲CPU百分比
 
0.0% wa
 等待输入输出的CPU时间百分比
 
0.0% hi
 
0.0% si
 

3. 第四五行为内存信息。

内容如下:

Mem: 191272k total
 物理内存总量
 
173656k used
 使用的物理内存总量
 
17616k free
 空闲内存总量
 
22052k buffers
 用作内核缓存的内存量
 
Swap: 192772k total
 交换区总量
 
0k used
 使用的交换区总量
 
192772k free
 空闲交换区总量
 
123988k cached
 缓冲的交换区总量。 内存中的内容被换出到交换区,而后又被换入到内存,但使用过的交换区尚未被覆盖, 该数值即为这些内容已存在于内存中的交换区的大小。相应的内存再次被换出时可不必再对交换区写入。
 

二.  进程信息

列名
 含义
 
PID
 进程id
 
PPID
 父进程id
 
RUSER
 Real user name
 
UID
 进程所有者的用户id
 
USER
 进程所有者的用户名
 
GROUP
 进程所有者的组名
 
TTY
 启动进程的终端名。不是从终端启动的进程则显示为 ?
 
PR
 优先级
 
NI
 nice值。负值表示高优先级,正值表示低优先级
 
P
 最后使用的CPU,仅在多CPU环境下有意义
 
%CPU
 上次更新到现在的CPU时间占用百分比
 
TIME
 进程使用的CPU时间总计,单位秒
 
TIME+
 进程使用的CPU时间总计,单位1/100秒
 
%MEM
 进程使用的物理内存百分比
 
VIRT
 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
 
SWAP
 进程使用的虚拟内存中,被换出的大小,单位kb。
 
RES
 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
 
CODE
 可执行代码占用的物理内存大小,单位kb
 
DATA
 可执行代码以外的部分(数据段+栈)占用的物理内存大小,单位kb
 
SHR
 共享内存大小,单位kb
 
nFLT
 页面错误次数
 
nDRT
 最后一次写入到现在,被修改过的页面数。
 
S
 进程状态。
            D=不可中断的睡眠状态
            R=运行
            S=睡眠
            T=跟踪/停止
            Z=僵尸进程
 
COMMAND
 命令名/命令行
 
WCHAN
 若该进程在睡眠,则显示睡眠中的系统函数名
 
Flags
 任务标志,参考 sched.h
 

top 的man 命令解释如下:

    Listed below are top's available fields.  They are always associated with the  letter  shown,  regardless  of the position you may have established for them with the 'o' (Order fields) interactive command.Any field is selectable as the sort field, and you control whether they are  sorted high-to-low  or  low-to-high.   For  additional  information on sort provisions see  topic 3c. TASK Area Commands.

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  oroutput.   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 'Irix mode' 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.

l: TIME  --  CPU Time

       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 additional information regarding this mode.

m: TIME+  --  CPU Time, hundredths

       The same as 'TIME', but reflecting more granularity through hundredths of a sec          ond.

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

       VIRT = SWAP + RES.

p: SWAP  --  Swapped size (kb)

       The swapped out portion of a task's total virtual memory image.

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 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  is not  currently  present  in  its address space.  A major page fault is when disk access is involved in making that page available.

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  parentheses, 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 officially documented in <linux/sched.h>.  Less formal documentation can also be  found  on the 'Fields select' and 'Order fields' screens.

       默认情况下仅显示比较重要的  PID、USER、PR、NI、VIRT、RES、SHR、S、%CPU、%MEM、TIME+、COMMAND  列。

2.1 用快捷键更改显示内容。
(1)更改显示内容通过 f键可以选择显示的内容。

       按 f 键之后会显示列的列表,按 a-z  即可显示或隐藏对应的列,最后按回车键确定。

(2)按o键可以改变列的显示顺序。

       按小写的 a-z 可以将相应的列向右移动,而大写的 A-Z  可以将相应的列向左移动。最后按回车键确定。

       按大写的 F 或 O 键,然后按 a-z 可以将进程按照相应的列进行排序。而大写的  R 键可以将当前的排序倒转。

       设置完按回车返回界面。

三.  命令使用

详细内容可以参考MAN 帮助文档。这里列举部分内容:

命令格式:

top [-] [d] [p] [q] [c] [C] [S]    [n]

参数说明:

d:  指定每两次屏幕信息刷新之间的时间间隔。当然用户可以使用s交互命令来改变之。

p:  通过指定监控进程ID来仅仅监控某个进程的状态。

q:该选项将使top没有任何延迟的进行刷新。如果调用程序有超级用户权限,那么top将以尽可能高的优先级运行。

S: 指定累计模式

s : 使top命令在安全模式中运行。这将去除交互命令所带来的潜在危险。

i:  使top不显示任何闲置或者僵死进程。

c:  显示整个命令行而不只是显示命令名

在top命令的显示窗口,我们还可以输入以下字母,进行一些交互:

帮助文档如下:

Help for Interactive Commands - procps version 3.2.7

Window 1:Def: Cumulative mode Off.  System: Delay 4.0 secs; Secure mode Off.

  Z,B       Global: 'Z' change color mappings; 'B' disable/enable bold

  l,t,m     Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info

  1,I       Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode

  f,o     . Fields/Columns: 'f' add or remove; 'o' change display order

  F or O  . Select sort field

  <,>     . Move sort field: '<' next col left; '>' next col right

  R,H     . Toggle: 'R' normal/reverse sort; 'H' show threads

  c,i,S   . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time

  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks

  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')

  u       . Show specific user only

  n or #  . Set maximum tasks displayed

  k,r       Manipulate tasks: 'k' kill; 'r' renice

  d or s    Set update interval

  W         Write configuration file

  q         Quit

          ( commands shown with '.' require a visible task display window )

Press 'h' or '?' for help with Windows,

h或者?  : 显示帮助画面,给出一些简短的命令总结说明。

k  :终止一个进程。系统将提示用户输入需要终止的进程PID,以及需要发送给该进程什么样的信号。一般的终止进程可以使用15信号;如果不能正常结束那就使用信号9强制结束该进程。默认值是信号15。在安全模式中此命令被屏蔽。

i:忽略闲置和僵死进程。这是一个开关式命令。

q:  退出程序。

r:  重新安排一个进程的优先级别。系统提示用户输入需要改变的进程PID以及需要设置的进程优先级值。输入一个正值将使优先级降低,反之则可以使该进程拥有更高的优先权。默认值是10。

S:切换到累计模式。

s :  改变两次刷新之间的延迟时间。系统将提示用户输入新的时间,单位为s。如果有小数,就换算成ms。输入0值则系统将不断刷新,默认值是5 s。需要注意的是如果设置太小的时间,很可能会引起不断刷新,从而根本来不及看清显示的情况,而且系统负载也会大大增加。

f或者F :从当前显示中添加或者删除项目。

o或者O  :改变显示项目的顺序。

l: 切换显示平均负载和启动时间信息。即显示影藏第一行

m: 切换显示内存信息。即显示影藏内存行

t : 切换显示进程和CPU状态信息。即显示影藏CPU行

c:  切换显示命令名称和完整命令行。 显示完整的命令。 这个功能很有用。

M : 根据驻留内存大小进行排序。

P:根据CPU使用百分比大小进行排序。

T: 根据时间/累计时间进行排序。

W:  将当前设置写入~/.toprc文件中。这是写top配置文件的推荐方法。

 

Linux系统出现了性能问题,一般我们可以通过top、iostat、free、vmstat等命令来查看初步定位问题。其中iostat可以给我们提供丰富的IO状态数据。

基本使用

$iostat -d -k 1 10
参数 -d 表示,显示设备(磁盘)使用状态;-k某些使用block为单位的列强制使用Kilobytes为单位;1 10表示,数据显示每隔1秒刷新一次,共显示10次。

 

# iostat -x 1 10
Linux 2.6.18-92.el5xen    02/03/2009
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.10    0.00    4.82   39.54    0.07   54.46
Device:         rrqm/s   wrqm/s   r/s   w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.00     3.50  0.40  2.50     5.60    48.00    18.48     0.00    0.97   0.97   0.28
sdb               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sdc               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sdd               0.00     0.00  0.00  0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
sde               0.00     0.10  0.30  0.20     2.40     2.40     9.60     0.00    1.60   1.60   0.08
sdf              17.40     0.50 102.00  0.20 12095.20     5.60   118.40     0.70    6.81   2.09  21.36
sdg             232.40     1.90 379.70  0.50 76451.20    19.20   201.13     4.94   13.78   2.45  93.16
rrqm/s:   每秒进行 merge 的读操作数目。即 delta(rmerge)/s
wrqm/s:  每秒进行 merge 的写操作数目。即 delta(wmerge)/s
r/s:           每秒完成的读 I/O 设备次数。即 delta(rio)/s
w/s:         每秒完成的写 I/O 设备次数。即 delta(wio)/s
rsec/s:    每秒读扇区数。即 delta(rsect)/s
wsec/s:  每秒写扇区数。即 delta(wsect)/s
rkB/s:      每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节。(需要计算)
wkB/s:    每秒写K字节数。是 wsect/s 的一半。(需要计算)
avgrq-sz: 平均每次设备I/O操作的数据大小 (扇区)。delta(rsect+wsect)/delta(rio+wio)
avgqu-sz: 平均I/O队列长度。即 delta(aveq)/s/1000 (因为aveq的单位为毫秒)。
await:    平均每次设备I/O操作的等待时间 (毫秒)。即 delta(ruse+wuse)/delta(rio+wio)
svctm:   平均每次设备I/O操作的服务时间 (毫秒)。即 delta(use)/delta(rio+wio)
%util:      一秒中有百分之多少的时间用于 I/O 操作,或者说一秒中有多少时间 I/O 队列是非空的。即 delta(use)/s/1000 (因为use的单位为毫秒)

如果 %util 接近 100%,说明产生的I/O请求太多,I/O系统已经满负荷,该磁盘
可能存在瓶颈。
idle小于70% IO压力就较大了,一般读取速度有较多的wait.

同时可以结合vmstat 查看查看b参数(等待资源的进程数)和wa参数(IO等待所占用的CPU时间的百分比,高过30%时IO压力高)

另外还可以参考
一般:
svctm < await (因为同时等待的请求的等待时间被重复计算了),
svctm的大小一般和磁盘性能有关:CPU/内存的负荷也会对其有影响,请求过多也会间接导致 svctm 的增加。
await: await的大小一般取决于服务时间(svctm) 以及 I/O 队列的长度和 I/O 请求的发出模式。
如果 svctm 比较接近 await,说明I/O 几乎没有等待时间;
如果 await 远大于 svctm,说明 I/O队列太长,应用得到的响应时间变慢,
如果响应时间超过了用户可以容许的范围,这时可以考虑更换更快的磁盘,调整内核 elevator算法,优化应用,或者升级 CPU。
队列长度(avgqu-sz)也可作为衡量系统 I/O 负荷的指标,但由于 avgqu-sz 是按照单位时间的平均值,所以不能反映瞬间的 I/O 洪水。

  别人一个不错的例子.(I/O 系统 vs. 超市排队)
举一个例子,我们在超市排队 checkout 时,怎么决定该去哪个交款台呢? 首当是看排的队人数,5个人总比20人要快吧?除了数人头,我们也常常看看前面人购买的东西多少,如果前面有个采购了一星期食品的大妈,那么可以考虑换个队排了。还有就是收银员的速度了,如果碰上了连钱都点不清楚的新手,那就有的等了。另外,时机也很重要,可能 5分钟前还人满为患的收款台,现在已是人去楼空,这时候交款可是很爽啊,当然,前提是那过去的 5 分钟里所做的事情比排队要有意义(不过我还没发现什么事情比排队还无聊的)。
I/O 系统也和超市排队有很多类似之处:
r/s+w/s 类似于交款人的总数
平均队列长度(avgqu-sz)类似于单位时间里平均排队人的个数
平均服务时间(svctm)类似于收银员的收款速度
平均等待时间(await)类似于平均每人的等待时间
平均I/O数据(avgrq-sz)类似于平均每人所买的东西多少
I/O 操作率 (%util)类似于收款台前有人排队的时间比例。
我们可以根据这些数据分析出 I/O 请求的模式,以及 I/O 的速度和响应时间。
下面是别人写的这个参数输出的分析
# iostat -x 1
avg-cpu:  %user   %nice    %sys   %idle
16.24    0.00    4.31   79.44
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
/dev/cciss/c0d0
0.00  44.90  1.02 27.55    8.16  579.59     4.08   289.80    20.57    22.35   78.21   5.00  14.29
/dev/cciss/c0d0p1
0.00  44.90  1.02 27.55    8.16  579.59     4.08   289.80    20.57    22.35   78.21   5.00  14.29
/dev/cciss/c0d0p2
0.00   0.00  0.00  0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00
上面的 iostat 输出表明秒有 28.57 次设备 I/O 操作: 总IO(io)/s = r/s(读) +w/s(写) = 1.02+27.55 = 28.57 (次/秒) 其中写操作占了主体 (w:r = 27:1)。
平均每次设备 I/O 操作只需要 5ms 就可以完成,但每个 I/O 请求却需要等上 78ms,为什么? 因为发出的 I/O 请求太多 (每秒钟约 29 个),假设这些请求是同时发出的,那么平均等待时间可以这样计算:
平均等待时间 = 单个 I/O 服务时间 * ( 1 + 2 + ... + 请求总数-1) / 请求总数
应用到上面的例子: 平均等待时间 = 5ms * (1+2+...+28)/29 = 70ms,和 iostat 给出的78ms 的平均等待时间很接近。这反过来表明 I/O 是同时发起的。
每秒发出的 I/O 请求很多 (约 29 个),平均队列却不长 (只有 2 个 左右),这表明这 29 个请求的到来并不均匀,大部分时间 I/O 是空闲的。
一秒中有 14.29% 的时间 I/O 队列中是有请求的,也就是说,85.71% 的时间里 I/O 系统无事可做,所有 29 个 I/O 请求都在142毫秒之内处理掉了。
delta(ruse+wuse)/delta(io) = await = 78.21 => delta(ruse+wuse)/s=78.21 * delta(io)/s = 78.21*28.57 =2232.8,表明每秒内的I/O请求总共需要等待2232.8ms。所以平均队列长度应为 2232.8ms/1000ms = 2.23,而iostat 给出的平均队列长度 (avgqu-sz) 却为 22.35,为什么?! 因为 iostat 中有 bug,avgqu-sz值应为 2.23,而不是 22.35。

 

 

Input Output statistics (  iostat )

  iostat反映了终端、磁盘I/O情况和CPU活动。输出结果的第一行是从系统启动到现在为止的这段时间的结果,接下去的每一行是interval时

间段内的结果。Kernel里有一组计数器用来跟踪这些值。
  iostat的默认参数是tdc(terminal,  disk, and CPU)。如果任何其他的选项被指定,这个默认参数将被完全替代,例如,iostat -d将只反

映磁盘的统计结果。

语法:

基本语法: iostat  <options>;   interval  count

option - 让你指定所需信息的设备,像磁盘、cpu或者终端(-d , -c , -t  or -tdc ) 。x 选项给出了完整的统计结果(gives the extended

statistic)。

interval -  在两个samples之间的时间(秒)。

count  - 就是需要统计几次

例子:

$ iostat -xtc 5 2
                          extended disk statistics       tty         cpu
     disk r/s  w/s Kr/s Kw/s wait actv svc_t  %w  %b  tin tout us sy wt id
     sd0   2.6 3.0 20.7 22.7 0.1  0.2  59.2   6   19   0   84  3  85 11 0
     sd1   4.2 1.0 33.5  8.0 0.0  0.2  47.2   2   23
     sd2   0.0 0.0  0.0  0.0 0.0  0.0   0.0   0    0
     sd3  10.2 1.6 51.4 12.8 0.1  0.3  31.2   3   31


     The fields have the following meanings:

      disk    name of the disk
      r/s     reads per second
      w/s     writes per second
      Kr/s    kilobytes read per second
      Kw/s    kilobytes written per second
      wait    average number of transactions waiting for service (Q length)
      actv    average number of transactions  actively 
              being serviced (removed  from  the
              queue but not yet
              completed)
      %w      percent of time there are transactions  waiting
              for service (queue non-empty)
      %b      percent of time the disk is busy  (transactions
                  in progress)

 


Results and Solutions:

从iostat输出结果中需要注意的值:

Reads/writes  per second (r/s , w/s)
Percentage busy (%b)
Service time (svc_t)

如果磁盘显示长时间的高reads/writes,并且磁盘的percentage busy (%b)也远大于5%,同时average service time  (svc_t)也远大于30

milliseconds,这以下的措施需要被执行:
1.)调整应用,令其使用磁盘i/o更加有效率,可以通过修改磁盘队列、使用应用服务器的cache

2.)将文件系统分布到2个或多个磁盘上,并使用volume manager/disksuite的条带化特点

3.) 增加系统参数值,如inode cache  , ufs_ninode。Increase the system parameter values for  inode cache  , ufs_ninode ,  which

is  Number of inodes to be held in memory. Inodes are cached globally (for UFS), not on a per-file system basis 

4.) 将文件系统移到更快的磁盘/控制器,或者用更好的设备来代替

vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存、进程、CPU活动进行监控。他是对系统的整体情况进行统计,不足之处是无法对某个进程进行深入分析。通常使用vmstat 5 5(表示在5秒时间内进行5次采样)命令测试。将得到一个数据汇总他能够反映真正的系统情况。
#vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b   swpd   free   buff cache   si   so    bi    bo   in    cs us sy id wa
1 0 62792   3460   9116 88092    6   30   189    89 1061   569 17 28 54 2
0 0 62792   3400   9124 88092    0    00    14 884   434 4 14 81 0
0 0 62792   3400   9132 88092    0    00    14 877   424 4 15 81 0
1 0 62792   3400   9140 88092    0    00    14 868   418 6 20 74 0
1 0 62792   3400   9148 88092    0    00    15 847   400 9 25 67 0
Linux 内存监控vmstat命令输出分成六个部分:


(1)进程procs:
r:在运行队列中等待的进程数 。
b:在等待io的进程数 。


(2)Linux 内存监控内存memoy:
swpd:现时可用的交换内存(单位KB)。
free:空闲的内存(单位KB)。
buff: 缓冲去中的内存数(单位:KB)。
cache:被用来做为高速缓存的内存数(单位:KB)。


(3) Linux 内存监控swap交换页面
si: 从磁盘交换到内存的交换页数量,单位:KB/秒。
so: 从内存交换到磁盘的交换页数量,单位:KB/秒。


(4)Linux 内存监控 io块设备:
bi: 发送到块设备的块数,单位:块/秒。
bo: 从块设备接收到的块数,单位:块/秒。


(5)Linux 内存监控system系统:
in: 每秒的中断数,包括时钟中断。
cs: 每秒的环境(上下文)转换次数。


(6)Linux 内存监控cpu中央处理器:
cs:用户进程使用的时间 。以百分比表示。
sy:系统进程使用的时间。 以百分比表示。
id:中央处理器的空闲时间 。以百分比表示。


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

 

free命令用来显示内存使用情况。display information about free and used memory on the system。

常用参数
b 以字节为单位显示。
-k 以K字节为单位显示。默认显示。
-m 以兆字节为单位显示。

 

-s <seconds> 每隔多少秒重复执行。可编写一个脚本用于监控。

使用示例
示例一
[root@sunrise root]# free
                    total        used        free     shared    buffers     cached
Mem:       4091428    4073120      18308          0     112784    2564792
-/+ buffers/cache:    1395544    2695884
Swap:      8385888          0    8385888
[root@sunrise root]#

 

 

数值的单位是KBytes。


Mem开头的行:

total是指内存总数。比如这台机器4G内存,实际上已经扣除掉了作为显存的部分。

used是指操作系统已经使用的内存数。这部分既包括操作系统本身使用的部分,也包括应用程序已经使用的部分,还包括缓存的部分。

free是指操作系统还没有使用的内存数。我们通常看到这部分比较小。

shared已经废弃不用,总是显示0。

buffers和cached是指作为缓存的内存数。


-/+ buffers/cache开头的行:(重点看这行)

used列是指应用程序总共使用的内存数。等于Mem.used-Mem.buffers-Mem.cached。

free列是指应用程序还未使用的内存数。这个数据才是我们需要关注的空闲可用内存数。等于Mem.free+Mem.buffers+Mem.cached。

如果此行中free列的数据太小,那么就需要优化程序或者增加物理内存了。

 

示例二
[root@bbqztweb root]# free -s 60
             total       used       free     shared    buffers     cached
Mem:       1016532     996320      20212          0      97964     166716
-/+ buffers/cache:     731640     284892
Swap:      2040244     281544    1758700

             total       used       free     shared    buffers     cached
Mem:       1016532     996328      20204          0      97964     166724
-/+ buffers/cache:     731640     284892
Swap:      2040244     281544    1758700

             total       used       free     shared    buffers     cached
Mem:       1016532     996460      20072          0      97964     166724
-/+ buffers/cache:     731772     284760
Swap:      2040244     281544    1758700

             total       used       free     shared    buffers     cached
Mem:       1016532     996316      20216          0      97964     166740
-/+ buffers/cache:     731612     284920
Swap:      2040244     281544    1758700


[root@bbqztweb root]#

 

示例三
free命令实际上是根据/proc/meminfo生成的。-/+ buffers/cache:这行是计算出来的。

[root@bbqztweb root]# free -b; cat /proc/meminfo
             total       used       free     shared    buffers     cached
Mem:    1040928768 1017909248   23019520          0  100220928  172040192
-/+ buffers/cache:  745648128  295280640
Swap:   2089209856  288301056 1800908800
        total:    used:    free:  shared: buffers:  cached:
Mem:  1040928768 1017909248 23019520        0 100220928 371302400
Swap: 2089209856 288301056 1800908800
MemTotal:      1016532 kB
MemFree:         22480 kB
MemShared:           0 kB
Buffers:         97872 kB
Cached:         168008 kB
SwapCached:     194592 kB
Active:         667076 kB
ActiveAnon:     510760 kB
ActiveCache:    156316 kB
Inact_dirty:    125964 kB
Inact_laundry:   20508 kB
Inact_clean:     17308 kB
Inact_target:   166168 kB
HighTotal:      122044 kB
HighFree:         5564 kB
LowTotal:       894488 kB
LowFree:         16916 kB
SwapTotal:     2040244 kB
SwapFree:      1758700 kB
CommitLimit:   2548508 kB
Committed_AS:  1063004 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     2048 kB
[root@bbqztweb root]#

 

示例四
[root@bbqztweb root]# free -b -s 1 | grep 'buffers/cache:'
-/+ buffers/cache:  745574400  295354368
-/+ buffers/cache:  745574400  295354368
-/+ buffers/cache:  745574400  295354368
Ctrl+C
[root@bbqztweb root]# free -b -s 1 | grep 'buffers/cache:' | awk '{print $4}'
Ctrl+C

怪哉,没有显示任何输出。但下面的是可以输出东西的,难道管道线多了就不灵了?why?

[root@bbqztweb root]# free -b -s 1 | awk '{print $4}'                        
shared
22200320
295211008
1800908800

shared
22200320
295211008
1800908800


Netstat命令用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。
       在Internet RFC标准中,Netstat的定义是: Netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告。

 

检查2222 端口的相关信息:

[root@singledb ~]# netstat -an |grep 2222

tcp        0      0 :::2222                     :::*                        LISTEN    

tcp        0      0 ::ffff:192.168.3.200:2222   ::ffff:192.168.3.115:53516  ESTABLISHED

     

 

该命令的帮助文档如下:

[root@singledb ~]# netstat -h

usage: netstat [-veenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}

       netstat [-vnNcaeol] [<Socket> ...]

       netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [delay]

 

        -r, --route                display routing table

        -I, --interfaces=[<Iface>] display interface table for <Iface>

        -i, --interfaces           display interface table

        -g, --groups               display multicast group memberships

        -s, --statistics           display networking statistics (like SNMP)

        -M, --masquerade           display masqueraded connections

        -v, --verbose              be verbose

        -n, --numeric              don't resolve names

        --numeric-hosts            don't resolve host names

        --numeric-ports            don't resolve port names

        --numeric-users            don't resolve user names

        -N, --symbolic             resolve hardware names

        -e, --extend               display other/more information

        -p, --programs             display PID/Program name for sockets

        -c, --continuous           continuous listing

        -l, --listening            display listening server sockets

        -a, --all, --listening     display all sockets (default: connected)

        -o, --timers               display timers

        -F, --fib            display Forwarding Information Base (default)

        -C, --cache                display routing cache instead of FIB

        -T, --notrim               stop trimming long addresses

        -Z, --context              display SELinux security context for sockets

 

  <Iface>: Name of interface to monitor/list.

  <Socket>={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom

  <AF>=Use '-A <af>' or '--<af>'; default: inet

  List of possible address families (which support routing):

    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)

    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)

    x25 (CCITT X.25)

     

       在上面的命令里讲了一个参数的意思。 如果想查看更详细的内容,可以使用man命令。 这个可以显示的更详细。

 

 

Netstat的一些常用选项 :

       netstat -s: 按照各个协议分别显示其统计数据。

       netstat -r: 显示关于路由表的信息。

netstat -a: 显示一个所有的有效连接信息列表.

       netstat -n: 显示所有已建立的有效连接。

 

 

[root@singledb ~]# netstat -a

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address               Foreign Address             State    

tcp        0      0 localhost.localdomain:2208  *:*                         LISTEN       

tcp        0      0 192.168.122.1:domain        *:*                         LISTEN     

tcp        0      0 ::ffff:192.168.3.200:ssh    ::ffff:192.168.3.115:51710  ESTABLISHED

tcp        0      0 ::ffff:192.16:rockwell-csp2 ::ffff:192.168.3.115:53516  ESTABLISHED

udp        0      0 *:48902                     *:*                                   

udp        0      0 192.168.122.1:domain        *:*                                                                     

udp        0      0 *:mdns                      *:*                                   

Active UNIX domain sockets (servers and established)

Proto RefCnt Flags       Type       State         I-Node Path

unix  2      [ ACC ]     STREAM     LISTENING     6166   @ISCSIADM_ABSTRACT_NAMESPACE

unix  28     [ ]         DGRAM                    6709   /dev/log

unix  2      [ ACC ]     STREAM     LISTENING     9022   /dev/gpmctl

unix  2      [ ACC ]     STREAM     LISTENING     6702   /var/run/audispd_events

 

以其中一条做说明:

tcp        0      0 ::ffff:192.168.3.200:ssh    ::ffff:192.168.3.115:51710  ESTABLISHED

 

协议(Proto):TCP,指是传输层通讯协议。

有关TCP, 可以参考Blog:

       网络七层协议 说明

       http://blog.csdn.net/tianlesoftware/archive/2010/11/16/6012976.aspx

 

Local  Address:::ffff:192.168.3.200:ssh,本地的IP地址,和用于连接的端口, 这里写成ssh了。 指的是SSH 端口。 

Foreign Address: ffff:192.168.3.115:51710, 远程机器的的IP地址和连接的端口。

State:ESTABLISHED。 连接状态。可有一下几种状态:

                     LISTEN  :在监听状态中。 

                     ESTABLISHED:已建立联机的联机情况。

                     TIME_WAIT:该联机在目前已经是等待的状态。

 

 

[root@singledb ~]# netstat -n

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State    

tcp        0    132 ::ffff:192.168.3.200:22     ::ffff:192.168.3.115:51710  ESTABLISHED

tcp        0      0 ::ffff:192.168.3.200:2222   ::ffff:192.168.3.115:53516  ESTABLISHED

--刚才这里显示的SSH。 现在显示成对应的端口了。

Active UNIX domain sockets (w/o servers)

Proto RefCnt Flags       Type       State         I-Node Path

unix  28     [ ]         DGRAM                    6709   /dev/log

unix  2      [ ]         DGRAM                    1413   @/org/kernel/udev/udevd

unix  2      [ ]         DGRAM                    7379   @/org/freedesktop/hal/udev_event

unix  2      [ ]         DGRAM                    15309

unix  2      [ ]         DGRAM                    13877

unix  2      [ ]         DGRAM                    13005

unix  3      [ ]         STREAM     CONNECTED     12935

unix  3      [ ]         STREAM     CONNECTED     12934

unix  2      [ ]         DGRAM                    12930

 

 

Netstat -n基本上是-a参数的数字形式,-a 和 -n 是最常用的两个,其中

       (1)-n 显示用数字化主机名,即IP地址

       (2)-n 只显示TCP连接

 

 

[root@singledb ~]# netstat -r

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

192.168.3.0     *               255.255.255.0   U         0 0          0 bond0

192.168.122.0   *               255.255.255.0   U         0 0          0 virbr0

169.254.0.0     *               255.255.0.0     U         0 0          0 bond0

default         192.168.3.1     0.0.0.0         UG        0 0          0 bond0  

 

 

[root@singledb ~]# netstat -s

Ip:

    63105 total packets received

    0 forwarded

    0 incoming packets discarded

    41834 incoming packets delivered

    33322 requests sent out

Icmp:

    1377 ICMP messages received

    0 input ICMP message failed.

    ICMP input histogram:

        destination unreachable: 1377

    1377 ICMP messages sent

    0 ICMP messages failed

    ICMP output histogram:

        destination unreachable: 1377

IcmpMsg:

        InType3: 1377

        OutType3: 1377

Tcp:

    147 active connections openings

    33 passive connection openings

    0 failed connection attempts

    0 connection resets received

    2 connections established

    31684 segments received

    31347 segments send out

    393 segments retransmited

    0 bad segments received.

    0 resets sent

Udp:

    132 packets received

    1 packets to unknown port received.

    0 packet receive errors

    201 packets sent

TcpExt:

    23 TCP sockets finished time wait in fast timer

    7032 delayed acks sent

    10 delayed acks further delayed because of locked socket

    Quick ack mode was activated 8137 times

    2 packets directly queued to recvmsg prequeue.

    2 packets directly received from prequeue

    3496 packets header predicted

    2325 acknowledgments not containing data received

    7805 predicted acknowledgments

    6 times recovered from packet loss due to SACK data

    TCPDSACKUndo: 3

    12 congestion windows recovered after partial ack

    3 TCP data loss events

    5 fast retransmits

    3 retransmits in slow start

    137 other TCP timeouts

    2 sack retransmits failed

    8137 DSACKs sent for old packets

    24 DSACKs received

IpExt:

    InMcastPkts: 36

    OutMcastPkts: 40

    InBcastPkts: 8617

[root@singledb ~]#