How can I monitor disk I/O in a particular directory?

I’ve got a few processes with a known name that all write to files in a single directory. I’d like to log the number of disk block reads and writes over a period (not just file access) to test whether a parameter change reduces the amount of I/O significantly. I’m currently using iostat -d -p, but that is limited to the whole partition.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I realize this is going to sound both simplistic and absurd, but if you have
control over the apps in question (maybe in a test environment) you could
mount ONLY that directory on a partition of its own, then iostat, etc. would
tell you only about it, and nothing else on that spot.

If there are physical drives involved you could fake it up with a loopback
mount à la

dd if=/dev/zero of=/bigdisk/LOOPFILE bs=1024m count=1024m # 1gb loopback file
mke2fs -j /bigdisk/LOOPFILE
mkdir /tmpcopy
mount -o loop /tmpcopy /bigdisk/LOOPFILE
cp -r -p $SPECIALDIR2MONITOR /tmpcopy
umount /tmpcopy
mount -o loop $SPECIALDIR2MONITOR  /bigdisk/LOOPFILE,

That would not completely remove all competing disk I/O, but
I’m pretty sure iostat‘s output would be more specific to your need.

Method 2

You can use inotifywait -m DIRNAME from the inotify-tools.

Method 3

I don’t think there’s a direct way. One way to get the data you want would be to access the directory tree through a virtual filesystem that logs accesses. Loggedfs is one such filesystem, though I don’t know if it can show all the data you’re interested in. (If not it would probably be a modest coding effort to that data.)

mkdir /tmp/replica
loggedfs /path/to/directory /tmp/replica
mycommand --root=/tmp/replica
fusermount -u /tmp/replica


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x