iotop:一款相似top的I/O監控工具。python
項目主頁:http://guichaz.free.fr/iotop/linux
iotop由python編寫(運行需安裝Python ≥ 2.7)經過linux內核(2.6.20以上)來監控I/O信息,經過列表的方式展現了當前系統中進程/線程的I/O使用率。若是想要經過iotop獲取I/O信息,那麼在Linux內核編譯時,須要開啓CONFIG_TASK_DELAY_ACCT、CONFIG_TASK_IO_ACCOUNTING, CONFIG_TASKSTATS 和 CON‐FIG_VM_EVENT_COUNTERS這三個變量。 git
iotop監控的主要項:api
進程/線程的I/O的讀寫帶寬bash
進程/線程swapin的耗時佔比app
進程/線程的I/O阻塞(等待)耗時佔比ionic
每一個進程/線程的I/O優先級ide
系統中I/O總讀寫帶寬工具
系統中I/O實際讀寫帶寬(和總讀寫帶寬有時候值並不一致)測試
Ubuntu
sudo apt install -y iotop
Centos
sudo yum install -y iotop
#下載源碼 git clone git://repo.or.cz/iotop.git #進入對應目錄 cd iotop #編譯 python setup.py build #安裝 sudo python setup.py install
3.幫助
輸入:iotop -h
Usage: /usr/sbin/iotop [OPTIONS]
DISK READ and DISK WRITE are the block I/O bandwidth used during the sampling
period. SWAPIN and IO are the percentages of time the thread spent respectively
while swapping in and waiting on I/O more generally. PRIO is the I/O priority at
which the thread is running (set using the ionice command).
/*
DISK READ:採樣週期內讀磁盤的帶寬(平均值)
DISK WRITE:採用週期內寫磁盤的帶寬(平均值)
SWAPIN:磁盤換入的時間佔總時間的百分比(內存不夠用的時候會進行內存換入到磁盤)
IO: 普通的磁盤讀寫等待時間佔總時間的百分比
PRIO: 進程/線程進行I/O調度時候的優先級(使用ionice設定)
*/
Controls: left and right arrows to change the sorting column, r to invert the
sorting order, o to toggle the --only option, p to toggle the --processes
option, a to toggle the --accumulated option, i to change I/O priority, q to
quit, any other key to force a refresh.
/*
按鍵控制:
⬅️/➡️:選擇排序的列
r:按逆序排列當前IO進程/線程列表
o:同--only參數
p: 同--processes參數
a: 同--accumulated參數
i: 改變I/O優先級
q: 退出iotop
其餘任意鍵:強制刷新當前IO進程/線程列表
*/
Options:
--version show program's version number and exit //顯示版本信息
-h, --help show this help message and exit //顯示幫助信息
-o, --only only show processes or threads actually doing I/O //顯示當前有I/O活動的進程或者線程(也就是沒有進行IO操做的進程/線程不展現到列表)
-b, --batch non-interactive mode //非交互模式,即後臺模式(這個能夠把信息重定位輸出到某個文件)
-n NUM, --iter=NUM number of iterations before ending [infinite] //信息刷新次數,默認一直刷新,不會自行退出;若是指定該參數爲N,則iotop在更新N次列表信息後自動退出(此參數在批處理模式下比較方便)
-d SEC, --delay=SEC delay between iterations [1 second] //信息刷新間隔,即每隔幾秒刷新一次,默認爲每隔一秒刷新一次
-p PID, --pid=PID processes/threads to monitor [all] //篩選展現特定PID的進程或者線程,默認爲全部進程/線程
-u USER, --user=USER users to monitor [all] //篩選展現特定用戶下進程/線程IO,默認爲全部用戶
-P, --processes only show processes, not all threads //篩選只展現進程的IO信息,默認展現全部進程和線程的IO信息
-a, --accumulated show accumulated I/O instead of bandwidth //設置IO的值爲累計IO而不是實時IO
-k, --kilobytes use kilobytes instead of a human friendly unit //設置IO的單位爲KB/s,默認根據IO大小自行進行單位適配。(在批處理模式下設置比較方便統計)
-t, --time add a timestamp on each line (implies --batch) //批處理模式,在每行前面加上時間戳
-q, --quiet suppress some lines of header (implies --batch) //批處理模式,只在打印一次列名
-qq column names are never printed, //不打印列名
-qqq the I/O summary is never printed. //連概要信息也不打印
1.每隔十秒打印一次信息,僅打印有活躍I/O的進程和線程數據
iotop -d 10 -o
2.每隔十秒打印一次信息,設置單位爲KB/s,僅打印有活躍I/O的進程和線程數據
iotop -d 10 -o -k
3.每隔十秒打印一次信息,設置單位爲KB/s, 使用累加模式,僅打印有活躍I/O的進程和線程數據
iotop -d 10 -o -k -a
如圖:紅框裏面變成累加值而不是實時值(對比上圖)
4.批處理模式1
每隔十秒將iotop中的有活躍IO的進程/線程相關信息輸出到文件控制檯,並同時輸出到文件
iotop -d 10 -o -b | tee iotop.result
5.批處理模式2
其餘同上,增長了兩個參數,-n和-k,使用計量單位爲KB/s,統計十次後自動退出
iotop -d 10 -o -b -k -n 10 | tee iotop.result
6.批處理模式3
這裏指定了只打印PID爲2025的進程,且在每行都加上時間戳
iotop -p 2025 -t -b -n 10 | tee iotop.result
咱們能夠利用第六個例子來獲取機器上指定進程的IO信息
例如:機器上部署了兩個服務,進程id分別爲2025和345,而後執行以下命令(-n自行修改,-n的次數乘以-d的時間即爲總統計時間,以下面應該是10*10等於100秒)
iotop -p 2025 -p 345 -t -b -n 10 -d 10| tee iotop.result
而後用awk或者python解析iotop.result,能夠生成對應的csv文件。
利用csv文件能夠再excel中繪製曲線圖或者用python的圖形庫直接繪圖。
博主:測試生財
座右銘:專一測試與自動化,致力提升研發效能;經過測試精進完成原始積累,經過讀書理財奔向財務自由。
csdn:https://blog.csdn.net/ccgshigao