Ubuntu でファイルシステムへの IO (Read/Write) を監視するには inotify
を使います。 今回は Ubuntu 20.04LTS で検証を行いました。
inotify のインストール
inotify をインストールするには以下を実行します。
apt -y install inotify-tools
実行例
例えば /etc
配下の IO を監視したい場合は以下のように実行します。
inotifywait -e create,delete,modify,move -mr /etc/
実行例は以下の通りです。
# inotifywait -e create,delete,modify,move -mr /etc/
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
/etc/opt/ CREATE test
/etc/opt/ DELETE test
・
・
・
監視対象ファイル数の増加
inotify で監視出来るファイル数は /proc/sys/fs/inotify/max_user_watches
で確認することが出来ます。 デフォルトでは 8,192 になっていました。
# cat /proc/sys/fs/inotify/max_user_watches
8192
これを変更するには /etc/sysctl.conf
へ以下を追加し、sysctl -p
を実行して変更を反映します。 但し、無闇に値を増加するとその分、消費メモリが多くなる為、注意が必要です。
fs.inotify.max_user_watches=16384
コメント