学历代表过去、能力代表现在、学习力代表未来

Linux性能监控:vmstat

上一篇 / 下一篇  2011-01-12 11:16:06 / 个人分类:性能监控

转载自:http://www.bitscn.com/os/linux/200802/128193.html

vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写, 是实时系统监控工具。该命令通过使用knlist子程序和/dev/kmen伪设备驱动器访问这些数据,输出信息直接打印在屏幕。vmstat反馈的与CPU相关的信息包括:

    1.多少任务在运行

    2.CPU使用的情况

    3.CPU收到多少中断

    4.发生多少上下文切换

vmstat的语法如下: vmstat [delay [count]]

参数 解释

delay 相邻的两次采样的间隔时间

count 采样的次数,count只能和delay一起使用

当没有参数时,vmstat则显示系统启动以后所有信息的平均值。有delay时,第一行的信息自系统启动以来的平均信息。从第二行开始,输出为前一个delay时间段的平均信息。当系统有多个CPU时,输出为所有CPU的平均值。

参数 解释

任务的信息(procs)

   r 在internal时间段里,运行队列里等待CPU的任务的个数,即不包含vmstat进程 procs_running-1

   b 在internal时间段里,被资源阻塞的任务数(I/0,页面调度,等等.),通常情况下是接近0的procs_blocked

CPU信息(cpu)

    us 在internal时间段里,用户态的CPU时间(%),包含 nice值为负进程 (?user+?nice)/?total*100

    sy 在internal时间段里,核心态的CPU时间(%) (?system+?irq+?softirq)/?total*100

    id 在internal时间段里,cpu空闲的时间,不包括等待i/o的时间(%) ?idle/?total*100

    wa 在internal时间段里,等待i/o的时间(%) ?iowait/?total*100

系统信息(system)

    in 在internal时间段里,每秒发生中断的次数 ?intr/interval

    cs 在internal时间段里,每秒上下文切换的次数,即每秒内核任务交换的次数 ?ctxt/interval

范例1:average mode (粗略信息)

当vmstat不带参数时,对应的输出值是从系统启动以来的平均值,而r和b则对应的是完成这一命令时,系统的值。从下面例子,可以看出系统基本出去闲置状态(idle)。自启动以来,CPU在用户态消耗时间为5%,在核心态消耗为本1%,剩下的为闲置时间。需要指出的是:这里的用户态时间包括nice值为负的进程的时间。

CODE:

[root@localhost ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 4580 428 98516 0 0 49 6 15 19 2 1 96 1
[root@localhost ~]#

范例2:average mode (详细信息)

命令格式: vmstat –s

这里只讨论与CPU相关信息。“CPU ticks”表示自系统启动CPU运行时间,这里以tick为时间单位。用tick来西安市us,sy id 和wa的时间;forks指自从系统启动以来,所创建的新任务的个数。这些信息从/proc/stat 的第一行和”processes”行获得。

CODE:

[root@localhost ~]# vmstat -s
255280 total memory
244216 used memory
206624 active memory
21208 inactive memory
11064 free memory
628 buffer memory
91396 swap cache
255992 total swap
24 used swap
255968 free swap
973400 non-nice user cpu ticks
477 nice user cpu ticks
206168 system cpu ticks
43567714 idle cpu ticks
373234 IO-wait cpu ticks
62732 IRQ cpu ticks
1972 softirq cpu ticks
22366502 pages paged in
88756936 pages paged out
0 pages swapped in
0 pages swapped out
135634319 interrupts
137288441 CPU context switches
1134440368 boot time
208990 forks
[root@localhost ~]#
 

结果解释

non-nice user cpu ticks 自系统启动以来,CPU在用户态下运行非nice进程的时间,单位为jiffies user

nice user cpu ticks 自系统启动以来,CPU在用户态下运行nice进程的时间,单位为jiffies nice

system cpu ticks 自系统启动以来,CPU处于系统状态的时间,单位为jiffies sys

idle cpu ticks 自系统启动以来,CPU处于闲置状态的时间,单位为jiffies idle

IO-wait cpu ticks 自系统启动以来,CPU处理IO中断的时间,单位为jiffies iowait

IRQ cpu ticks 自系统启动以来,CPU处理硬中断的时间,单位为jiffies irq

softing cpu ticks 自系统启动以来,CPU处理软中断的时间,单位为jiffies Softirq

interrupts 自系统启动以来,发生的所有的中断的次数目 Intr

CPU context switches 自系统启动以来,发生的上下文交换的次数 Ctxt

boot time 自系统启动以来到现在运行的时间,单位为秒。 btime

forks 自系统启动以来所创建的任务的个数目。 Process

范例3:定期采样(delay [count])

定期采样数据是指每隔delay时间,采样一次。当count 为0时,vmstat 将不停地定期报告信息;否则当报告count次后,vmstat 命令停止运行。

第一行的信息如同范例1,是自系统启动以来的平均信息。从第二行开始,每行的意思是:r和b采样那一时刻系统运行队列和等待队列的情况;而usystem参数(in,cs)以及CPU参数(us,sy,id,wa)对应的输出值是系统在前一个delay的情况。

从下面例子可以看出上下文交换的次数小于中断的发生次数。当系统大部分时间是空闲并且中断大部分是时间中断时,这种现象极可能发生。当时间中断发生时, 因为调度器没有什么任务可调度,所以很少发生上下文切换。

CODE:

[root@localhost ~]# vmstat 2 4
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 24 11032 652 91396 0 0 49 6 15 19 2 1 96 1
0 0 24 11032 652 91396 0 0 0 0 377 464 1 0 99 0
0 0 24 11024 652 91396 0 0 0 0 387 476 1 0 100 0
0 0 24 11024 652 91396 0 0 0 0 323 377 0 0 100 0
[root@localhost ~]#


TAG:

 

评分:0

我来说两句

Open Toolbar