簡介
pidstat主要用於監控全部或指定進程占用系統資源的情況,如CPU,內存、設備IO、任務切換、線程等。pidstat首次運行時顯示自系統啟動開始的各項統計信息,之后運行pidstat將顯示自上次運行該命令以后的統計信息。用戶可以通過指定統計的次數和時間來獲得所需的統計信息。
實例講解
默認參數
執行pidstat,將輸出系統啟動后所有活動進程的cpu統計信息:
linux:~ # pidstat Linux 2.6.32.12-0.7-default (linux) 06/18/12 _x86_64_ 11:37:19 PID %usr %system %guest %CPU CPU Command …… 11:37:19 11452 0.00 0.00 0.00 0.00 2 bash 11:37:19 11509 0.00 0.00 0.00 0.00 3 dd
指定采樣周期和采樣次數
pidstat命令指定采樣周期和采樣次數,命令形式為”pidstat [option] interval [count]”,以下pidstat輸出以2秒為采樣周期,輸出10次cpu使用統計信息:
pidstat 2 10
cpu使用情況統計(-u)
使用-u選項,pidstat將顯示各活動進程的cpu使用統計,執行”pidstat -u”與單獨執行”pidstat”的效果一樣。
內存使用情況統計(-r)
使用-r選項,pidstat將顯示各活動進程的內存使用統計:
linux:~ # pidstat -r -p 13084 1 Linux 2.6.32.12-0.7-default (linux) 06/18/12 _x86_64_ 15:08:18 PID minflt/s majflt/s VSZ RSS %MEM Command 15:08:19 13084 133835.00 0.00 15720284 15716896 96.26 mmmm 15:08:20 13084 35807.00 0.00 15863504 15849756 97.07 mmmm 15:08:21 13084 19273.87 0.00 15949040 15792944 96.72 mmmm
以上各列輸出的含義如下:
minflt/s: 每秒次缺頁錯誤次數(minor page faults),次缺頁錯誤次數意即虛擬內存地址映射成物理內存地址產生的page fault次數 majflt/s: 每秒主缺頁錯誤次數(major page faults),當虛擬內存地址映射成物理內存地址時,相應的page在swap中,這樣的page fault為major page fault,一般在內存使用緊張時產生 VSZ: 該進程使用的虛擬內存(以kB為單位) RSS: 該進程使用的物理內存(以kB為單位) %MEM: 該進程使用內存的百分比 Command: 拉起進程對應的命令
IO情況統計(-d)
使用-d選項,我們可以查看進程IO的統計信息:
linux:~ # pidstat -d 1 2 Linux 2.6.32.12-0.7-default (linux) 06/18/12 _x86_64_ 17:11:36 PID kB_rd/s kB_wr/s kB_ccwr/s Command 17:11:37 14579 124988.24 0.00 0.00 dd 17:11:37 PID kB_rd/s kB_wr/s kB_ccwr/s Command 17:11:38 14579 105441.58 0.00 0.00 dd
輸出信息含義
kB_rd/s: 每秒進程從磁盤讀取的數據量(以kB為單位) kB_wr/s: 每秒進程向磁盤寫的數據量(以kB為單位) Command: 拉起進程對應的命令
針對特定進程統計(-p)
使用-p選項,我們可以查看特定進程的系統資源使用情況:
linux:~ # pidstat -r -p 1 1 Linux 2.6.32.12-0.7-default (linux) 06/18/12 _x86_64_ 18:26:17 PID minflt/s majflt/s VSZ RSS %MEM Command 18:26:18 1 0.00 0.00 10380 640 0.00 init 18:26:19 1 0.00 0.00 10380 640 0.00 init ……
pidstat常用命令
使用pidstat進行問題定位時,以下命令常被用到:
pidstat -u 1 pidstat -r 1 pidstat -d 1
以上命令以1秒為信息采集周期,分別獲取cpu、內存和磁盤IO的統計信息。