Monitoring disk activity with iotop

Feb 10, 2020

The program watches I/O usage information output by the Linux kernel (/proc/pid/io) and displays a table of current I/O usage by processes on the system. Red Hat backported I/O accounting in RHEL 5.4(kernel 2.6.18-164.el5) so the above statement does not apply on Red Hat Enterprise.

Even though I/O accounting was enabled in RHEL 5.4 the kernel is not configured correctly so iotop really works starting with RHEL 5.6 (kernel 2.6.18-238.el5). If /proc/self/io file exist then the I/O accounting is built-in the kernel. Since 2012 iotop is part of the Red Hat Enterprise Linux.

[root@c5vm01 ~]# cat /proc/self/io
rchar: 1900
wchar: 0
syscr: 7
syscw: 0
read_bytes: 0
write_bytes: 0
cancelled_write_bytes: 0

Field Descriptions

  • rchar: The number of bytes which this task has caused to be read from storage.
  • wchar: The number of bytes which this task has caused, or shall cause to be written to disk.
  • syscr: Attempt to count the number of read I/O operations (system calls such as read and pread).
  • syscr: Attempt to count the number of write I/O operations (system calls such as write and pwrite).
  • read_bytes: Attempt to count the number of bytes which this process really did cause to be fetched from the storage layer.
  • write_bytes: Attempt to count the number of bytes which this process caused to be sent to the storage layer.
  • cancelled_write_bytes: Represents the number of bytes which this process caused to not happen, by truncating pagecache.

Installation

yum install iotop python python-ctypes

Commands

  • Show processes or threads actually doing I/O: iotop -o
  • Turn on non-interactive mode (useful for logging I/O usage over time): iotop -b
  • Set the number of iterations before quitting: iotop -n
  • Add a timestamp on each line (implies –batch): iotop -t
  • Only show processes (by default iotop shows all threads): iotop -P
  • Monitor one or more processes: iotop -p 2446
  • Monitor a specific user: iotop -u postfix
  • Set the delay between iterations in seconds (1 second by default): iotop -d 5
  • Suppress some lines of header (implies - -batch): iotop -q

Recipes

Use batch mode, 60 iterations (1 minute) with timestamp, column names are never printed, save all in a file.

iotop -o -b -n 60 -t -qqq > iotop.out

Monitor a specific PID for 24 hours:

iotop -o -p 1155 -b -n 86400 -t -qqq > iotop.out &

Keyboard shortcuts

Use the left and right arrows to change the sorting (the sort field will have a “>”)

Key Description
r reverse the sorting order (“>” change to “<”), default option is I/O.
o toggle the - -only option
p toggle the - -processes option
a toggle the - -accumulated option (shows accumulated I/O since iotop started)
i change the priority of a thread or a process’ thread(s)
q quit
monitoringlinuxlinuxiotop

How to enable console access on KVM guest

comments powered by Disqus