
- 1 sar 命令查看當前磁盤 IO 讀寫
- (1)sar 工具安裝
- (2)sar 查看磁盤IO讀寫情況
- 2 iotop 命令查看磁盤 IO 性能
- (1)iotop 工具安裝
- (2)iotop 的常用用例
- (3)iotop 可選引數說明
- 3 磁盤性能壓測工具 fio
- (1)fio 工具安裝
- (2)IOPS 壓測示例
- (3)帶寬壓測
- 4 iostat 的常用用例
- 5 簡單驗證磁盤是否故障
- 6 查看檔案屬于哪個盤
- 7 附錄
- 8 小結
1 sar 命令查看當前磁盤 IO 讀寫
sar(System Activity Reporter 系統活動情況報告)是 Linux 上最為全面的系統性能分析工具之一,可以從多方面對系統的活動進行報告,包括:檔案的讀寫情況、系統呼叫的使用情況、磁盤I/O、CPU效率、記憶體使用狀況、行程活動等,
(1)sar 工具安裝
yum install sysstat
(2)sar 查看磁盤IO讀寫情況
# 查看當前磁盤 IO 讀寫,每 1 秒顯示 1 次 顯示 10次,
sar -b 1 10

- tps # 每秒向磁盤設備請求資料的次數,包括讀、寫請求,為 rtps 與 wtps 的和,出于效率考慮,每一次 IO 下發后并不是立即處理請求,而是將請求合并,這里 tps 指請求合并后的請求計數
- rtps # 每秒向磁盤設備的讀請求次數
- wtps # 每秒向磁盤設備的寫請求次數
- bread # 每秒從磁盤讀的 bytes 數量
- bwrtn # 每秒向磁盤寫的 bytes 數量
2 iotop 命令查看磁盤 IO 性能
iotop 命令是一個用來監視磁盤 I/O 使用狀況的工具,iotop 是行程級別 IO 監控,
(1)iotop 工具安裝
yum install iotop
(2)iotop 的常用用例
- iotop -o # 只顯示正在產生 IO 的行程或執行緒;
- iotop -d 3 -n 5 # 時間間隔 3 秒,輸出 5 次;
- iotop -botq -p 8382 # 輸出 pid 為 8382 的行程 IO 情況
(3)iotop 可選引數說明
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
-b, --batch non-interactive mode
-n NUM, --iter=NUM number of iterations before ending [infinite]
-d SEC, --delay=SEC delay between iterations [1 second]
-p PID, --pid=PID processes/threads to monitor [all]
-u USER, --user=USER users to monitor [all]
-P, --processes only show processes, not all threads
-a, --accumulated show accumulated I/O instead of bandwidth
-k, --kilobytes use kilobytes instead of a human friendly unit
-t, --time add a timestamp on each line (implies --batch)
-q, --quiet suppress some lines of header (implies --batch)
3 磁盤性能壓測工具 fio
(1)fio 工具安裝
yum install fio
(2)IOPS 壓測示例
- (/data/test 這個是壓測資料讀寫目錄)
fio -directory=/data/test -direct=1 -iodepth 10 -thread -rw=randwrite -ioengine=psync -bs=4k -size=2G -numjobs=10 -runtime=180 -group_reporting -name=rand_write
(3)帶寬壓測
- (/data/test 這個是壓測資料讀寫目錄)
fio -directory=/data/test -direct=1 -iodepth 10 -thread -rw=randwrite -ioengine=psync -bs=4096k -size=2G -numjobs=10 -runtime=180 -group_reporting -name=rand_write
4 iostat 的常用用例
iostat 是系統級別的 IO 監控,而 iotop 是行程級別 IO 監控,
iostat -d -k 1 10 #查看TPS和吞吐量資訊(磁盤讀寫速度單位為KB)
iostat -d -m 2 #查看TPS和吞吐量資訊(磁盤讀寫速度單位為MB)
iostat -d -x -k 1 10 #查看設備使用率(%util)、回應時間(await)
iostat -c 1 10 #查看cpu狀態
5 簡單驗證磁盤是否故障
在目標磁盤上 touch 一個空檔案看看,是否磁盤故障導致無法寫入,
6 查看檔案屬于哪個盤
查看檔案屬于哪個盤
df /data/
7 附錄
sar使用:https://www.cnblogs.com/zcx-python/p/9001630.html
iostat 使用:https://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858810.html
IO測驗工具之fio詳解:https://www.cnblogs.com/raykuan/p/6914748.html
8 小結
磁盤 IO 性能監控/壓測工具常用的有 sar、iotop、fio、iostat ,這篇文章只是簡單記錄涉及相關命令的使用,不做過多詳細的深入使用實踐說明,只是起到一個簡單的拋磚引玉,
「不甩鍋的碼農」原創,轉載請注明來源,未經授權禁止商業用途!同名 GZH 請關注!
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/433261.html
標籤:Linux
