转贴
[url]http://blog.csdn.net/jianghuyue/archive/2009/01/04/3704409.aspx[/url]
LINUX Operating System 监控统计信息:
free 内存管理:
free 结果:
total used free shared buffers cached
Mem: 2025356 1469320 556036 0 226972 961492
-/+ buffers/cache: 280856 1744500
Swap: 4194232 45912 4148320
结果中的第一行是从内核角度看内存使用的状况, 只有556036k内存可用
第二行:从应用层的角度看内存使用的状况,其中: 1744500 = 556036 + 0 + 226972 + 961492, 1744500+280856=2025356
从应用的角度来讲,buffer和cached的内存是可用的, buffer/cached是用来提升文件读取的性能,
buffer/cached的区别:
buffers
是指用来给块设备作的缓冲大小,他只记录文件系统的
metadata
以及
tracking in-flight pages. cached
是用来给文件作缓冲。
那就是说:
buffers
是用来存储,目录里面有什么内容,权限等等。而
cached
直接用来记忆咱们打开的文件,若是你想知道他是否是真的生效,你能够试一下,前后执行两次命令
#man X ,
你就能够明显的感受到第二次的开打的速度快不少
。
mpstat:处理器的相关信息的统计。
若是server有多个processors, mpstat能够统计出每一个processor的使用统计状况
mpstat -P [ALL | {number}]
mpstat -P ALL:
结果:
17时49分54秒 CPU %user %nice %system %iowait %irq %soft %idle intr/s
17时49分54秒 all 0.89 0.00 1.41 1.43 0.01 0.40 95.87 395.84
17时49分54秒 0 0.06 0.00 0.11 0.11 0.00 0.03 99.69 25.47
17时49分54秒 1 0.08 0.00 0.11 0.11 0.00 0.04 99.66 25.07
17时49分54秒 2 0.06 0.00 0.11 0.11 0.00 0.03 99.69 25.19
17时49分54秒 3 0.07 0.00 0.11 0.11 0.00 0.03 99.68 25.21
能够看到该server有四个cpu
iostat:用于生成cpu utilization report和 Device utilization report
netstat:输出网络链接、路由表、接口统计、masquerade connections(?)和multicast memberships.
vmstat:用来报告关于进程状态、内存消耗、分页活动、blocking I/O 操做、interrupts、context switches、和内存的使用率。
vmstat -a:显示active和inactive内存统计来代替buffer和cache内存统计
vmstat -a
procs memory swap io system cpu
r b swpd free
inact active si so bi bo in cs us sy id wa
0 0 45912 556396 529708 561632 0 0 0 15 1 65 1 1 97 1
vmstat
procs memory swap io system cpu
r b swpd free
buff cache si so bi bo in cs us sy id wa
0 0 45912 556808 226968 961364 0 0 0 15 1 65 1 1 97 1
其中:
procs, r: number of runnable process, b: number of processes in uninterruptible sleep.
memory swpd: the amount of memory paged to disk.
free: the amount of free physical memory
buff: the amount of memory consumed by buffer
inact : the amount of memory on the inactive list (in KB by default)
active: the amount of memory on the active list (in KB by default)
swap:
si: the amount of memory paged in from disk (in KB/s by default)
so: the amount of memory paged out to disk (in KB/s by default)
io
bi: blocks received from a block device (in blocks/s).
bo: blocks sent to a block device (in blocks/s)
system
in: the number of interrupts received (in interrupts/s)
cs: the number of context switches (in switches/s)
cpu
us: percentage of total processor time consumed by user-space
sy: percentage of total processor time consumed by the kernel
wa: percentage of total processor time spent in I/O wait
id: percentage of total processor time spent idle
文件:
/proc/meminfo -- memory information
/proc/stat -- system statistics
/proc/[1-9]*/stat -- process statistics
top:
uptime:
uptime
13:47:40 up 407 days, 22:02, 2 users, load average: 0.00, 0.00, 0.00
w
13:47:59 up 407 days, 22:02, 2 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 10.1.60.78 10:04am 0.00s 0.10s 0.01s w
root pts/2 10.1.60.78 10:05am 25.00s 0.10s 0.01s info uptime
sar: 这个命令对于系统各项性能的监控起到重要的做用, 看看sar的info文档中的解释, 他是用来收集、报告、和存储系统活动信息的实用工具
监控cpu的使用状况:
sar -o data.file -u 10 2
>>-o 选项指定结果存储在data.file当中 -u选项指定对cpu的使用状况进行统计和报告, 10表示执行间隔(interval) , 而2是指搜集几回
>> 使用 sar -f data.file 来查看统计的结果
结果实例:
Linux 2.4.21-47.EL (78.33) 2008年12月31日
18时01分04秒 CPU %user %nice %system %iowait %idle
18时01分05秒 all 0.25 0.00 0.25 0.50 99.00
18时01分06秒 all 0.00 0.00 0.00 1.00 99.00
18时01分07秒 all 1.00 0.00 0.00 0.75 98.25
18时01分08秒 all 0.00 0.00 0.00 0.75 99.25
18时01分09秒 all 0.00 0.00 0.00 2.75 97.25
18时01分10秒 all 0.00 0.00 0.00 0.75 99.25
18时01分11秒 all 0.25 0.00 0.25 1.00 98.50
18时01分12秒 all 0.00 0.00 0.00 0.50 99.50
18时01分13秒 all 0.00 0.00 0.00 1.25 98.75
18时01分14秒 all 0.00 0.00 0.00 2.75 97.25
Average: all 0.15 0.00 0.05 1.20 98.60
sar -b I/O 和transfer rate statistics
transfer:是指一次对physical disk的I/O请求, 多个logical request能够组成一个transfer。
15时30分01秒 tps rtps wtps bread/s bwrtn/s
15时40分01秒 0.97 0.00 0.97 0.00 15.66
15时50分01秒 1.43 0.02 1.41 0.27 35.71
16时00分01秒 1.37 0.01 1.36 1.36 25.87
16时10分01秒 1.52 0.00 1.52 0.04 30.71
16时20分01秒 1.12 0.00 1.11 0.01 16.82
16时30分01秒 1.21 0.00 1.21 0.00 18.10
16时40分01秒 1.07 0.00 1.07 0.00 16.78
16时50分01秒 0.85 0.00 0.85 0.00 12.17
17时00分01秒 0.83 0.00 0.83 0.00 12.00
17时10分01秒 0.98 0.00 0.98 0.00 15.29
如上结果:
tps: transfer per second, rtps: read transfer per second wtps: written transfer per second, bread/s: block read per second, bwrtn/s: block written per second.
sar -B 内存分页调度统计[paging statistic]
15时30分01秒 pgpgin/s pgpgout/s fault/s majflt/s
15时40分01秒 0.00 7.83 0.00 0.00
15时50分01秒 0.13 17.86 0.00 0.00
16时00分01秒 0.68 12.94 0.00 0.00
16时10分01秒 0.02 15.36 0.00 0.00
16时20分01秒 0.01 8.41 0.00 0.00
16时30分01秒 0.00 9.05 0.00 0.00
16时40分01秒 0.00 8.39 0.00 0.00
pgpgin/s: 每秒钟从硬盘到内存的换页数, 单位kilobyte. pgpgout/s:每秒钟从内存到硬盘的换页数, fault/s: 每秒钟发生的page faults, majflt/s:
关于page fault
在 计算机存储技术上来讲, page是一个固定大小的块(block),它是在physical memory和外部存储(如disk)间tranfer的单位,page fault是指一次由硬件引发,传递给软件的interrupt或者exception。它发生的时机是一个page被映射到了内存地址空间,可是该 page没有被实际装载到物理内存。
page fault的类型:
Page Mapped |
Page Loaded |
Page Status |
Page access valid |
Exception |
yes |
yes |
present |
yes |
No exception |
yes |
-- |
not present |
yes |
Page fault |
no |
yes |
yes |
yes |
Protection fault |
-- |
-- |
-- |
no |
Protection faul |
1: Minor Page Fault:
如 果page被load到内存当中的时候page fault发生了,可是它的状态在hardware中没有被更新为Present,被称为一个minor 或者 soft page fault。它发生的缘由多是因为内存已经load完成,但当时它是一个shared memory被多个不一样的程序使用。由于这种fault不会致使disk latency,因此它同major page fault来比,速度更快而且开销更小。
2 Major Page Fault:
若是page没有被load到内存当中,则称为 major或hard page fault。Major fault比minor fault带来更大的开销,会为运行的程序带来disk latency。它主要是考虑为os增长可用的内存地址空间,就是说,只有在须要的时候,才将须要的page或者内存块load到内存当中。
3 Invalid page fault:
若是一个page fault是因为引用了无效的page{NULL}引起的page fault。
4 protection page fault:
当 程序试图访问无效的page时候,如访问没有被映射到memory的page、或者写一个read-only page、或者修改一个优先级不匹配的page,os会产生一个protection fault。并非全部的protection faults都是illegal access, 他是os用来实现copy-on-write访问被多个programms共享的内存, 当有个program试图修改这个copy的机制。
sar -c: 用来统计报告一段时间内的process 建立的状况。
sar -c :
15时30分01秒 proc/s
15时40分01秒 0.39
15时50分01秒 1.07
16时00分01秒 1.12
16时10分01秒 0.61
16时20分01秒 0.34
16时30分01秒 0.36
Average: 0.37
sar -d: 每一个block device 活动状况的报告
05时10分01秒 DEV tps rd_sec/s wr_sec/s
05时20分01秒 dev104-0 0.85 0.00 12.29
05时20分01秒 dev104-1 0.23 0.00 4.16
05时20分01秒 dev104-2 0.00 0.00 0.00
05时20分01秒 dev104-3 0.19 0.00 2.24
Average: dev104-0 0.90 0.00 14.16
Average: dev104-1 0.24 0.00 4.57
Average: dev104-2 0.00 0.00 0.00
Average: dev104-3 0.20 0.00 2.74
Average: dev104-4 0.00 0.00 0.00
Average: dev104-5 0.37 0.00 5.94
Average: dev104-6 0.08 0.00 0.92
DEV:devm-n, m是major number of the device, and n is the minor number of the device
tps: transfer per second, rd_sec/s : sectors read per second; wr_sec/s: sectors written per second.
sar -n DEV | EDEV | SOCK | FULL: 网络统计报告
sar -n DEV的统计结果:
05时10分01秒 IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
05时20分01秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
05时20分01秒 eth0 0.13 0.12 11.78 12.41 0.00 0.00 0.00
05时20分01秒 eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
....
Average: lo 0.00 0.00 0.09 0.09 0.00 0.00 0.00
Average: eth0 0.16 0.13 14.04 14.49 0.00 0.00 0.00
Average: eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
IFACE: network interfaces; rxpck/s: total number of packets received per second; txpck/s: total number packets transmitted per second; rxbyt/s: total number bytes received per second; txbyt/s: total number bytes send per second. rxcmp/s: Number of compressed packets received per second; txcmp/s: Number of compressed packets transmitted per second. rxmcst/s: Number of multicast packets received per second.
sar -n EDEV:的统计结果:网络设备上出错统计状况的统计
10时20分01秒 IFACE rxerr/s txerr/s coll/s rxdrop/s txdrop/s txcarr/s rxfram/s rxfifo/s txfifo/s
10时30分01秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10时30分01秒 eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10时30分01秒 eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
IFACE: 同上; rxerr/s: 每秒钟收到的bad packets的数目;txerr/s: 每秒发送的bad packets的数目; coll/s:传送packets时,每秒发生的碰撞次数; rxdrop/s:每秒钟内因为linux的buffer满而丢弃的packet,txdrop/s:
txcarr/s: 在传送packets时,每秒内发生的carrier 错误的数目。rxfram/s: Number of frame alignment errors that happened per second on received packets.
rxfifo/s: Number of FIFO overrun errors that happened per second on received packets. txfifo/s:Number of FIFO overrun errors that happened per second on transmitted packets.
sar -n SOCK:对使用中sockets的统计
10时20分01秒 totsck tcpsck udpsck rawsck ip-frag
10时30分01秒 34 6 1 0 0
10时40分01秒 34 6 1 0 0
10时50分01秒 34 6 1 0 0
11时00分01秒 34 6 1 0 0
Average: 32 4 1 0 0
其 中: totsck:一共使用了多少sockets, tcpsck当前使用的tcp sockets的数目。 udpsck: 当前使用的udp sockets的数目; rawsck:当前使用的RAW socket的数目; ip-frag: number of ip-fragment currently in use.
sar -P cpu|ALL:
11时05分51秒 CPU %user %nice %system %iowait %idle
11时05分53秒 all 0.87 0.00 0.25 0.62 98.25
11时05分53秒 0 3.50 0.00 0.50 1.00 95.00
11时05分53秒 1 0.00 0.00 0.50 0.50 99.00
11时05分53秒 2 0.00 0.00 0.00 1.00 99.00
11时05分53秒 3 0.00 0.00 0.00 0.00 100.00
Average: CPU %user %nice %system %iowait %idle
Average: all 0.87 0.00 0.25 0.62 98.25
Average: 0 3.50 0.00 0.50 1.00 95.00
Average: 1 0.00 0.00 0.50 0.50 99.00
Average: 2 0.00 0.00 0.00 1.00 99.00
Average: 3 0.00 0.00 0.00 0.00 100.00
sar -q : queue length 和 load average统计报告
10时20分01秒 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
10时30分01秒 5 67 0.00 0.00 0.00
10时40分01秒 4 67 0.00 0.00 0.00
10时50分01秒 4 68 0.00 0.00 0.00
11时00分01秒 3 68 0.00 0.00 0.00
Average: 4 64 0.00 0.00 0.00
runq-sz: 运行队列长度(等待cpu执行的processes); plist-sz:在process list当中的processes的数目; ldavg-1, ldavg-5, ldavg-15:在1分钟、5分钟、15分钟间隔内的系统负载。
sar -r : memory and swap space utilization statistics report。
0时20分01秒 kbmemfree kbmemused %memused kbbuffers kbcached kbswpfree kbswpused %swpused kbswpcad
10时30分01秒 557912 1467444 72.45 226968 960672 4148320 45912 1.09 12888
10时40分01秒 557768 1467588 72.46 226968 960700 4148320 45912 1.09 12888
10时50分01秒 557184 1468172 72.49 226968 960736 4148320 45912 1.09 12888
11时00分01秒 558136 1467220 72.44 226968 960764 4148320 45912 1.09 12888
11时10分01秒 557392 1467964 72.48 226968 960812 4148320 45912 1.09 12888
11时20分01秒 557928 1467428 72.45 226968 960840 4148320 45912 1.09 12888
11时30分01秒 558268 1467088 72.44 226968 960872 4148320 45912 1.09 12888
Average: 559755 1465601 72.36 226966 960732 4148320 45912 1.09 12888
sar -R : report memory statistics.
10时20分01秒 frmpg/s bufpg/s campg/s
10时30分01秒 0.06 0.00 0.02
10时40分01秒 -0.06 0.00 0.01
10时50分01秒 -0.24 0.00 0.02
11时00分01秒 0.40 0.00 0.01
11时10分01秒 -0.31 0.00 0.02
11时20分01秒 0.22 0.00 0.01
11时30分01秒 0.14 0.00 0.01
11时40分01秒 -0.33 0.00 0.01
Average: -0.01 0.00 -0.00
frmpg/s: Number of memory pages freed by the system per second.
bufpg/s: Number of additional memory pages used as buffers by the system per second.
campg/s: Number of additional memory pages cached by the system per second.
sar -u: cpu utilization
10时20分01秒 CPU %user %nice %system %iowait %idle
10时30分01秒 all 0.04 0.00 0.05 0.17 99.73
10时40分01秒 all 0.04 0.00 0.07 0.19 99.70
10时50分01秒 all 0.05 0.00 0.06 0.15 99.74
11时00分01秒 all 0.04 0.00 0.03 0.17 99.76
11时10分01秒 all 0.05 0.00 0.10 0.23 99.63
11时20分01秒 all 0.04 0.00 0.07 0.17 99.73
11时30分01秒 all 0.04 0.00 0.05 0.16 99.75
11时40分01秒 all 0.04 0.00 0.05 0.18 99.73
Average: all 0.05 0.00 0.06 0.16 99.74
sar -v:关于inode、file和其它kernel tables的状态的报告
10时20分01秒 dentunusd file-sz inode-sz super-sz %super-sz dquot-sz %dquot-sz rtsig-sz %rtsig-sz
10时30分01秒 142499 4418 137709 0 0.00 0 0.00 0 0.00
10时40分01秒 142498 4414 137708 0 0.00 0 0.00 0 0.00
10时50分01秒 142500 4415 137708 0 0.00 0 0.00 0 0.00
11时00分01秒 142498 4418 137706 0 0.00 0 0.00 0 0.00
11时10分01秒 142501 4411 137708 0 0.00 0 0.00 0 0.00
11时20分01秒 142500 4419 137708 0 0.00 0 0.00 0 0.00
11时30分01秒 142496 4393 137708 0 0.00 0 0.00 0 0.00
11时40分01秒 142497 4400 137708 0 0.00 0 0.00 0 0.00
Average: 142504 4450 137706 0 0.00 0 0.00 0 0.00
dentunusd: Number of unused cache entries in the directory cache.
file-sz: number of used file handles.
inode-sz: number of used inode handles.
super-sz: number of super block handlers allocated by the kernel.
super-sz%: Percentage of allocated super block handlers with regard to the maximum number of super block handlers that Linux can allocate.
dquot-sz: number of disk quote entry allocated by the system.
%dquot-sz:
rtsig-sz: Number of queued RT signals.
%rtsig-sz : percentage of ...
sar -w: report of system switches activities.
10时20分01秒 cswch/s
10时30分01秒 19.92
10时40分01秒 20.11
10时50分01秒 19.67
11时00分01秒 23.10
11时10分01秒 33.17
11时20分01秒 31.34
11时30分01秒 19.39
11时40分01秒 22.19
11时50分01秒 25.07
12时00分01秒 19.83
Average: 22.09
sar -W: swapping 统计报告
10时20分01秒 pswpin/s pswpout/s
11时20分01秒 0.00 0.00
11时30分01秒 0.00 0.00
11时40分01秒 0.00 0.00
11时50分01秒 0.00 0.00
12时00分01秒 0.00 0.00
12时10分01秒 0.00 0.00
Average: 0.00 0.00
sar -x pid |SELF|ALL: 对指定process的统计 或者全部processes的统计(ALL)sar -X pid | SELF | ALL: 对指定process的子进程的统计