Linux 系統信息監控統計命令小結

轉貼
[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的子進程的統計
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章