Linux iotop工具简介
iotop的简介:
iotop是一款开源、免费的用来监控磁盘i/o使用状况的类似top命令的工具,iotop可以监控进程的i/o信息。它是python语言编写的,与iostat工具比较,iostat是系统级别的io监控,而iotop是进程级别io监控。目前最新的版本为iotop 0.6。其官方网址http://guichaz.free.fr/iotop/
iotop的安装:
注意,iotop的安装有前提条件(如果操作系统不满足这些条件,iotop无法正确安装):
1:内核版本为2.6.20或更高版本
2:python 2.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安装
yum安装是最简单、快捷的。前提条件是你有配置yum的源配置。
[root@db-server ~]# python -v
python 2.7.5
[root@db-server ~]# uname -a
linux db-server 3.10.0-862.el7.x86_64 #1 smp fri apr 20 16:44:24 utc 2018 x86_64 x86_64 x86_64 gnu/linux
[root@db-server ~]#
[root@db-server ~]# yum -y install iotop
iotop的源码安装
wget http://guichaz.free.fr/iotop/files/iotop-0.6.tar.bz2
tar -xvf iotop-0.6.tar.gz
cd iotop-0.6
python setup.py build
python setup.py install
iotop的参数
# iotop --help
usage: /usr/local/sbin/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, i to change i/o priority, 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)
参数 |
长参数 |
参数描述 |
|
--version |
显示版本号 |
-h |
--help |
显示帮助信息 |
-o |
--only |
只显示正在产生i/o的进程或线程,运行过程中,可以通过按o随时切换 |
-b |
--batch |
非交互模式下运行,一般用来记录日志。 |
-n num |
--iter=num |
设置监控(显示)num次,主要用于非交互模式。默认无限 |
-d sec |
--delay=sec |
设置显示的间隔秒数,支持非整数 |
-p pid |
--pid=pid |
只显示指定进程(pid)的信息 |
-u user |
--user=user |
显示指定的用户的进程的信息 |
-p |
--processes |
只显示进程,不显示所有线程 |
-a |
--accumulated |
累积的i/o,显示从iotop启动后每个进程累积的i/o总数,便于诊断问题 |
-k |
--kilobytes |
显示使用kb单位 |
-t |
--time |
非交互模式下,加上时间戳。 |
-q |
--quiet |
只在第一次监测时显示列名. 去除头部一些行:这个参数可以设置最多3次来移除头部行:-q列头部只在最初交互显示一次;-qq列头部不显示;-qqq,i/o的总结不显示 |
iotop的快捷键
r:反向排序,
o:切换至选项--only,
p:切换至--processes选项,
a:切换至--accumulated选项
q:退出
i:改变线程的优先级
iotop的例子
1:只显示正在产生i/o的进程
# iotop -o
2:使用非交互模式将iotop命令输出信息写入日志
#nohup iotop -b -o -n 10 -d 5 -t > /tmp/iotop.log &
3:借助iotop命令找到消耗i/o最高的进程,然后通过进程找到其正在执行的sql语句
# iotop -op
pid prio user disk read disk write swapin io> command
11741 be/4 oracle 4.70 m/s 0.00 b/s 0.00 % 98.60 % ora_s004_scm2
11739 be/4 oracle 66.99 m/s 0.00 b/s 0.00 % 93.30 % ora_s005_scm2
11741 be/4 oracle 21.76 m/s 0.00 b/s 0.00 % 91.78 % ora_s006_scm2
11743 be/4 oracle 4.87 m/s 3.78 m/s 0.00 % 27.74 % ora_s007_scm2
11745 be/4 oracle 62.39 k/s 0.00 b/s 0.00 % 2.88 % ora_s008_scm2
11733 be/4 oracle 39.00 k/s 0.00 b/s 0.00 % 2.08 % ora_s002_scm2
11697 be/4 oracle 0.00 b/s 1879.61 k/s 0.00 % 0.30 % ora_dbw0_scm2
11699 be/4 oracle 0.00 b/s 102.36 k/s 0.00 % 0.20 % ora_lgwr_scm2
在找到消耗i/o最大的进程后,找出oracle进程正在执行的sql语句
sql> @getsql_by_spid.sql
enter value for pid: 11741
old 13: where c.spid = '&pid'))
new 13: where c.spid = '11741'))
sql_text
--------------------------------------------
...............................(实际环境中,这里会输出sql语句)
getsql_by_spid.sql脚本如下所示:
select /*+ ordered */
sql_text
from v$sqltext a
where (a.hash_value, a.address) in (
select decode (sql_hash_value,
0, prev_hash_value,
sql_hash_value
),
decode (sql_hash_value, 0, prev_sql_addr, sql_address)
from v$session b
where b.paddr = (select addr
from v$process c
where c.spid = '&pid'))
order by piece asc
/
这里只简单列了几个例子,因为iotop命令非常简单,了解iotop的参数和快捷方式后,基本上只需根据实际需求去获取进程或信息的i/o信息,剩下就是分析判断了。
上一篇: canvas基本矩形
下一篇: Java加强--2.IO流