This article covers essential disk I/O and network activity monitoring, detailing key metrics and tools like iostat, iotop, df, ss, iftop, and nload to keep your system responsive and connected. Let's explore how to monitor these vital resources!
Keeping an Eye on Your Disks: I/O Performance & Capacity 💿
Slow disk performance can cripple an otherwise powerful system. Monitoring disk input/output (I/O) and capacity helps you identify bottlenecks and prevent storage shortages.
Key Disk I/O Metrics
- Read/Write Operations (IOPS): The number of read and write operations per second. High IOPS usually mean a busy disk.
- Throughput (MB/s): The actual data transfer rate to and from the disk, typically measured in megabytes per second. This shows how much data is being moved.
- Latency (Service Time): The time it takes for a single I/O operation to complete. High latency means slow disk response and can lead to sluggish application performance.
- Queue Length: The number of I/O requests waiting to be processed by the disk. A consistently long queue indicates the disk can't keep up with demand.
- Utilization (
%util): The percentage of time the disk was busy processing I/O requests. If it's consistently near 100%, the disk is a bottleneck.
Tools for Disk I/O Insights
iostat(Input/Output Statistics): Provides detailed reports on CPU utilization and I/O statistics for block devices (disks).iostat: Shows a summary since boot.iostat -xz 1 5: Shows extended statistics (-x), skips devices with no activity (-z), every 1 second, 5 times. This is very useful.
Look for columns like# Example: Display extended I/O stats every 2 seconds, 3 times for all devices iostat -xz 2 3r/s(reads per second),w/s(writes per second),rkB/s(read kilobytes per second),wkB/s(write kilobytes per second),await(average time for I/O requests to be served, including queue time),svctm(average service time for I/O requests, deprecated in newer versions, look atawait), and%util.
iotop(I/O Top): An interactive,top-like utility specifically for monitoring disk I/O usage by individual processes. This is great for finding out which process is hammering your disks. (You might need to install it:sudo apt install iotoporsudo yum install iotop).- Just run
sudo iotop. - Use
-oor--onlyto show only processes that are actually doing I/O.# Example: Show only processes currently doing I/O sudo iotop -o
- Just run
Monitoring Filesystem Capacity & Inode Usage
Beyond performance, you need to track how much space is left.
df(Disk Filesystem): We've met this before! It reports filesystem disk space usage.df -h: Shows usage in human-readable format (e.g., 1K, 23M, 2G).df -h
- Inode Usage (
df -i): Every file and directory on your filesystem uses an inode. It's possible to run out of inodes even if you still have disk space, especially if you have millions of tiny files.df -i: Shows inode usage information.df -ih: Combines human-readable sizes with inode information (though size is less relevant for inodes themselves).
Look at the# Example: Display inode usage df -iIUse%column. If it gets close to 100%, you'll have trouble creating new files.
Tracking Network Traffic: Ensuring Smooth Connectivity 🌐
Network performance is vital for most applications today. Monitoring network activity helps you understand bandwidth usage, identify connection issues, and spot potential misconfigurations.
Key Network Metrics
- Bandwidth Utilization: The amount of data being transferred over the network interface compared to its maximum capacity, usually measured in bits per second (bps) or bytes per second (Bps).
- Connections: The number of active network connections, listening ports, and their states.
- Errors: The number of errors occurring on network interfaces (e.g., dropped packets, collisions). High error rates indicate problems.
- Packet Rate: The number of network packets being sent and received per second.
Tools for Network Insights
ss(Socket Statistics): A modern utility that has largely replaced the oldernetstatcommand.ssis used to investigate network sockets (connections).ss -tulnp: Shows all TCP (-t), UDP (-u), listening (-l), numeric (don't resolve hostnames/ports,-n), and process (-p) information. This is a very common and useful combination.# Example: List all listening TCP and UDP sockets with process names sudo ss -tulnpss -tan: Shows all TCP connections in a numeric format including their state (e.g., ESTABLISHED, LISTEN, TIME_WAIT).
netstat(Network Statistics): The older command for displaying network connections, routing tables, interface statistics, etc. Many of its functions are now better handled byssorip.- If you still use it,
netstat -tulnpis similar to thessexample above.
- If you still use it,
iftop(Interface Top): An interactivetop-like utility for displaying bandwidth usage on a network interface in real time. It shows you which connections are using the most bandwidth. (You might need to install it:sudo apt install iftoporsudo yum install iftop).- You typically need to specify an interface:
sudo iftop -i eth0(replaceeth0with your actual network interface name, likeenp0s3orwlan0). - Press
Pto toggle port display,nto toggle DNS resolution.# Example: Monitor bandwidth on interface enp0s3 sudo iftop -i enp0s3
- You typically need to specify an interface:
nload: A simple command-line tool that monitors network traffic and bandwidth usage in real time. It provides a nice visual graph. (You might need to install it:sudo apt install nloadorsudo yum install nload).- Just run
nload. You can switch between devices using the arrow keys. nload eth0: Monitor a specific device.# Example: Monitor network traffic on all detected devices (use arrows to switch) nload
- Just run
By keeping an eye on disk I/O, filesystem capacity, and network activity using these tools and metrics, you can ensure your system remains performant, responsive, and well-connected, addressing issues before they impact your users or applications.