Search Our Database
How to monitor Server Performance with htop and top
Introduction
Monitoring server performance is crucial for maintaining system stability, optimizing resource usage, and quickly identifying potential issues. Two of the most widely used tools for this purpose are htop and top, both of which provide real-time, command-line-based monitoring of system processes and resource utilization. These tools help administrators gain valuable insights into CPU usage, memory allocation, system load, and active processes, making it easier to detect bottlenecks and inefficiencies.
top is a classic, pre-installed utility on most Unix-like systems that displays an overview of system resource usage and running processes. It offers a simple, text-based interface that allows users to sort processes by CPU, memory, or time, and manage them directly from the command line. On the other hand, htop is an enhanced, interactive alternative to top. It features a more user-friendly interface with color-coded displays, visual indicators, and intuitive navigation, allowing users to scroll through processes, kill tasks, and customize the display with ease.
These tools are essential for system administrators, developers, and anyone responsible for maintaining Linux servers. This guide provides step-by-step instructions on how to install, use, and interpret the outputs of htop and top to effectively monitor server performance.
Prerequisites
- Access to a Linux-based server via terminal or SSH.
- Root or sudo privileges to install software and manage processes.
- Basic familiarity with the command line interface (CLI).
- htop may need to be installed manually, while top is typically pre-installed on most Linux distributions.
Step-by-step Guide
Monitoring with top
Step 1: Launch top
To begin monitoring system resource usage, launch the top utility from your terminal:
top
This command opens an interactive, real-time display of active processes, CPU usage, memory consumption, and system load.
Step 2: Understanding the top Interface
Once top is running, the interface is divided into two main sections:
-
System summary (top few lines):
-
load average: Shows system load over 1, 5, and 15 minutes.
-
Tasks: Indicates the total number of processes and their states (running, sleeping, etc.).
-
%Cpu(s): Breaks down CPU usage into user, system, idle, and other categories.
-
MiB Mem and MiB swap: Displays memory and swap usage, including buffer/cache data.
-
Example output:
top - 12:45:17 up 10 days, 3:15, 2 users, load average: 0.20, 0.15, 0.10 Tasks: 132 total, 1 running, 131 sleeping, 0 stopped, 0 zombie %Cpu(s): 5.0 us, 1.5 sy, 0.0 ni, 93.0 id, 0.5 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 7982.3 total, 2020.5 free, 2510.3 used, 3451.5 buff/cache MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 5020.1 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1254 root 20 0 475460 59804 14928 S 3.3 0.7 0:15.42 python3 2312 mysql 20 0 1789652 356320 25812 S 2.7 4.4 12:23.67 mysqld 1011 root 20 0 162180 8604 6580 S 0.3 0.1 0:01.33 sshd 1221 ubuntu 20 0 12420 3320 2900 S 0.0 0.0 0:00.04 bash 1257 ubuntu 20 0 43240 3740 3180 R 0.0 0.0 0:00.12 top
Process list (bottom section):
-
Displays a live list of all processes with metrics such as:
-
PID: Process ID
-
USER: Process owner
-
%CPU, %MEM: CPU and memory consumption
-
COMMAND: Name of the running command or service
-
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1254 root 20 0 475460 59804 14928 S 3.3 0.7 0:15.42 python3 2312 mysql 20 0 1789652 356320 25812 S 2.7 4.4 12:23.67 mysqld
🖊️ Tip: Press q to exit the top utility.
Monitoring with htop
Step 1: Install htop
htop is an advanced alternative to top that provides a user-friendly, color-coded, and interactive interface.
To install htop:
sudo apt update sudo apt install htop
Step 2: Launch htop
After installation, launch the tool with:
htop
This will open an interactive dashboard with real-time CPU, memory, swap, and process activity.
Step 3: Understanding the htop Interface
CPU and Memory Bars (Top Area):
-
Visual bars show real-time CPU core usage, memory, and swap activity.
-
Tasks: Total number of running, sleeping, and zombie processes.
-
Load average and Uptime values are also shown for quick assessment.
1 [|||||||||||||||||||||||||| 75.0%] Tasks: 132, 1 running 2 [|||||||||||||| 50.0%] Load average: 0.20 0.15 0.10 3 [||||||||| 25.0%] Uptime: 10 days, 03:15:27 Mem[||||||||||||||||| 4.0G/7.8G] Swp[ 0K/2.0G]
Process List (Bottom Area):
-
Displays processes with sortable columns including:
-
PID, USER, CPU%, MEM%, Command
-
-
Press F6 to change sorting, F9 to kill a process, and arrow keys to navigate.
Example:
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command 1254 root 20 0 465M 58M 14M S 3.3 0.7 0:15.42 python3 2312 mysql 20 0 1.7G 348M 25M S 2.7 4.4 12:23.67 mysqld
🖊️ Tip: htop supports mouse navigation, which makes it easier to interact with running processes.
Conclusion
Monitoring server performance with htop and top is essential for system administrators and developers to ensure efficient resource usage and stable operations. While top provides a straightforward, text-based interface for monitoring, htop offers enhanced interactivity and a more user-friendly experience. By using these tools, administrators can easily identify performance bottlenecks, manage processes, and optimize system resources.
For more advanced monitoring and automation, consider integrating these tools with monitoring solutions like Nagios, Zabbix, or Prometheus.
Should you have any inquiries about the guidelines, please feel free to open a ticket through your portal account or contact us at support@ipserverone.com. We’ll be happy to assist you further.