亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Using iotop to check I/O and swap

系統 1793 0

Slicehost Articles: Using iotop to check I/O and swap

Using iotop to check I/O and swap

The iotop utility provides an easy-to-use interface for monitoring swap and disk I/O on a per-process basis.

?


?

Watching the disk

Sometimes you get more disk activity on your system than you would like. Maybe you saw the problem by running iostat, or you've noticed that the system is swapping heavily, or you got an email from support pointing out the problem. In cases like that it's useful to know which process is causing all the hubbub.

Enter iotop. It works like the traditional top command but it tracks device I/O (input/output) on a per-process basis. That can help you zero in quickly on which process is responsible for all the I/O and troubleshoot from there.

Prerequisites

The iotop command requires a kernel version 2.6.20 or higher and python 2.5 or higher.

CentOS and Red Hat Enterprise Linux 5.5 (current at the time of this writing) use an older version of python and so cannot run iotop on a standard installation. They can, however, run dstat , which performs a similar function to iotop.

Check your kernel version by running "uname -r":

      $ uname -r
2.6.35.1-rscloud

    

And check your python version by running "python -V":

      $ python -V
Python 2.5.2

    

Install

You can install iotop through your distribution's package manager (if it's available in the repository) or you can download the source package from the project's website.

From package manager

To install iotop using your package manager pick the appropriate command from the list below (aptitude for Ubuntu/Debian, yum for Fedora, etc.):

      sudo aptitude install iotop
sudo yum install iotop
sudo emerge iotop
sudo pacman -Sy iotop

    

If there is no iotop package in your repository but your system meets the prerequisites, you can install from source instead.

From source

The latest version of iotop is available from the project's web site . Look for a link to the latest source package for iotop and download it with wget:

      wget http://guichaz.free.fr/iotop/files/iotop-0.4.1.tar.bz2

    

Once you've downloaded the tarball, unpack it:

      tar -xjvf iotop-0.4.1.tar.bz2

    

From inside that directory you can either run iotop where it is (by running "./iotop.py") or you can run the installer to put iotop in /usr/bin:

      sudo ./setup.py install

    

Basic usage

At its simplest you can run iotop with no arguments:

      iotop

    

You should see a list of processes along with details about their current I/O use:

The column titles should be pretty self-explanatory, but there are two particular stats to note.

IO

The "IO" column lists total I/O for each process (which includes disk use and swap). Results are sorted by I/O by default when iotop is launched.

SwapIn

The "SwapIn" column lists swap activity for each process.

Runtime commands

Using the right and left arrow keys while viewing iotop will change the column used to sort the results.

If you want the processes sorted in reverse order hit "r" while viewing iotop.

Hitting "o" will filter the list so it will only show processes that are actively doing I/O. Typing "o" again will return to a list of all processes.

Script usage

You can use iotop in "batch mode" to have it print just one set of results instead of launching a constantly-updating interface. Batch mode can be useful when you want a script that logs regular I/O usage to a file.

Sending the "-b" flag to iotop will tell it to run in batch mode. You'll usually want to combine that with some other flags:

The "-o" flag causes iotop to report only process with active I/O.

The "-t" flag will add a timestamp to the results.

The "--iter=#" option will limit the number of samples iotop returns when run.

The "-q" flag will prevent iotop from displaying column headers after its first run. You can prevent headers from being printed at all with "-qq". To prevent both headers and I/O summaries from being printed use "-qqq".

For example, the result of:

      iotop -bto --iter=1

    

Would look like:

      Total DISK READ: 0.00 B/s | Total DISK WRITE: 27.64 K/s
    TIME  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN      IO    COMMAND
17:08:25   177 be/4 root        0.00 B/s    7.90 K/s  0.00 %  0.05 % [kjournald]

    

A sample cron script

You can use cron task scheduling to get iotop to run every minute and log any I/O activity it detects. Open this file for editing (with sudo):

      /etc/cron.d/iotop

    

And put the following into that file:

      #  Run iotop and log any detected activity.

* * * * * root iotop -botqqq --iter=3 >> /var/log/iotop

    

Save the file. That cron.d entry will cause iotop to run every minute, logging any I/O activity it finds to "/var/log/iotop". It takes three samples when it runs (five seconds apart), doesn't log headers or summary information, and only logs processes with measured I/O activity.

After a minute take a look in /var/log. If the script ran as expected there should now be an "iostat" log there (though it may be an empty file if it didn't find any I/O to log).

Tweak the command to your liking. If you want a different number of samples per minute change the "--iter" value. If you want I/O summaries printed when the script runs change "qqq" to "qq".

Rotate the created log

If you plan to leave the iotop logger running (and aren't just going to run it for a day or so to check on a burst of disk activity) you'll want to rotate its log occasionally to keep it from getting too big.

To that end, create a file for editing at "/etc/logrotate.d/iotop" (again using sudo).

Put the following into the file:

      /var/log/iotop {
  rotate 5
  weekly
  compress
  missingok
  notifempty
}

    

For more details on what that logrotate config will do you can look through our articles on logrotate . For example, you might change the frequency of rotations from "weekly" to "daily" if you find you're logging a lot of disk I/O. You could then increase the number of archived logs it keeps accordingly.

Similar commands

Another program that can be used to check I/O is dstat . While its presentation isn't necessarily as attractive as iotop's, it allows for more flexibility in what can be written to a log when used in a script. It also runs on older versions of python than iotop so it will run on more distributions.

The "sysstat" package includes several commands useful for gathering system usage statistics, and newer versions of the package include a program named "pidstat". When run with the "-d" option pidstat will display disk I/O information on a per-process basis.

Summary

As "top" is to processor and memory use, so "iotop" is to disk I/O and swap use. The ability to see I/O on a per-process basis is relatively new to Linux (thus the requirement for a newer kernel to run iotop), but it was a very welcome addition. Iotop can be very useful when trying to track down which process is using swap memory or is causing an excessive amount of disk activity.

  • -- Jered

Using iotop to check I/O and swap


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久亚洲精品tv | 日日天天干 | 四虎在线免费观看视频 | 九九热思思 | 99香蕉国产 | 我不卡老子影院午夜伦我不卡四虎 | 青青国产成人久久激情911 | 国产一区二区三区在线观看视频 | 久久久久久久九九九九 | 九九精品在线播放 | 老司机午夜网站 | 青草社区在线 | 天天操天天玩 | 日本一级特黄视频 | 国产精品福利社 | 国产视频二区在线观看 | 国产精品不卡视频 | 欧美日韩一区二区三 | 在线观看深夜观看网站免费 | 一区二区三区四区在线视频 | 亚洲精品乱码久久久久 | 亚洲国产另类久久久精品小说 | 亚洲国产男人本色在线观看的a站 | 成人短视频在线在线观看 | 中文字幕日本不卡一二三区 | 亚洲欧美中文字幕 | 福利视频网 | 欧美综合视频在线 | 国产精品日韩欧美在线第3页 | 精品综合久久久久久97超人该 | 久久综合干 | 国产精品无码久久综合网 | 91久久综合九色综合欧美亚洲 | 欧美一级在线全免费 | 日本国产一区二区三区 | 日韩欧美理论片 | 国产成人精品高清在线观看99 | 久久免费资源福利资源站 | 日本欧美一区二区三区乱码 | 奇米7777第四色| 一区二区三区网站在线免费线观看 |