htop is a highly interactive and user-friendly process viewer for Linux systems, offering a real-time overview of system processes, memory, and CPU usage. In this article, you'll learn how to install htop on an Ubuntu VPS, explore its key features, and use it to monitor server performance efficiently.
10 min
Edited:12-10-2024
htop is a command-line, interactive system-monitoring tool for Unix-based systems like Linux. It provides an intuitive, colorful interface to monitor system resource usage, including CPU, memory, and running processes. Unlike the traditional top command, htop allows you to scroll through processes, manage them with ease, and get a comprehensive visual display of system health. htop is particularly useful for system administrators managing VPS (Virtual Private Servers) or dedicated servers because it enables quick and efficient process management, which is crucial for maintaining optimal server performance.
1 - Real-Time System Monitoring: Displays CPU, memory, and swap usage along with system load.
2 - Process Management: Allows you to easily kill, renice, or manage processes directly from the interface.
3 - Visual Representation: CPU and memory usage is shown in visual bar graphs, making it easy to interpret system load.
4 - User-Friendly: Navigate through processes using arrow keys, and filter processes with a search function.
5 - Customizable Interface: Customize the appearance and functionality to suit your specific monitoring needs.
Installing htop on your Ubuntu VPS is a straightforward process. Follow these steps to install and configure htop on an Ubuntu-based system.
Before installing htop, update your system to ensure all existing packages are up-to-date:
1. sudo apt update
2. sudo apt upgrade
htop is available in the default Ubuntu package repositories, so you can install it using the apt package manager. Simply run the following command:
1. sudo apt install htop
Once the installation is complete, verify that htop has been installed successfully by running:
1. htop --version
This should display the installed version of htop.
Now that htop is installed, let’s explore its interface and learn how to use it for monitoring your VPS.
To start htop, simply type the command:
1. htop
You will see a colorful, dynamic interface displaying system resource usage, CPU load, memory, and a list of all running processes.
The htop interface is divided into two main sections:
Top Section: Displays system information such as CPU usage, memory, swap, system load averages, and uptime. Each CPU core is represented with a usage bar.
Bottom Section: Lists all running processes, with columns for PID, user, CPU usage, memory consumption, and the command used to start each process.
You can scroll through this list of processes using the arrow keys and sort them based on different criteria (CPU usage, memory, etc.).
Here are some essential htop features and commands for effective server monitoring and process management:
F1 (Help): Shows the help menu and lists all available keyboard shortcuts.
F2 (Setup): Opens the configuration menu, where you can customize htop's appearance and behavior.
F3 (Search): Allows you to search for a specific process by name. Simply press F3 and start typing the name of the process.
F4 (Filter): Filters processes based on certain criteria, like user or process name.
F5 (Tree View): Switches to a tree view, which shows parent-child relationships between processes.
F6 (Sort): Sorts processes based on a selected column (e.g., CPU, memory, or time).
F9 (Kill Process): Allows you to kill a selected process. After selecting a process, press F9, and choose the signal to send (SIGTERM or SIGKILL).
F10 (Quit): Exits htop.
To identify resource-heavy processes, sorting and filtering are critical. You can sort processes by different columns, like CPU usage or memory consumption, using the F6 key. For example, if you want to identify the processes consuming the most CPU resources, press F6, and then choose CPU% as the sorting column.
You can also filter processes to focus on a specific user’s processes or find a particular one by using F3 for searching or F4 for filtering.
One of the best features of htop is the ability to manage processes directly from the interface. Here's how you can manage processes:
Killing a Process: To terminate a process, navigate to it using the arrow keys, press F9, and select the signal you want to send (e.g., SIGKILL to forcefully terminate the process).
Renicing a Process: If you want to change the priority of a process, you can "renice" it (change its niceness value). Select the process, press F7 to increase its priority, or F8 to decrease it.
htop provides a wide range of customization options that allow you to tailor its interface to your needs.
1 - Press F2 to enter the configuration menu.
2 - Use the arrow keys to navigate the setup options, where you can configure meters (the graphical display of CPU, memory, swap usage), columns (which process attributes to display), and more.
For example, you might want to display additional columns like the process owner or the path to the executable file, or hide certain meters to simplify the display.
At the top of the htop interface, you can see vital system information, such as:
CPU Usage: Shows CPU usage for each core, as well as total CPU load. The usage is displayed as a horizontal bar graph.
Memory Usage: Displays total, used, and free memory in real time.
Swap Usage: Shows swap memory usage, which can help you identify if your system is running out of physical RAM and swapping to disk.
System Load: Shows system load averages (1 minute, 5 minutes, 15 minutes) and uptime, providing a quick view of how busy your system has been over time.
Suppose your VPS is running slower than usual, and you want to identify which processes are consuming excessive CPU resources. Here’s how you can do it using htop:
1 - Launch htop by typing htop in your terminal.
2 - Press F6 to open the sorting menu.
3 - Select CPU% to sort processes by CPU usage in descending order.
4 - The most CPU-intensive processes will appear at the top of the list. If a process is consuming excessive CPU, you can select it and press F9 to terminate it, or F7/F8 to adjust its priority.
This can help you quickly mitigate performance issues by identifying and managing resource-hogging processes.
htop is a powerful, interactive system monitoring tool that offers a detailed and real-time view of your server's processes and resource usage. Its user-friendly interface and extensive feature set make it an invaluable tool for system administrators who need to monitor and manage VPS performance efficiently. By following this guide, you’ve installed htop on your Ubuntu VPS, explored its key features, and learned how to use it effectively for real-time monitoring and process management. With htop, keeping your server’s performance in check becomes simpler, faster, and more intuitive.
14-10-2024
This article offers a detailed guide on installing and configuring IPTables on an Ubuntu VPS. IPTables is a powerful firewall tool that helps secure your server by controlling inbound and outbound traffic. Learn how to set up rules for traffic filtering, configure basic security policies, and apply custom rules to protect your VPS.
IPtables
security
12 min
This article offers a comprehensive guide on installing and configuring ModSecurity, a powerful web application firewall (WAF), on an Ubuntu VPS. Learn how to secure your server by filtering and monitoring HTTP requests, set up ModSecurity with Nginx or Apache, and apply rules to protect against common web attacks.
Modsecurity
security
10 min
14-10-2024
This article provides a comprehensive guide on installing and configuring PHP-FPM (FastCGI Process Manager) on an Ubuntu VPS. Learn how to optimize PHP performance for your web applications by configuring PHP-FPM with Nginx or Apache, managing pools, and fine-tuning settings for efficient processing of PHP scripts.
PHP-FPM
speed
optimise
12 min