Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Linux Performance Monitoring & File System Stats

· 6 min read · Home Tech

In this article
  1. Background: Why Monitor Performance and File Systems
  2. Core Performance Monitoring Commands
  3. File System Statistics: df and du
  4. How to Interpret the Output
  5. Common Problems and How to Diagnose Them
  6. Choosing the Right Tool for the Job
  7. Costs and Safety Considerations
  8. Frequently Asked Questions

Linux performance monitoring and file system statistics reports are the core tools for understanding how a system uses CPU, memory, disk, and network resources, and for diagnosing slowdowns or capacity issues. This article explains the standard commands, their output formats, and how to interpret them for real-world troubleshooting.

Background: Why Monitor Performance and File Systems

Linux systems run everything from small embedded devices to large servers. Performance monitoring helps you answer questions like: Is the CPU saturated? Is memory exhausted? Is the disk the bottleneck? File system statistics specifically track disk usage, inode consumption, and I/O throughput. Without these reports, you are guessing. They reveal whether an application is slow because of a hardware limit, a configuration problem, or a runaway process. System administrators and developers rely on these tools for capacity planning, identifying leaks, and tuning kernel parameters.

Core Performance Monitoring Commands

The most common tools come with the procps-ng and sysstat packages. Here are the essentials:

  • top – real-time view of processes, CPU usage, memory, load average, and running tasks.
  • htop – an interactive, colorized alternative to top (often installed separately).
  • vmstat – reports virtual memory, paging, block I/O, and CPU activity in snapshots.
  • iostat – per-disk and per-partition CPU and I/O statistics.
  • sar – collects and reports historical system activity data (from sysstat).
  • free – shows memory and swap usage in human-readable form.
  • mpstat – reports per-processor CPU usage.
  • pidstat – per-process statistics for CPU, memory, I/O, and context switches.

Each command has a different focus. For a quick overview, top is the first stop. For a deeper look at disk I/O, iostat -x gives extended device statistics like await, svctm, and %util. For historical trends, sar can log data at regular intervals and let you review past performance.

File System Statistics: df and du

File system statistics are primarily about space and inode usage. The two fundamental commands are:

  • df – reports free and used space on mounted file systems. Use df -h for human-readable sizes and df -i to show inode usage.
  • du – summarizes disk usage of files and directories. Use du -sh /path to get a total for a directory, or du -ah to list every file.

Inodes are metadata structures that store file information. A file system can run out of inodes even when space is free, which prevents creating new files. Checking df -i is critical on systems with many small files, such as mail servers or temporary directories. If inodes are exhausted, you must delete files, not just free space.

How to Interpret the Output

Raw numbers mean little without context. Here is how to read common metrics:

  • Load average (from top or uptime): three numbers over 1, 5, and 15 minutes. A load above the number of CPU cores indicates saturation.
  • %us, %sy, %wa, %st (from vmstat or top): user CPU, system CPU, I/O wait, and stolen time. High %wa points to disk bottlenecks.
  • si and so (from vmstat): swap in and swap out. Non-zero values mean memory pressure.
  • %util (from iostat -x): the percentage of time the disk was busy. Values near 100% suggest saturation, but modern drives can report 100% with low actual throughput due to queuing.
  • await (from iostat): average time for an I/O request to complete, including queue time. High await relative to device capability signals contention.

Always compare metrics over time. A single snapshot can be misleading. Use sar to collect data at 10-minute intervals and review daily reports.

Common Problems and How to Diagnose Them

Here are typical scenarios and the commands that reveal them:

  • High CPU usage: Run top and sort by CPU with P. Identify the process. Use pidstat -p PID 1 to watch its CPU over time.
  • Out of memory (OOM): Check free -h for low available memory and high swap usage. Look at dmesg | grep -i oom to see if the kernel killed processes.
  • Disk full: Run df -h to find the full mount point. Then du -x --max-depth=1 /path | sort -n to locate the largest directories.
  • High I/O wait: Use iostat -x 1 to see which device is busy. Check if it is a specific partition or a shared disk.
  • Inode exhaustion: Run df -i. If the used inode percentage is near 100%, find directories with many small files using find / -xdev -type f | wc -l per directory.

A common misconception is that a high load average always means CPU problems. It can also be caused by processes stuck in uninterruptible sleep (usually I/O). Check the process state in top; a D state means waiting for disk.

Choosing the Right Tool for the Job

No single command covers everything. The choice depends on the question:

  • Quick health check: top, free -h, df -h.
  • Historical analysis: sar (requires sysstat service enabled).
  • Per-process breakdown: pidstat.
  • Disk performance: iostat -x.
  • Network performance: netstat -i or ip -s link (though not covered in depth here).
  • File system space: df and du.

For deeper analysis, tools like perf (for CPU profiling), strace (for system calls), and iotop (for per-process I/O) are available, but they require root privileges and more expertise.

Costs and Safety Considerations

Most monitoring commands are free and open source. The main cost is the overhead of collecting data. Running sar with frequent intervals writes logs to disk, which can consume space over time. The sysstat package typically rotates logs via logrotate. For production systems, keep monitoring intervals reasonable (e.g., 1-5 minutes) and store logs for the retention period you need.

Safety: These commands are read-only and do not modify the system. However, some tools like iostat may require root to access certain disk metrics. Always run them as a normal user first; if permission denied, use sudo. Do not run du on very large file systems without proper filters, as it can take a long time and consume I/O.

Frequently Asked Questions

What is the difference between df and du?

df reports the space usage of entire file systems (mount points), while du estimates the space used by files and directories. They can differ because df includes reserved blocks and metadata, and du counts only file contents.

Why does df show 100% usage but du shows less?

This happens when deleted files are still held open by a process. The space is not freed until the process closes the file. Use lsof +L1 to find such files, or restart the process.

How can I monitor performance in real time?

Use top or htop for an interactive view. For a continuous log, run sar -u 1 0 to output CPU usage every second indefinitely, or use vmstat 1 for a rolling summary.

What is a good load average for a server?

It depends on the number of CPU cores. A load average below the core count is generally fine. For example, on a 4-core system, a load of 3.5 is high but not necessarily critical; sustained load above the core count indicates saturation.

How do I check if my disk is the bottleneck?

Run iostat -x 1 and look at %util and await. If %util is near 100% and await is high, the disk is likely saturated. Also check vmstat for high wa (I/O wait) values.

Can I monitor performance without root access?

Most basic commands like top, free, and df work as a normal user. Some detailed statistics, such as per-process I/O in pidstat, may require root. However, you can often use sudo if you have permission.