本文转载自微信公众号「DBA闲思杂想录」,作者潇湘隐者。转载本文请联系DBA闲思杂想录公众号。
iotop的简介:
iotop是一款开源、免费的用来监控磁盘I/O使用状况的类似top命令的工具,iotop可以监控进程的I/O信息。它是Python语言编写的,与iostat工具比较,iostat是系统级别的IO监控,而iotop是进程级别IO监控。目前最新的版本为iotop 0.6。其官方网址http://guichaz.free.fr/iotop/[1]
iotop的安装:
注意,iotop的安装有前提条件(如果操作系统不满足这些条件,iotop无法正确安装):
1:内核版本为2.6.20或更高版本
2:Python 2.7或更高的版本
官方文档的详细介绍如下:
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)
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信息,剩下就是分析判断了。
参考资料
[1]iotop: http://guichaz.free.fr/iotop/
git clone支持https和git(即ssh)两种方式下载源码: 当使用git方式下载时,如...
需要注意的是,调用的封装的数据库,和jQuery的保存地址 一、注册 (1)写文本框...
详解Spring Controller autowired Request变量 spring的DI大家比较熟悉了,对于...
大家好我是爱景甜的网工我是一个思科出身专注于华为的网工 好了话不多说进入正题...
多年以后,面对台下五彩斑斓的Jetbrain和Vscode用户,这位曾经的资深的vim追随者...
1 概述 在接下来的时间里,将会入手ASP.NET MVC这一专题,尽量用最快的时间,最...
在新的MySQL 8.0.23中,引入了新的有趣功能:不可见列。 这是第一篇关于这个新功...
最近在学习jQuery时接触到了show()、hide()、toggle()函数,于是利用这几个函数...
一个常见的场景,获取:标签背景图片链接: 如字符串:var bgImg = "url (\" htt...
在Asp.net Core之前所有的Action返回值都是ActionResult,Json(),File()等方法返...