
027 霧中天鵝的副本.png
1 sar 命令查看當(dāng)前磁盤 IO 讀寫
sar(System Activity Reporter 系統(tǒng)活動(dòng)情況報(bào)告)是 Linux 上最為全面的系統(tǒng)性能分析工具之一,可以從多方面對(duì)系統(tǒng)的活動(dòng)進(jìn)行報(bào)告,包括:文件的讀寫情況、系統(tǒng)調(diào)用的使用情況、磁盤I/O、CPU效率、內(nèi)存使用狀況、進(jìn)程活動(dòng)等。
(1)sar 工具安裝
yum install sysstat
(2)sar 查看磁盤IO讀寫情況
# 查看當(dāng)前磁盤 IO 讀寫,每 1 秒顯示 1 次 顯示 10次。
sar -b 1 10

file
- tps # 每秒向磁盤設(shè)備請(qǐng)求數(shù)據(jù)的次數(shù),包括讀、寫請(qǐng)求,為 rtps 與 wtps 的和。出于效率考慮,每一次 IO 下發(fā)后并不是立即處理請(qǐng)求,而是將請(qǐng)求合并,這里 tps 指請(qǐng)求合并后的請(qǐng)求計(jì)數(shù)
- rtps # 每秒向磁盤設(shè)備的讀請(qǐng)求次數(shù)
- wtps # 每秒向磁盤設(shè)備的寫請(qǐng)求次數(shù)
- bread # 每秒從磁盤讀的 bytes 數(shù)量
- bwrtn # 每秒向磁盤寫的 bytes 數(shù)量
2 iotop 命令查看磁盤 IO 性能
iotop 命令是一個(gè)用來監(jiān)視磁盤 I/O 使用狀況的工具。iotop 是進(jìn)程級(jí)別 IO 監(jiān)控。
(1)iotop 工具安裝
yum install iotop
(2)iotop 的常用用例
- iotop -o # 只顯示正在產(chǎn)生 IO 的進(jìn)程或線程;
- iotop -d 3 -n 5 # 時(shí)間間隔 3 秒,輸出 5 次;
- iotop -botq -p 8382 # 輸出 pid 為 8382 的進(jìn)程 IO 情況
(3)iotop 可選參數(shù)說明
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 磁盤性能壓測(cè)工具 fio
(1)fio 工具安裝
yum install fio
(2)IOPS 壓測(cè)示例
- (/data/test 這個(gè)是壓測(cè)數(shù)據(jù)讀寫目錄)
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)帶寬壓測(cè)
- (/data/test 這個(gè)是壓測(cè)數(shù)據(jù)讀寫目錄)
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 是系統(tǒng)級(jí)別的 IO 監(jiān)控,而 iotop 是進(jìn)程級(jí)別 IO 監(jiān)控。
iostat -d -k 1 10 #查看TPS和吞吐量信息(磁盤讀寫速度單位為KB)
iostat -d -m 2 #查看TPS和吞吐量信息(磁盤讀寫速度單位為MB)
iostat -d -x -k 1 10 #查看設(shè)備使用率(%util)、響應(yīng)時(shí)間(await)
iostat -c 1 10 #查看cpu狀態(tài)
5 簡(jiǎn)單驗(yàn)證磁盤是否故障
在目標(biāo)磁盤上 touch 一個(gè)空文件看看,是否磁盤故障導(dǎo)致無法寫入。
6 查看文件屬于哪個(gè)盤
查看文件屬于哪個(gè)盤
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測(cè)試工具之fio詳解:https://www.cnblogs.com/raykuan/p/6914748.html
8 小結(jié)
磁盤 IO 性能監(jiān)控/壓測(cè)工具常用的有 sar、iotop、fio、iostat 。這篇文章只是簡(jiǎn)單記錄涉及相關(guān)命令的使用,不做過多詳細(xì)的深入使用實(shí)踐說明,只是起到一個(gè)簡(jiǎn)單的拋磚引玉。
「不甩鍋的碼農(nóng)」原創(chuàng),轉(zhuǎn)載請(qǐng)注明來源,未經(jīng)授權(quán)禁止商業(yè)用途!同名 GZH 請(qǐng)關(guān)注!