018 磁盘 IO 性能监控/压测工具(sar、iotop、fio、iostat)

2022/2/26 23:24:18

本文主要是介绍018 磁盘 IO 性能监控/压测工具(sar、iotop、fio、iostat),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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 

file

  • 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 请关注!



这篇关于018 磁盘 IO 性能监控/压测工具(sar、iotop、fio、iostat)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程