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

Using iotop to check I/O and swap

系統 2081 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條評論
主站蜘蛛池模板: 一区二区三区鲁丝不卡麻豆 | 亚洲美女精品视频 | 99视频在线观看免费 | 亚洲综合视频一区 | 亚洲 欧美 成人日韩 | 神马手机不卡影院 | 国产欧美日韩精品第三区 | 天天尻逼 | 亚洲女人天堂a在线播放 | 国产精品毛片久久久久久久 | 欧美成人性做爰 | youjizz欧美粗又大中国 | 99这里只有| 欧美精品成人a多人在线观看 | 欧美日韩精品一区二区三区 | 天天做天天爱天天操 | 久久精品免视看国产明星 | 伊人色综 | 色婷婷精品免费视频 | 九九99香蕉在线视频免费 | 视频一区二区在线 | 久久伊人中文字幕 | 亚洲欧美一区二区三区九九九 | 久久久久久久亚洲精品一区 | 国产午夜精品一二区理论影院 | 久久久久久青草大香综合精品 | 亚洲国产精品一区二区第四页 | 国产欧美精品区一区二区三区 | a毛片免费播放全部完整 | 国产成人一区二区三区影院免费 | 亚洲国产精品热久久2022 | 久久精品综合国产二区 | 久草在线资源 | 香蕉久人久人青草青草 | 中文字幕99| 久久综合久久自在自线精品自 | 亚洲日比视频 | 免费永久国产在线视频 | 私人影院aaaaa毛片 | 亚洲成人在线免费 | 成人网中文字幕色 |