Linux iotop工具簡介

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

  1. SWAPIN and IO are the percentages of time the thread spent respectively
  2. 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

clip_image001

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信息,剩下就是分析判斷了。

作者:瀟湘隱者
出處:http://www.cnblogs.com/kerrycode/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章