Linux系統IO分析工具之iotop參數詳解(查看IO佔用)

這篇文章主要介紹了Linux系統IO分析工具之iotop參數詳解(查看IO佔用),本文着重註解了iotop工具的參數,以及可操做命令,須要的朋友能夠參考下php

簡介:html

iotop – simple top-like I/O monitor
iotop是一個用來監視磁盤I/O使用情況的 top 類工具,可監測到哪個程序使用的磁盤IO的信息(requires 2.6.20 or later)java

安裝:
node

複製代碼
代碼以下:

yum -y install iotop


用法:
python

複製代碼
代碼以下:

iotop [OPTIONS]


選項:
mysql

複製代碼
代碼以下:

--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改變排序(方向鍵改變排序列),還可以使用如下命令:

linux

複製代碼
代碼以下:

r:反向排序,
o:切換至選項--only,
p:切換至--processes選項,
a:切換至--accumulated選項
q:退出 
i:改變線程的優先級


例子:
ios

複製代碼
代碼以下:

$ iotop 
$ iotop –b –n 3 –d 5

 

iotop命令是專門顯示硬盤IO的命令,界面風格相似top命令。這個命令只有在kernelv2.6.20及之後的版本中才有。
 
一、直接yum安裝,rh6的光盤裏有包。
yum install iotop
 
二、命令參數介紹
 
-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.
 
三、使用截圖
 
 
 
[root@localhost tmp]# iotop -o 
 
 
iotop命令的鍵盤快捷鍵:
一、左右箭頭改變排序方式,默認是按IO排序
二、r鍵是反向排序
三、o鍵是隻顯示有IO輸出的進程
四、一樣q是退出

介紹

Linux下的IO統計工具如iostat, nmon等大多數是隻能統計到per設備的讀寫狀況, 若是你想知道每一個進程是如何使用IO的就比較麻煩.git

iotop 是一個用來監視磁盤 I/O 使用情況的 top 類工具。iotop 具備與 top 類似的 UI,其中包括 PID、用戶、I/O、進程等相關信息。sql

 

實例

直接運行就好

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狀況

linux系統中,管理員可使用top來監控進程的cpu和內存的使用狀況,可是對於磁盤的i/o則只能使用iostat籠統地進行監視,不能對應進程這對於管理員來講很不方便。好比你的服務器負載很低,內存使用也不多,可是硬盤狂轉,但你就是沒法準確肯定是哪一個進程在搞鬼。最近在google這個問題時,偶然發現了io監控這缺失的一環的工具。這就是iotop ,當前的最新版本是0.2.1,官方網站提供了源碼和rpm包下載。
 
官方網站: http://guichaz.free.fr/iotop/

iotop 須要python版本>=2.5,且系統內核>=2.6.20
 
iotop能夠顯示磁盤讀寫的速率,交換分區進出狀況和總體磁盤性能情況,這些都是按照每一個進程使用狀況來統計。進程列表按照I/O使用狀態排序並每秒刷新一次。

IO負載高的來源定位

 

前言:

在通常運維工做中常常會遇到這麼一個場景,服務器的IO負載很高(iostat中的util),可是沒法快速的定位到IO負載的來源進程和來源文件致使沒法進行相應的策略來解決問題。

這個現象在MySQL上更爲常見,在5.6(performance_schema提供io instrument)以前,咱們一般只能猜到是MySQL致使的高IO,可是無法定位具體是哪一個文件帶來的負載。

例如是ibdata的刷寫?仍是冷門ibd的隨機讀取?

本文就將介紹一個比較簡單的定位IO高負載的流程。

 

工具準備:

iotop: http://guichaz.free.fr/iotop/

pt-ioprofile:http://www.percona.com/downloads/percona-toolkit/2.2.1/

 


 

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安裝。

yum install iotop 

在Ubuntu裏安裝命令是: sudo apt-get install iotop 
安裝好以後在終端輸入:iotop就能夠了 
或者:

git clone git://repo.or.cz/iotop.git





iotop使用說明:

能夠用左右箭頭操做,按 r 是相反方向,按 o 是動態切換

用法 iotop -參數

–version 查看版本信息的 -h, –help 查看幫助信息的 -o, –only 只顯示在劃硬盤的程序-b, –batch 批量處理 用來記錄日誌的 -n NUM  設定循環幾回 -d SEC, –delay=SEC  設定顯示時間間隔

相關文章
相關標籤/搜索