安裝sysstat rpm包就有iostat、mpstat、sar、sa的功能,rpm –Uvh sysstat*
另一個用于獲取 CPU 相關統計信息的有用的命令是 mpstat。下面是一個示例輸出:
# mpstat -P ALL 5 2
Linux 2.6.9-67.ELsmp (oraclerac1) 12/20/2008
10:42:38 PM CPU %user %nice %system %iowait %irq %soft %idle intr/s
10:42:43 PM all 6.89 0.00 44.76 0.10 0.10 0.10 48.05 1121.60
10:42:43 PM 0 9.20 0.00 49.00 0.00 0.00 0.20 41.60 413.00
10:42:43 PM 1 4.60 0.00 40.60 0.00 0.20 0.20 54.60 708.40
10:42:43 PM CPU %user %nice %system %iowait %irq %soft %idle intr/s
10:42:48 PM all 7.60 0.00 45.30 0.30 0.00 0.10 46.70 1195.01
10:42:48 PM 0 4.19 0.00 2.20 0.40 0.00 0.00 93.21 1034.53
10:42:48 PM 1 10.78 0.00 88.22 0.40 0.00 0.00 0.20 160.48
Average: CPU %user %nice %system %iowait %irq %soft %idle intr/s
Average: all 7.25 0.00 45.03 0.20 0.05 0.10 47.38 1158.34
Average: 0 6.69 0.00 25.57 0.20 0.00 0.10 67.43 724.08
Average: 1 7.69 0.00 64.44 0.20 0.10 0.10 27.37 434.17
它顯示了系統中 CPU 的各種統計信息。–P ALL 選項指示該命令顯示所有 CPU 的統計信息,而不只是特定 CPU 的統計信息。參數 5 2 指示該命令每隔 5 秒運行一次,共運行 2次。以上輸出首先顯示了所有 CPU 的合計指標,然后顯示了每個 CPU 各自的指標。最后,在結尾處顯示所有 CPU 的平均值。
讓我們看一看這些列值的含義:
%user 表示處理用戶進程所使用 CPU 的百分比。用戶進程是用于應用程序(如 Oracle 數據庫)的非內核進程。在本示例輸出中,用戶 CPU 百分比非常低。
%nice 表示使用 nice 命令對進程進行降級時 CPU 的百分比。在之前的部分中已經對 nice 命令進行了介紹。簡單來說,nice 命令更改進程的優先級。
%system 表示內核進程使用的 CPU 百分比
%iowait 表示等待進行 I/O 所使用的 CPU 時間百分比
%irq 表示用于處理系統中斷的 CPU 百分比
%soft 表示用于軟件中斷的 CPU 百分比
%idle 顯示 CPU 的空閑時間
%intr/s 顯示每秒 CPU 接收的中斷總數
當您擁有前面所述的 vmstat 時,您可能想知道 mpstat 命令的作用。差別很大:mpstat 可以顯示每個處理器的統計,而vmstat 顯示所有處理器的統計。因此,編寫糟糕的應用程序(不使用多線程體系結構)可能會運行在一個多處理器機器上,而不使用所有處理器。從而導致一個 CPU 過載,而其他 CPU 卻很空閑。通過 mpstat 可以輕松診斷這些類型的問題。
針對 Oracle 用戶的用法 與 vmstat 相似,mpstat 命令還產生與 CPU 有關的統計信息,因此所有與CPU 問題有關的討論也都適用于 mpstat。
當您看到較低的 %idle 數字時,您知道出現了 CPU 不足的問題。當您看到較高的 %iowait 數字時,您知道在當前負載下 I/O 子系統出現了某些問題。該信息對于解決 Oracle 數據庫性能問題非常方便。
Sar以下命令都可以interval count參數
[root@daidai ~]# sar -u 2 2
Linux 2.6.18-194.el5 (daidai.com) 06/20/2016
11:14:10 AM CPU %user %nice %system %iowait %steal %idle
11:14:12 AM all 0.25 0.00 0.00 0.25 0.00 99.49
11:14:14 AM all 0.00 0.50 0.76 0.00 0.00 98.74
Average: all 0.13 0.25 0.38 0.13 0.00 99.12
CPU all 表示統計信息為所有 CPU 的平均值。
%user 顯示在用戶級別(application)運行使用 CPU 總時間的百分比。
%nice 顯示在用戶級別,用于nice操作,所占用 CPU 總時間的百分比。
%system 在核心級別(kernel)運行所使用 CPU 總時間的百分比。
%iowait 顯示用于等待I/O操作占用 CPU 總時間的百分比。
%steal 管理程序(hypervisor)為另一個虛擬進程提供服務而等待虛擬 CPU 的百分比。
%idle 顯示 CPU 空閑時間占用 CPU 總時間的百分比。
tips:
若 %iowait 的值過高,表示硬盤存在I/O瓶頸
若 %idle 的值高但系統響應慢時,有可能是 CPU 等待分配內存,此時應加大內存容量
若 %idle 的值持續低于 10,則系統的 CPU 處理能力相對較低,表明系統中最需要解決的資源是 CPU。
[root@daidai ~]# sar -b 2 3
Linux 2.6.18-194.el5 (daidai.com) 06/20/2016
11:31:08 AM tps rtps wtps bread/s bwrtn/s
11:31:10 AM 3.03 0.00 3.03 0.00 129.29
11:31:12 AM 3.03 0.00 3.03 0.00 64.65
11:31:14 AM 3.05 0.00 3.05 0.00 64.97
Average: 3.04 0.00 3.04 0.00 86.34
tps 每秒鐘物理設備的 I/O 傳輸總量
rtps 每秒鐘從物理設備讀入的數據總量
wtps 每秒鐘向物理設備寫入的數據總量
bread/s 每秒鐘從物理設備讀入的數據量,單位為 塊/s
bwrtn/s 每秒鐘向物理設備寫入的數據量,單位為 塊/s
[root@daidai ~]# sar -c
Linux 2.6.18-194.el5 (daidai.com) 06/20/2016
09:50:01 AM proc/s
10:00:01 AM 0.38
10:10:01 AM 0.30
10:20:01 AM 0.30
10:30:01 AM 0.45
10:40:01 AM 0.30
11:20:01 AM 0.79
11:30:01 AM 0.28
Average: 0.43
每秒鐘創建的進程數
[root@daidai ~]# sar -n DEV 1 2
Linux 2.6.18-194.el5 (daidai.com) 06/20/2016
11:39:34 AM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
11:39:35 AM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
11:39:35 AM eth0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
11:39:35 AM sit0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
11:39:35 AM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
11:39:36 AM lo 2.04 2.04 102.04 102.04 0.00 0.00 0.00
11:39:36 AM eth0 3.06 5.10 183.67 867.35 0.00 0.00 0.00
11:39:36 AM sit0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
Average: lo 1.02 1.02 50.76 50.76 0.00 0.00 0.00
Average: eth0 1.52 2.54 91.37 431.47 0.00 0.00 0.00
Average: sit0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
IFACE 網絡設備名
rxpck/s 每秒接收的包總數
txpck/s 每秒傳輸的包總數
rxbyt/s 每秒接收的字節(byte)總數
txbyt/s 每秒傳輸的字節(byte)總數
rxcmp/s 每秒接收壓縮包的總數
txcmp/s 每秒傳輸壓縮包的總數
rxmcst/s 每秒接收的多播(multicast)包的總數
[root@daidai ~]# sar -q 1 3
Linux 2.6.18-194.el5 (daidai.com) 06/20/2016
11:42:54 AM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15
11:42:55 AM 0 184 0.02 0.02 0.00
11:42:56 AM 0 184 0.02 0.02 0.00
11:42:57 AM 0 184 0.02 0.02 0.00
Average: 0 184 0.02 0.02 0.00
runq-sz 運行隊列的長度(等待運行的進程數)
plist-sz 進程列表中進程(processes)和線程(threads)的數量
ldavg-1 最后1分鐘的系統平均負載(System load average)
ldavg-5 過去5分鐘的系統平均負載
ldavg-15 過去15分鐘的系統平均負載
[root@daidai ~]# sar -r
Linux 2.6.18-194.el5 (daidai.com) 06/20/2016
09:50:01 AM kbmemfree kbmemused %memused kbbuffers kbcached kbswpfree kbswpused %swpused kbswpcad
10:00:01 AM 1067600 3869580 78.38 195616 3249408 10482404 0 0.00 0
10:10:01 AM 1068624 3868556 78.36 195616 3249500 10482404 0 0.00 0
10:20:01 AM 1069492 3867688 78.34 195616 3249572 10482404 0 0.00 0
10:30:01 AM 1079024 3858156 78.14 195616 3249588 10482404 0 0.00 0
10:40:01 AM 1079676 3857504 78.13 195616 3249616 10482404 0 0.00 0
11:20:01 AM 1083792 3853388 78.05 195616 3249952 10482404 0 0.00 0
11:30:01 AM 1083420 3853760 78.06 195616 3249984 10482404 0 0.00 0
11:40:01 AM 1084164 3853016 78.04 195616 3250008 10482404 0 0.00 0
Average: 1076974 3860206 78.19 195616 3249704 10482404 0 0.00 0
kbmemfree Amountof free memory available in kilobytes.
kbmemused Amount of used memory in kilobytes. This doesnot take into account memory used by the kernel itself.
%memused Percentage of used memory.
kbbuffers Amount of memory used as buffers by thekernel in kilobytes.
kbcached Amount of memory used to cache data by thekernel in kilobytes.
kbswpfree Amount of free swap space in kilobytes.
kbswpused Amount of used swap space in kilobytes.
%swpused Percentage of used swap space.
kbswpcad Amount of cached swap memory inkilobytes. This is memory that once was swappedout, is swapped back in but still also is in the swap area (if memory is neededit doesn’t need to be swapped out again because it is already in the swap area.This saves I/O).
[root@daidai ~]# iostat 1 3
Linux 2.6.18-194.el5 (daidai.com) 06/20/2016
avg-cpu: %user %nice %system %iowait %steal %idle
0.23 0.02 0.43 0.11 0.00 99.22
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 3.15 15.25 60.92 3462295 13828032
sda1 3.15 15.24 60.92 3460258 13828032
sda2 0.00 0.01 0.00 1613 0
sr0 0.00 0.01 0.00 1644 0
avg-cpu: %user %nice %system %iowait %steal %idle
0.51 0.00 0.51 0.00 0.00 98.98
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
sda1 0.00 0.00 0.00 0 0
sda2 0.00 0.00 0.00 0 0
sr0 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.51 0.00 0.00 99.49
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 3.00 0.00 64.00 0 64
sda1 3.00 0.00 64.00 0 64
sda2 0.00 0.00 0.00 0 0
sr0 0.00 0.00 0.00 0 0
[root@daidai ~]# vmstat 1 5
procs -----------memory-------------swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 1083368 1957003250136 0 0 4 16 24 41 0 0 99 0 0
0 0 0 1083368 1957003250136 0 0 0 40 998 205 1 1 99 0 0
0 0 0 1083368 195700 3250136 0 0 0 32 998 221 0 298 1 0
0 0 0 1089088 1957003250136 0 0 0 0 998 218 0 1 99 0 0
0 0 0 1089088 1957003250136 0 0 0 0 1004 191 0 0 100 0 0
Procs
r: The number of processes waiting forrun time.
b: The number of processes inuninterruptible sleep.
Memory
swpd: the amount of virtual memory used.
free: the amount of idle memory.
buff: the amount of memory used asbuffers.
cache: the amount of memory used ascache.
inact: the amount of inactive memory.(-a option)
active: the amount of active memory. (-aoption)
Swap
si: Amount of memory swapped in fromdisk (/s).
so: Amount of memory swapped to disk(/s).
IO
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device(blocks/s).
System
in: The number of interrupts per second,including the clock.
cs: The number of context switches persecond.
CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code.(user time, including nice time)
sy: Time spent running kernel code.(system time)
id: Time spent idle. Prior to Linux2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior toLinux 2.5.41, included in idle.
st: Time stolen from a virtual machine.Prior to Linux 2.6.11, unknown.
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。