ITPub博客

首页 > Linux操作系统 > Linux操作系统 > linux io tools

linux io tools

原创 Linux操作系统 作者:aaqwsh 时间:2013-03-13 10:16:29 0 删除 编辑
linux 下我们可以通过iostat 从整体上来观察io的情况,但是这个不能跟踪到某个process。
iotop是一个类似top的检测process IO 的Python 项目,如果有兴趣,大家可以研究一下。
但是对于那种多线程的应用,如mysql,还需要深入一点的工具,pt-ioprofile就是这样的一个:
[root@oel58 percona-toolkit-2.1.9]# man pt-ioprofile
PT-IOPROFILE(1)       User Contributed Perl Documentation      PT-IOPROFILE(1)
NAME
       pt-ioprofile - Watch process IO and print a table of file and I/O activity.
SYNOPSIS
       Usage: pt-ioprofile [OPTIONS] [FILE]
       pt-ioprofile does two things: 1) get lsof+strace for -s seconds, 2) aggregate the result. If you specify a FILE, then step 1) is not performed.
RISKS
       The following section is included to inform. users about the potential risks, whether known or unknown, of using this tool.  The two main cate-
       gories of risks are those created by the nature of the tool (e.g. read-only tools vs. read-write tools) and those created by bugs.
       pt-ioprofile is a read-only tool, so your data is not at risk. 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.
       At the time of this release, we know of no bugs that could cause serious harm to users.
       The authoritative source for updated information is always the online issue tracking system.  Issues that affect this tool will be marked as
       such.  You can see a list of such issues at the following URL: <http://www.percona.com/bugs/pt-ioprofile>.
       See also "BUGS" for more information on filing bugs and getting help.
 
下面是一些例子,因为这个工具默认是针对mysql的,所以没有指定process id:
[root@oel58 percona-toolkit-2.1.1]# perl pt-ioprofile
Sat Mar  9 17:15:19 CST 2013
Tracing process ID 5805
     total       read       open      close getdents64    _llseek    fcntl64 filename
  0.001335   0.000000   0.000213   0.000153   0.000830   0.000000   0.000139 /var/lib/mysql/
  0.000578   0.000139   0.000088   0.000074   0.000000   0.000277   0.000000 /var/lib/mysql/performance_schema/db.opt
  0.000464   0.000000   0.000075   0.000107   0.000215   0.000000   0.000067 /var/lib/mysql/test/
  0.000318   0.000000   0.000318   0.000000   0.000000   0.000000   0.000000 /var/lib/mysql/test/db.opt
  0.000185   0.000000   0.000185   0.000000   0.000000   0.000000   0.000000 /var/lib/mysql/mysql/db.opt
[root@oel58 percona-toolkit-2.1.1]# perl pt-ioprofile -cell sizes
Sat Mar  9 17:16:06 CST 2013
Tracing process ID 5805
     total       read    pread64   pwrite64      fsync       open      close    _llseek filename
    262144          0          0     262144          0          0          0          0 /var/lib/mysql/ibdata1
      8192          0          0       8192          0          0          0          0 /var/lib/mysql/ib_logfile0
       472        441         31          0          0          0          0          0 /var/lib/mysql/test/aa.frm
 
另外,对于mysql 5.5 及以上,如果你开启了Performance Schema ,这个database里也记录了一些跟mysql有关的io信息
File I/O Summaries:
file_summary_by_event_name: File events summarized per event name
file_summary_by_instance: File events summarized per file instance

不过Performance Schema作为新生事情,记录的信息还是比较少,占用的资源也稍微有点多,bug方面还不清楚,很多比较成熟的公司都还没开始用。
 

转载一个关于iotop工具使用方法:http://www.vmcd.org/2013/03/linux-tools-part-4-monitor-process-io-state/
iotop是一个类似top的检测process IO 的Python 项目。可以在这里下载到源码,可以在这里找到具体的说明。下面做一个演示:
首先下载源码,要求python version>=2.6
 
wget http://guichaz.free.fr/iotop/files/iotop-0.5.tar.gz
wget http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz 
编译python
 
[root@oel58 tmp]# cd /tmp/Python-2.6.6
[root@oel58 Python-2.6.6]#./configure && make && make install
....
checking for %zd printf() format support... yes
checking for socklen_t... yes
 
编译完成之后,编译iotop 源码
 
[root@oel58 tmp]# cd iotop-0.5
[root@oel58 iotop-0.5]# ./setup.py install
running install
running build
————————————————————–
 
[root@oel58 bin]# ./iotop --only
Total DISK READ : 0.00 B/s | Total DISK WRITE : 255.17 M/s
Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 256.64 M/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
16389 be/4 root 0.00 B/s 48.40 M/s 0.00 % 11.61 % dd if /dev/zero of /tmp/temp.txt bs 1M count 10000
16418 be/4 root 0.00 B/s 58.64 M/s 0.00 % 11.55 % dd if /dev/zero of /tmp/temp.txt bs 1M count 10000
16359 be/4 root 0.00 B/s 73.66 M/s 0.00 % 3.48 % dd if /dev/zero of /tmp/temp.txt bs 1M count 10000
6756 be/4 root 0.00 B/s 0.00 B/s 0.00 % 5.97 % [flush-8:0]
16418 be/4 root 0.00 B/s 21.15 M/s 0.00 % 4.52 % dd if /dev/zero of /tmp/temp.txt bs 1M count 10000
16447 be/4 root 0.00 B/s 23.91 M/s 0.00 % 3.02 % dd if /dev/zero of /tmp/temp.txt bs 1M count 10000
109 be/4 root 3.54 K/s 1030.75 K/s 0.00 % 2.36 % [kjournald]
16359 be/4 root 0.00 B/s 22.91 M/s 0.00 % 1.69 % dd if /dev/zero of /tmp/temp.txt bs 1M count 10000 
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.
经测试py version >2.6即可,此外需要说明如果kernel version < 2.6.20 会出现如下问题:
 
Total DISK READ : 0.00 B/s | Total DISK WRITE : 0.00 B/s
Actual DISK READ: 0.00 B/s | Actual DISK WRITE: 16.26 K/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND
CONFIG_TASK_DELAY_ACCT not enabled in kernel, cannot determine SWAPIN and IO % 
strace iotop主要调用的python模块
 
open("/usr/local/lib/python2.6/lib-dynload/_socket.so", O_RDONLY) = 9
open("/usr/local/lib/python2.6/lib-dynload/_ssl.so", O_RDONLY|O_LARGEFILE) = 8
open("/usr/local/lib/python2.6/site-packages/iotop/vmstat.py", O_RDONLY|O_LARGEFILE) = 5
open("/usr/local/lib/python2.6/site-packages/iotop/vmstat.pyc", O_RDONLY|O_LARGEFILE) = 6
open("/usr/local/lib/python2.6/lib-dynload/cStringIO.so", O_RDONLY) = 7
open("/usr/local/lib/python2.6/lib-dynload/cStringIO.so", O_RDONLY|O_LARGEFILE) = 6
..... 
iotop 对python的依赖性过高,以及对于version的要求过于严格,导致了通用性和移植性的下降。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/758322/viewspace-755961/,如需转载,请注明出处,否则将追究法律责任。

上一篇: Mysql Binary Log (3)
下一篇: blog迁移
请登录后发表评论 登录
全部评论

注册时间:2010-11-24

  • 博文量
    132
  • 访问量
    261386