Monitoring Disk Usage
Use tools like `df`, `du`, and `iostat` to monitor disk space, inode usage, and I/O performance of your server storage.
Monitoring Disk Usage is a free Linux Server Deployment & SSH Mastery lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Server Deployment & SSH Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Monitor Disk Usage?
Keeping an eye on your server's disk usage is crucial. Imagine a website suddenly going down because its logs filled up the entire disk! Or a database slowing to a crawl due to heavy disk activity.
Monitoring helps you:
- Prevent outages: Catch full disks before they cause problems.
- Optimize performance: Identify disks with high I/O that might be bottlenecks.
- Plan capacity: Understand growth trends to add storage proactively.
Meet `df`: Disk Free
The df command stands for 'disk free'. It's your go-to tool for checking the overall disk space usage of mounted file systems on your server.
It provides a summary of total space, used space, available space, and percentage used for each mounted partition.
`df` in Action: Space Check
Let's see df in action. The -h flag makes the output human-readable, showing sizes in KB, MB, or GB.
Try running this command to see your server's disk space at a glance:
df -hUnderstanding `df` Output
The output of df -h typically has these columns:
- Filesystem: The name of the disk partition or device.
- Size: Total size of the filesystem.
- Used: Amount of space currently in use.
- Avail: Amount of space still available.
- Use%: Percentage of disk space used.
- Mounted on: The directory where the filesystem is mounted.
Pay close attention to the Use% column to spot nearly full disks!
Meet `du`: Disk Usage
While df shows overall filesystem usage, du (disk usage) calculates the space used by specific files or directories.
This is extremely helpful for finding out which directories are consuming the most space, allowing you to pinpoint the source of high disk usage.
`du` in Action: Directory Size
To find the size of a directory, you can use du with the -s (summarize) and -h (human-readable) flags, followed by the path to the directory.
Let's check the size of the /var/log directory, which often contains large log files:
du -sh /var/log`df` vs. `du`: Key Differences
It's important to know when to use which:
df: Reports space usage for entire filesystems. It reads data from the filesystem's metadata.du: Reports space usage for files and directories. It scans through directory contents to calculate size.
Sometimes, df and du might show different numbers due to deleted files still held open by processes. A reboot or restarting the process usually syncs them up.
Meet `iostat`: I/O Performance
iostat is part of the sysstat package and provides detailed input/output (I/O) statistics for your storage devices.
This tool helps you monitor disk activity, which is crucial for identifying performance bottlenecks. High I/O wait times can significantly slow down your server.
`iostat` in Action: Disk Activity
To get a snapshot of your disk's I/O performance, you can use iostat. The -x flag provides extended statistics, and adding a number (e.g., 2) will make it update every 2 seconds.
This command might require sysstat to be installed (e.g., sudo apt install sysstat on Debian/Ubuntu).
iostat -x 2Interpreting `iostat` Output
When using iostat -x, look for these key metrics:
- %util: Percentage of CPU time during which I/O requests were issued to the device. High values (near 100%) indicate a busy disk.
- r/s, w/s: Number of read/write requests per second.
- rkB/s, wkB/s: Number of kilobytes read/written per second.
- await: The average time (in milliseconds) for I/O requests issued to the device to be served. High values suggest a slow disk.
These metrics help you gauge disk health and performance.
Quick Check: Disk Monitoring
You've learned about three essential tools for monitoring disk usage and performance. Now, let's test your understanding!
Recap: Your Monitoring Toolkit
Great job! You've mastered the basics of monitoring your server's disk usage and I/O performance.
You learned about:
df: For checking overall free disk space on filesystems.du: For identifying disk usage by specific files and directories.iostat: For monitoring disk I/O performance and identifying bottlenecks.
Regularly using these tools will help you keep your server running smoothly and prevent unexpected issues.
Frequently asked questions
Is the “Monitoring Disk Usage” lesson free?
Yes — the full text of “Monitoring Disk Usage” is free to read here on the web, and the Linux Server Deployment & SSH Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Server Deployment & SSH Mastery course, upgrade to CoddyKit PRO.
What will I learn in “Monitoring Disk Usage”?
Use tools like `df`, `du`, and `iostat` to monitor disk space, inode usage, and I/O performance of your server storage. You practise Linux Server Deployment & SSH Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Linux Server Deployment & SSH Mastery?
No prior experience is required. Linux Server Deployment & SSH Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Monitoring Disk Usage” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Linux Server Deployment & SSH Mastery lesson?
Yes. Every Linux Server Deployment & SSH Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Disk Partitioning and Formatting
- Mounting File Systems
- Monitoring Disk Usage
- Logical Volume Management (LVM)