Smart Systems for Home

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

Monitor Linux System Performance from the Terminal

· 4 min read · Home Tech

In this article
  1. Why Monitor from the Terminal?
  2. Core Built-in Tools
  3. Advanced Real-Time Monitors
  4. How to Use Each Tool Effectively
  5. Logging and Historical Data
  6. Common Problems and Troubleshooting
  7. Choosing the Right Tool
  8. Frequently Asked Questions

You can monitor Linux system performance directly from the terminal using built-in command-line tools that display real-time CPU, memory, disk, and network activity. These tools require no graphical interface and work on any Linux distribution, making them essential for administrators and power users.

Why Monitor from the Terminal?

Terminal-based monitoring is lightweight, fast, and works over SSH or on servers without a desktop environment. Unlike GUI tools that consume system resources, command-line utilities have minimal overhead, so they provide a more accurate picture of what the system is actually doing. They are also scriptable, allowing you to log performance data or trigger alerts automatically.

Core Built-in Tools

Every Linux system ships with several basic monitoring commands. The top command shows a live, updating list of processes sorted by CPU usage, with summary statistics at the top for load average, tasks, CPU percentages, and memory usage. Press q to quit. free -h displays memory and swap usage in human-readable units. df -h shows disk space usage for mounted filesystems, while iostat (from the sysstat package) reports disk I/O statistics. For network activity, ss or netstat can show active connections, but for throughput, you often need additional tools.

Advanced Real-Time Monitors

For more detailed and interactive views, install htop (a colorful, scrollable process viewer with mouse support), iotop (per-process I/O usage), nload or bmon (network bandwidth), and glances (an all-in-one dashboard). These tools are available in most distribution repositories. For example, on Debian/Ubuntu, run sudo apt install htop iotop nload glances. On Fedora/RHEL, use sudo dnf install htop iotop nload glances.

How to Use Each Tool Effectively

  • htop: Sort by CPU or memory by pressing F6, filter processes with F4, and kill a process with F9. The header shows color-coded bars for CPU cores and memory.
  • iotop: Requires root privileges. It shows each process's disk read/write speeds. Use iotop -o to only show processes doing I/O.
  • nload: Displays incoming and outgoing network traffic on all interfaces, with a graph. Press F2 to switch interfaces.
  • glances: Provides a comprehensive dashboard with CPU, memory, disk, network, and top processes. Press 1 for per-core CPU, d for disk I/O, and n for network.

Logging and Historical Data

For long-term monitoring, use sar (from sysstat) to collect and report historical data. The sysstat service runs in the background and logs data every 10 minutes by default. You can then query it with commands like sar -u (CPU), sar -r (memory), sar -b (I/O), and sar -n DEV (network). To enable sysstat on systemd-based systems, ensure the service is enabled with sudo systemctl enable --now sysstat.

Common Problems and Troubleshooting

If a tool is not installed, use your package manager to install it. For iotop and sar, you may need root privileges. If htop does not show all CPU cores, press F2 and check the Display options. For network tools, ensure you are monitoring the correct interface (e.g., eth0, wlan0, or ens33). If glances is not available, you can run it via pip install glances as a fallback.

Choosing the Right Tool

Select the tool based on what you need to monitor. For a quick check of system load, use top or htop. For disk I/O bottlenecks, use iotop. For network throughput, use nload. For a comprehensive overview, use glances. For historical analysis, use sar. For scripting, use top -b -n1 to get a single batch output, or vmstat for a concise snapshot of system processes, memory, paging, block I/O, traps, and CPU activity.

Frequently Asked Questions

How do I monitor CPU usage in real time?

Use top or htop. top is preinstalled on most systems; htop offers a nicer interface. Both show per-core usage and overall CPU percentage.

What is the difference between top and htop?

top is the classic tool, text-based and minimal. htop is a modern alternative with color, mouse support, and easier process management. Both show similar information, but htop is more user-friendly.

How can I monitor memory usage?

Run free -h for a quick summary of RAM and swap. For per-process memory, use top and press M to sort by memory, or use ps aux --sort=-%mem.

How do I check disk I/O performance?

Install and run iotop (requires root) to see per-process disk usage. For a system-wide summary, use iostat -x 2 (from sysstat) to show extended statistics updated every 2 seconds.

Can I monitor network bandwidth from the terminal?

Yes, use nload or bmon for real-time graphs. For a simple per-second count, use sar -n DEV 1 or vnstat for daily totals.

How do I log performance data for later analysis?

Enable the sysstat service to collect data automatically, then use sar to query it. Alternatively, redirect top -b -n1 to a file in a cron job to create custom logs.