Search Our Database

How to monitor Server Performance with htop and top

Last updated on |

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

top

Step 2: Understanding the top Interface

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

 

 


 

Monitoring with htop

Step 1: Install htop

Use the following commands based on your distribution:

sudo apt update
sudo apt install htop

Step 2: Launch htop

htop

Step 3: Understanding the htop Interface

  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]

  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
 1011 root       20   0  158M  8.4M  6.4M  S   0.3  0.1   0:01.33 sshd
 1221 ubuntu     20   0  12M   3.2M  2.8M  S   0.0  0.0   0:00.04 bash
 1257 ubuntu     20   0  42M   3.6M  3.1M  R   0.0  0.0   0:00.12 htop

 

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.