Linux系统IO分析⼯具之iotop参数详解(查看IO占⽤)
这篇⽂章主要介绍了Linux系统IO分析⼯具之iotop参数详解(查看IO占⽤),本⽂着重注解了iotop⼯具的参数,以及可操作命令,需要的朋友可以参考下
简介:
iotop – simple top-like I/O monitor
iotop是⼀个⽤来监视磁盘I/O使⽤状况的 top 类⼯具,可监测到哪⼀个程序使⽤的磁盘IO的信息(requires 2.6.20 or later)
安装:
复制代码
代码如下:
yum -y install iotop
git使用详解⽤法:
复制代码
代码如下:
iotop [OPTIONS]
选项:
复制代码
代码如下:
--version #显⽰版本号
-h, --help #显⽰帮助信息
-o, --only #显⽰进程或者线程实际上正在做的I/O,⽽不是全部的,可以随时切换按o
-b, --batch #运⾏在⾮交互式的模式
-n NUM, --iter=NUM #在⾮交互式模式下,设置显⽰的次数,
-
d SEC, --delay=SEC #设置显⽰的间隔秒数,⽀持⾮整数值
-p PID, --pid=PID #只显⽰指定PID的信息
-u USER, --user=USER #显⽰指定的⽤户的进程的信息
-P, --processes #只显⽰进程,⼀般为显⽰所有的线程
-a, --accumulated #显⽰从iotop启动后每个线程完成了的IO总数
-k, --kilobytes #以千字节显⽰
-t, --time #在每⼀⾏前添加⼀个当前的时间
-q, --quiet #suppress some lines of header (implies --batch). This option can be specified up to three times to remove header lines.
-q column names are only printed on the first iteration,
-qq column names are never printed,
-qqq the I/O summary is never printed.
可⽤的命令(在运⾏iotop命令后按相应键位):
使⽤left和right改变排序(⽅向键改变排序列),还可使⽤以下命令:
复制代码
代码如下:
r:反向排序,
o:切换⾄选项--only,
p:切换⾄--processes选项,
a:切换⾄--accumulated选项
q:退出
i:改变线程的优先级
例⼦:
复制代码
代码如下:
$ iotop
$ iotop –b –n 3 –d 5
iotop命令是专门显⽰硬盘IO的命令,界⾯风格类似top命令。这个命令只有在kernelv2.6.20及以后的版本中才有。
1、直接yum安装,rh6的光盘⾥有包。
yum install iotop
2、命令参数介绍
-o, --only
Only show processes or threads actually doing I/O, instead of showing all processes or threads. This can be dynamically toggled by pressing o.
-b, --batch
Turn on non-interactive mode. Useful for logging I/O usage over time.
-n NUM, --iter=NUM
Set the number of iterations before quitting (never quit by default). This is most useful in non-interactive mode.
-d SEC, --delay=SEC
Set the delay between iterations in seconds (1 second by default). Accepts non-integer values such as 1.1 seconds.
-p PID, --pid=PID
A list of processes/threads to monitor (all by default).
-u USER, --user=USER
A list of users to monitor (all by default)
-P, --processes
Only show processes. Normally iotop shows all threads.
-a, --accumulated
Show accumulated I/O instead of bandwidth. In this mode, iotop shows the amount of I/O processes have done since iotop started.
-k, --kilobytes
Use kilobytes instead of a human friendly unit. This mode is useful when scripting the batch mode of iotop. Instead of choosing the most appropriate unit iotop will dis‐
play all sizes in kilobytes.
-t, --time
Add a timestamp on each line (implies --batch). Each line will be prefixed by the current time.
-q, --quiet
suppress some lines of header (implies --batch). This option can be specified up to three times to remove header lines. -q column names are only printed on the first iteration,
-qq column names are never printed,
-qqq the I/O summary is never printed.
3、使⽤截图
[root@localhost tmp]# iotop -o
iotop命令的键盘快捷键:
1、左右箭头改变排序⽅式,默认是按IO排序
2、r键是反向排序
3、o键是只显⽰有IO输出的进程
4、同样q是退出
介绍
Linux下的IO统计⼯具如iostat, nmon等⼤多数是只能统计到per设备的读写情况, 如果你想知道每个进程是如何使⽤IO的就⽐较⿇烦. iotop 是⼀个⽤来监视磁盘 I/O 使⽤状况的 top 类⼯具。iotop 具有与 top 相似的 UI,其中包括 PID、⽤户、I/O、进程等相关信息。
实例
直接运⾏就好
iotop
输出如下
Total DISK READ: 6.01 M/s | Total DISK WRITE: 3.85 K/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 20074 be/4 hadoop 6.01 M/s 0.00 B/s 0.00 % 4.54 % java -Dproc_datanode -Xmx8192m -server
org.apache.hadoop.hdfs.server.datanode.DataNode
6371 be/4 hadoop 0.00 B/s 3.25 M/s 0.00 % 0.00 % java -Dproc_datanode -Xmx8192m -server
org.apache.hadoop.hdfs.server.datanode.DataNode
8497 be/4 hadoop 0.00 B/s 3.67 M/s 0.00 % 0.00 % java -Dproc_datanode -Xmx8192m -server
org.apache.hadoop.hdfs.server.datanode.DataNode
1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % init
2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd]
通过输出结果,我们可以清楚地知晓是什么程序在读写磁盘,速度以及命令⾏,pid 等信息。
在使⽤LINUX时经常会遇到系统IO占⽤很⾼,系统IO占⽤可以使⽤iostat -x 1查看
但很多时候知道磁盘IO负载⾼,但并不知道是什么程序占⽤的,是PHP,还是MYSQL,还是其它的,这就不好查看了。iotop⼯具可以实现以ubuntu为例:
安装
root@ubuntu111064:~# apt-get install iotop
安装完成后
执⾏iotop
就可以看到类似top⼀样的显⽰
iotop 详细参数:
root@ubuntu111064:~# iotop -h
unable to set locale, falling back to the default locale
Usage: /usr/bin/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).
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, q to quit, any other key to force
a refresh.
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)
-p 指定进程ID,显⽰该进程的IO情况
-u 指定⽤户名,显⽰该⽤户所有的进程IO情况
iotop 需要python版本>=2.5,且系统内核>=2.6.20
iotop可以显⽰磁盘读写的速率,交换分区进出情况和整体磁盘性能状况,这些都是按照每个进程使⽤情况来统计。进程列表按照I/O使⽤状态排序并每秒刷新⼀次。
前⾔:
在⼀般运维⼯作中经常会遇到这么⼀个场景,服务器的IO负载很⾼(iostat中的util),但是⽆法快速的定位到IO负载的来源进程和来源⽂件导致⽆法进⾏相应的策略来解决问题。
这个现象在MySQL上更为常见,在5.6(performance_schema提供io instrument)之前,我们通常只能猜到是MySQL导致的⾼IO,但是没法定位具体是哪个⽂件带来的负载。
例如是ibdata的刷写?还是冷门ibd的随机读取?
本⽂就将介绍⼀个⽐较简单的定位IO⾼负载的流程。
⼯具准备:
Step1 : iostat 查看IO情况
iostat -x 1 查看IO情况,从下图可以看到dfa这个磁盘的IO负载较⾼,接下来我们就来定位具体的负载来源
Step2: iotop定位负载来源进程
iotop的本质是⼀个python脚本,从proc中获取thread的IO信息,进⾏汇总。
从下图可以看出⼤部分的IO来源都来⾃于mysqld进程。因此可以确定dfa的负载来源是数据库
Step3 pt-ioprofile定位负载来源⽂件
pt-ioprofile的原理是对某个pid附加⼀个strace进程进⾏IO分析。
以下是摘⾃官⽹的⼀段警⽰:
However, it works by attaching strace to the process using ptrace(), which will make it run very slowly
until strace detaches. In addition to freezing the server, there is also some risk of the process crashing or performing badly after strace detaches from it, or indeed of strace not detaching cleanly and leaving the process in a sleeping state.
As a result, this should be considered an intrusive tool, and should not be used on production servers unless you are comfortable with that.
通过ps aux|grep mysqld 到 mysqld进程对应的进程号,通过pt-ioprofile查看哪个⽂件的IO占⽤时间最多。
默认参数下该⼯具展⽰的是IO占⽤的时间。
对于定位问题更有⽤的是通过IO的吞吐量来进⾏定位。使⽤参数 --cell=sizes,该参数将结果已 B/s 的⽅式展⽰出来
从上图可以看出IO负载的主要来源是sbtest (sysbench的IO bound OLTP测试)。
并且压⼒主要集中在读取上。
iotop命令是专门显⽰硬盘IO的命令,界⾯风格类似top命令。这个命令只有在kernelv2.6.20及以后的版本中才有。python版本需要python2.7及以上版本
官⽅的说明:
Linux has always been able to show how much I/O was going on (the bi and bo columns of the vmstat 1 command).
Iotop is a Python program with a top like UI used to show of behalf of which process is the I/O going on. It requires Python ≥ 2.7 and a Linux kernel ≥ 2.6.20 with the TASK_DELAY_ACCT CONFIG_TASKSTATS, TASK_IO_ACCOUNTING and CONFIG_VM_EVENT_COUNTERS options on.
iotop安装:
直接yum安装。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论