Tooltip - Inotify-tools

A nifty tool which might be handy when getting to know a system or tracking down I/O usage is inotify-tools . It’s a lightweight interface to the kernel’s inotify function. It gives a quick overview over which files are accessed and how in any given directory and it’s subdirectories (if asked to). It can quickly give an overview of efficiency of caching, frequency of commits, and all sorts of useful information for a whole range of applications.

Here’s some example output from the inotifywatch utility during a mysqlslap run:

1
2
3
4
5
6
7
8
9
# inotifywatch  /var/lib/mysql/mysqlslap/*
Establishing watches...
Finished establishing watches, now collecting statistics.
total  access  modify  close_write  close_nowrite  open  delete_self  filename
728    450     274     1            0              1     1            /var/lib/mysql/mysqlslap/t1.MYD
241    0       238     1            0              0     1            /var/lib/mysql/mysqlslap/t1.MYI
5      1       0       0            1              1     1            /var/lib/mysql/mysqlslap/t1.frm
2      0       0       0            0              0     1            /var/lib/mysql/mysqlslap/db.opt
.

Granted - as far as MySQL is concerned - most information is accessible through SHOW GLOBAL STATUS and/or SHOW ENGINE INNODB STATUS commands. But if you for instance have an erratic fear of the key_read_requests variable, you could always look at how often your MYI files are accessed. You catch my drift..

If you’re only interested in certain file operations, you can apply filters. If you for instance only have interest in file writes, your run would look like this:

1
2
3
4
5
6
7
8
9
# inotifywatch -e modify -e delete_self /var/lib/mysql/mysqlslap/*
Establishing watches...
Finished establishing watches, now collecting statistics.
total  modify  delete_self  filename
49     47      1            /var/lib/mysql/mysqlslap/t1.MYI
44     42      1            /var/lib/mysql/mysqlslap/t1.MYD
2      0       1            /var/lib/mysql/mysqlslap/db.opt
2      0       1            /var/lib/mysql/mysqlslap/t1.frm
.

You can monitor pretty much any file operation, so this tool can be used in a whole range of scenarios. Ever wondered just how many temp files your application creates or? Are you sure it doesn’t open and close the file handle for each operation? Do you want to know which file on your website is the most popular download at the moment but can’t wait until the webstats crontab has ran? I could go on…

inotify-tools come with another utility inotifywait. This tool looks for activity on a specified file or directory and instantly tells you which operation was performed. Nothing amazing, but I can see a few areas of use for that as well, though most of them have tools for that purpose already.

Aug 26th, 2008