Monitoring Ubuntu OverlayFS: Commands, Tools, and Scripts
OverlayFS is a union file system commonly used in Ubuntu to layer multiple directories (lowerdir) into a single unified view (upperdir + merged). Monitoring its performance, usage, and changes is critical for maintaining system stability—especially in containerized environments like Docker. Below are practical methods to monitor OverlayFS on Ubuntu.
These commands help verify OverlayFS status and resource usage:
df -h: Displays disk space usage for all mounted file systems, including OverlayFS. Look for the overlay entry to check total/used space.mount | grep overlay: Confirms OverlayFS is properly mounted. The output shows the lowerdir (base layers), upperdir (writable layer), and workdir (temporary files) paths.iostat -x 1: Provides real-time CPU and disk I/O statistics (e.g., read/write throughput, latency) for OverlayFS-mounted devices. Run with sudo for detailed metrics.iotop -o: Tracks process-level disk I/O, helping identify which applications are actively reading/writing to OverlayFS. Use -o to filter only active processes.To track modifications (creates/deletes/modifies) in an OverlayFS directory:
inotify-tools:sudo apt-get install inotify-tools
/path/to/overlay/mountpoint with your actual OverlayFS path (from mount | grep overlay). This script logs all file changes to the console:#!/bin/bash
WATCH_DIR="/path/to/overlay/mountpoint"
inotifywait -m -r -e create -e delete -e modify -e moved_to -e moved_from --format '%w%f %e' "$WATCH_DIR"
Make it executable (chmod +x monitor_overlayfs.sh) and run it to see live events.For long-term metrics collection and visualization (ideal for production):
wget https://github.com/prometheus/prometheus/releases/download/v2.40.5/prometheus-2.40.5.linux-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
cd prometheus-*
./prometheus --config.file=prometheus.yml
sudo apt-get install -y grafana
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
cAdvisor (for container-level metrics) or node_exporter (for host-level metrics) to collect OverlayFS data (e.g., disk usage, I/O rates). Add these as targets in Prometheus’ prometheus.yml.Identify processes consuming excessive OverlayFS resources:
top/htop:top (or htop for a more user-friendly interface) and sort by %MEM or %CPU to find processes using significant OverlayFS resources.lsof | grep overlay:If using OverlayFS with Docker Swarm (for distributed containers), monitor network traffic between nodes:
nethogs:sudo apt install nethogs
sudo nethogs
docker network ls # List all networks (check for 'overlay' type)
docker service ls # Monitor running services in the overlay network
While not strictly monitoring, these steps improve OverlayFS performance and reduce bottlenecks:
RUN apt-get update && apt-get install -y ... into a single command) to minimize overhead.noatime Mount Option: Avoid updating access timestamps (reduces write operations). Modify your mount command:sudo mount -t overlay overlay -o lowerdir=layer1:layer2,upperdir=merged,workdir=/workdir,noatime /mnt/overlayfs
upperdir and workdir to speed up reads/writes.gzip) to reduce I/O load.By combining these tools and techniques, you can effectively monitor Ubuntu OverlayFS for performance issues, troubleshoot problems, and optimize resource usage. Adjust monitoring frequency and thresholds based on your workload demands.