一,iotop的作用:

iotop是监视磁盘I/O使用状况的top类工具,

可以针对进程和线程统计io的使用情况

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

二,安装iotop:

[root@database1 ~]# yum install iotop

三,查看帮助

[root@database1 ~]# iotop --help
Usage: /usr/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,
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)

四,查看版本:

[root@yjweb ~]# iotop --version
iotop 0.6

五,iotop常用参数

1,只显示有io操作的进程

[root@database1 ~]# iotop -o

说明:-o:只显示有io操作的进程

2,显示针对进程的统计

[root@database1 ~]# iotop -o -P

说明:默认是针对线程的统计,表头是TID,

如果针对进程统计,表头是PID

3,显示启动后累积的数据:

[root@database1 ~]# iotop -oa

说明:

只看某一个时间点的数据有时找不到消耗I/O最高的进程,

这时查看累积的数据显示更有效

4,监控指定pid的io使用:

[root@database1 ~]# iotop -p 26474

说明:

-p  指定进程id

5,指定刷新的间隔时间

[root@database1 ~]# iotop -o -d 2

说明:默认是1秒,

-d: 指定间隔的秒数,例子中是2秒刷新一次

6,查看指定用户的io使用

[root@database1 ~]# iotop -o -a -u mysql

说明:

-u: 指定用户,当查询mysql的io时很方便

6,非交互模式,批量处理 用来记录日志

[root@database1 ~]# iotop -boqtn3

说明:

-b: batch处理,不支持交互,常用来输出日志
-q: quiet 只输出一次表头
-n:用来指定输出循环次数:例子中我们用了3次
-t: 增加一列时间
-t和-q两个参数只适用-b

如何输出到文件:

[root@database1 ~]# iotop -boqn3 > /root/iotop0319.txt 2>&1

六,交互命令:

o:   打开/关闭 只显示有io的进程/线程

p: 切换按进程和按线程的统计

a: 切换是否采用累积统计模式

q:退出

七,显示内容各表头的说明:

tid:线程id,按p可转换进程pid

PRIO:优先级

DISK READ:磁盘读取速率

DISK WRITE:磁盘写入速率

SWAPIN:swap交换百分比

IO>:IO等待所占用百分比

COMMAND:线程/进程详细信息

八,得到pid/tid后,如何找出它正在打开的文件?

用lsof

[root@database1 ~]# lsof -p 26474 | more
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 26474 mysql cwd DIR 252,17 4096 18268161 /data/mysql/data
mysqld 26474 mysql rtd DIR 252,1 4096 2 /
mysqld 26474 mysql txt REG 252,1 11172576 1055031 /usr/sbin/mysqld
。。。

说明:lsof -p参数:列出指定进程id下打开的文件

九,找到了mysql大量消耗io的线程id,如何找出对应的sql?

说明:mysql在5.7版本给performance_schema.threads表增加了thread_os_id, 即系统线程字段
低于5.7版本的mysql没办法根据操作系统的线程id找到sql

看例子:如果线程id是:19440

执行下面的sql即可:

SELECT a.name,
a.thread_id,
a.thread_os_id,
a.processlist_id,
a.type,
b.user,
b.host,
b.db,
b.command,
b.time,
b.state,
b.info
FROM performance_schema.threads a
LEFT JOIN information_schema.processlist b
ON a.processlist_id = b.id
where a.type = 'FOREGROUND'
and a.thread_os_id =19440

十,查看当前的centos版本

[root@yjweb ~]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)

centos8平台使用iotop监控磁盘io的更多相关文章

  1. centos8平台使用iostat监控磁盘io

    一,iostat所属的包: [root@centos8 ~]# whereis iostat iostat: /usr/bin/iostat /usr/share/man/man1/iostat.1. ...

  2. Cacti:添加监控磁盘IO

    来自:http://blog.sina.com.cn/s/blog_61c07ac50101gkzp.html 1.检查net-snmp是否支持IO监控 snmpwalk -v 1 -c public ...

  3. Cacti添加IO模板并监控磁盘IO

    1.下载Cacti_Net-SNMP_DevIO_v3.1.zip 下载Cacti_Net-SNMP_DevIO_v3.1.zip,解压并上传net-snmp_devio.xml到/resource/ ...

  4. 第七章——DMVs和DMFs(4)——用DMV和DMF监控磁盘IO

    原文:第七章--DMVs和DMFs(4)--用DMV和DMF监控磁盘IO 前言: 本文为本系列最后一篇,作为DBA,你必须经常关注磁盘的I/O问题,一旦出现问题,要尽快分析出是什么问题.SQLServ ...

  5. zabbix应用之Low-level discovery监控磁盘IO

    参考文章: http://qicheng0211.blog.51cto.com/3958621/1599776/ zabbix自带的"Template OS Linux"模板支持监 ...

  6. Zabbix 监控磁盘IO

    Zabbix 监控磁盘IO 1.数据获取脚本 #!/bin/bash # resource: http://www.muck.net/19/getting-hard-disk-performance- ...

  7. Zabbix自动发现并监控磁盘IO、报警

    本文转载自: https://www.93bok.com 引言 Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个,由于一台服务器中磁盘众多,如果只有一两台可以手动添加,但服务 ...

  8. Zabbix 自动发现并监控磁盘IO、报警 引言

    引言 Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个,由于一台服务器中磁盘众多,如果只有一两台可以手动添加,但服务集群达到几十那就非常麻烦,因此需要利用自动发现这个功能,自 ...

  9. centos8平台使用pidstat监控cpu/内存/io

    一,安装pidstat: 1,安装 [root@localhost yum.repos.d]# yum install sysstat 2,查看版本: [root@localhost ~]# pids ...

随机推荐

  1. 为什么互联网巨头们纷纷使用Git而放弃SVN?(内含Git核心命令与原理总结)

    写在前面 最近发现很多小伙伴对于工作中的一些基本工具的使用还不是很了解,比如:Git这个分布式的代码管理仓库,很多小伙伴就不是很了解,或者说不是很熟悉.甚至有些小伙伴都没听说过Git,就只会用个SVN ...

  2. mysqli报错注入常见函数

    以下均摘自<代码审计:企业级Web代码安全架构>一书 1.floor() select * from test where id=1 and (select 1 from (select ...

  3. js监听事件的绑定与移除

    监听事件的绑定与移除主要是addEventListener和removeEventListener的运用. addEventListener语法 element.addEventListener(ty ...

  4. git个人常用命令

    git https://www.cnblogs.com/chenwolong/p/GIT.html 添加当前目录的所有文件到暂存区 $ git add . 提交暂存区到仓库区 $ git commit ...

  5. CTF-BugKu-WEB-1-20

    2020.09.17 全面复习web,给自己定个目标,后天之前结束BugKu-Web,开始逆向. 经验教训 php弱等于用于绕过==,弱等于之前会把等号两边转化为同一类型变量: 全局变量全局变量全局变 ...

  6. netty之handler write

    转载自:https://blog.csdn.net/FishSeeker/article/details/78447684 实验过,例如channle的handler里有很多个outhandler,在 ...

  7. SpringBoot框架:使用mybatis连接mysql数据库完成数据访问(二)

    一.导入依赖包 1.在创建项目时勾选: 勾选SQL中的JDBC API.MyBatis Framework.MySQL Driver,创建项目后就会自动配置和引入这些包. 2.在pom.xml文件中添 ...

  8. win10 系统出现“你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问。”

    公司无法访问共享 \192.168.7.101.win+R 输入gpedit.msc2.计算机配置-管理模板–网络-lanman 工作站-找到"启用不安全的来宾登录"选择 已启用. ...

  9. if-else​ 条件语句

    1.  条件语句模型 Go里的流程控制方法还是挺丰富,整理了下有如下这么多种: if - else 条件语句 switch - case 选择语句 for - range 循环语句 goto 无条件跳 ...

  10. SpringBoot一统江湖

    一 SpringBoot简介 SpringBoot是Spring框架的一个新子项目 用于创建Spring4.0项目 它的开发始于2013年 2014年4月发布1.0.0版本 它可以自动配置Spring ...