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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不甩锅的码农

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值