How to Use the htop Command to Monitor System Processes and Resource Usage (2024)

Table of Contents

  • Introduction
  • What Can “top” Show You?
  • Getting Started
  • Part 1. The “htop” Summary Area: What it All Means
  • Part 2. Active Processes
  • Part 3. “htop” Commands
  • Part 4. Using the Data Inside “htop” to Troubleshoot Performance Issues
  • Further Reading

Introduction

htop is the prettier, more colorful, and slightly more up-to-date version of top. A few metrics such as steal and iowait are easier to see intop, but for most other purposes, htop may be the better tool for troubleshooting server performance issues.

Here is our article ontop, we’d recommend you start there and then come back to htop if you haven’t already read this:

How to use the top command to monitor system processes and resource usage

Just like top, this is an excellent skill to develop and will help assist you in diagnosing any performance issues on your websites and server. It’s easy to use once you know the basics.

The goal of this article is to get you to a place where you can run the htop command on your server and understand the information that it’s displaying.Armed with this information, you’ll be able to troubleshoot any performance issues you discover.

What Can “htop” Show You?

htopwill display a real-time overview of what’s happening on your server. In a nutshell, you’ll be able to see the following at a glance: –

  1. The number of individual CPU’s on your server and their resource usage broken down individually
  2. RAM usage broken down by processes, buffer, and disk cache
  3. Swap usage
  4. Total number of tasks, thread count, and the number of running tasks
  5. 1 minute, 5 minutes, and 15 minutes load averages
  6. System uptime and current time (by default, this is set to UTC time)
  7. A breakdown of running processes

How to Use the htop Command to Monitor System Processes and Resource Usage (1)

Getting Started

A note on system users – we highly recommend putting each of your websites on their own system user. Not only is important to keep your websites isolated from each other (a hacked/malware-infected website can’t affect sites on a different system user), it will also show in the USER column, so you can easily identify any site with high resource usage using either toporhtop.

For example, if my website was assigned to a system user called “steve-com”, in the USER column, you’ll see the user “steve-com” and know exactly which site you need to look into. If they were all on the same system user, you won’t be able to tell what’s going on.

To run the top command you will need to SSH into your server.Please see the following articles to get started:

Step 1.Generate your SSH Key

Step 2.Add your SSH Key to GridPane(also seeAdd default SSH Keys)

Step 3.Connect to your server by SSH as Root user(we like and useTermius)

Once inside your server, run:

htop

To exithtop useQorCTRL+C.

Part 1. The “htop” Summary Area: What it All Means

The summary area at the beginning is the system overview. Below we’ll cover what each part means, section by section.

CPU Breakdown

How to Use the htop Command to Monitor System Processes and Resource Usage (2)

Here, with the numbers 1 and 2, we can see this is a 2-core VPS. A 4 core will have 4 bars, 8 core = 8 bars, and so on. Each number/bar represents one CPU. Each bar has a % on the right-hand side indicating how much CPU is in use.

Specific CPU usage is then broken down by processes via the following color code:

  • Blue: The % of CPU used by low-priority processes
  • Green: The % of CPU used for user processes
  • Red: The % of CPU used by system/kernel processes

Bonus points: –

  • Yellow/Orange: The % of CPU used by IRQ time
  • Magenta:The % of CPU used by Soft IRQ time
  • Grey: The % of CPU by IO Wait time
  • Cyan: The % of CPU by Steal

topmaybe easier to understand in terms of what exactly is consuming CPU, but what we’re looking to see is just how busy are the CPU/s. In this article, the bars are mostly empty, which means the CPU is mostly idle.

The higher your CPU usage (full bars, higher percentage), the busier your system is, and this will affect the performance of your websites.

Bursts of high usage are normal and nothing to be concerned about. Sustained high CPU usage is something that requires further attention.

RAM and Swap Usage

How to Use the htop Command to Monitor System Processes and Resource Usage (3)

This section shows information regarding the memory usage of the system. We have RAM and Swap – Swap is part of your hard disk that’s used by your server like it uses RAM. This is why having spare disk space is important for your system and why performance issues can arise when your disk space usage gets past 90%. If you use software such as Photoshop, Illustrator, or other heavy Adobe Creative Cloud apps, you’ll likely have experienced the same thing on your computer.

RAM usage is broken down by colors.

  1. Green: Used memory pages
  2. Blue: Buffer pages
  3. Yellow: Cache pages

Swap space is your safety net if you run out of RAM. High swap and RAM usage will affect your system’s ability to process tasks efficiently, potentially resulting in 504 time-out errors. Processes will get slower and backed up while they wait for memory to become available.

Tasks

How to Use the htop Command to Monitor System Processes and Resource Usage (4)

For clarity, Tasks and Processes for our purposes are the same things. Here we have 44 total processes, with 1 currently running. 100 “thr” means “threads”. So here we have 44 tasks that are broken up into 100 threads.

Load Average

How to Use the htop Command to Monitor System Processes and Resource Usage (5)

This is the exact same breakdown that the top command gives. If you haven’t already read that article, please check it out (link at the top and bottom of this article). In a nutshell, here we can see the average “load” over one, five, and fifteen minutes.

Load is measured per CPU, so if you have more than one core, you will need to divide what you see by the number of cores your server is running. Sustained, high load times mean your server is consistently busy. This could be due to a number of reasons, such as high website traffic or a brute force attack. The rest of the data provided by htop should help fill in the gaps.

System Uptime and Current System Time

How to Use the htop Command to Monitor System Processes and Resource Usage (6)

Here you can see how long the server has been online and the current system time. For our purposes, this isn’t particularly important.

Part 2. Active Processes

So you now have an overview of what’s happening on your server at a glance. If you’re seeing high resource usage, we now need to look at the processes themselves to see what’s responsible.

The active process list is the lower part of the overview. This is highlighted below:

How to Use the htop Command to Monitor System Processes and Resource Usage (7)

Below is a quick breakdown of what each column displays: –

  • PID:Displays a task’s unique process ID
  • USER:The username of the user who started the task
  • PRI:Shows the scheduling priority of the task.
  • NI: Represents the nice value of the task. We covered this above in the CPU section in part 2. Nice affects the priority of a task – 19 being the lowest priority, -20 being the highest
  • VIRT:Shows the total amount of memory used by the task
  • RES:Shows the memory consumed by the process in RAM (in kb)
  • SHR:Represents the amount of shared memory (in kb) used by the task
  • S: The current status of the process (zombie, sleeping, running, uninterruptedly sleeping, or traced).
  • CPU%:Represents the percentage of CPU used by each process
  • MEM%:Shows the percentage of total available RAM used by each process
  • TIME+:The total amount of CPU Time used by the task, shown in hundredths of a second.
  • COMMAND:The name of the running process

Below these in the footer are htop‘s menu items. More on these below.

Part 3. “htop” Commands

Before anything else, you can scroll the process list with the arrow keys – vertically and horizontally. This will come in handy as you get to know the basics.

The bottom menu

You can exit any of the following commands by hitting Esc.

  • F1 Help:Opens a basic intro page detailing a lot of what’s in this very section
  • F2Setup: Customise features – you can probably leave it alone.
  • F3Search: Open up a search bar and run a search for processes
  • F4Filter: Filter processes by typing (e.g. filter all MySQL tasks by typing “MySQL”)
  • F5Tree: Show processes in a tree view
  • F6SortBy: Sort processes by specific columns
  • F7 Nice –: Increase the priority of a task by clicking on it or navigating to it with your arrow keys and hitting F7
  • F8 Nice +: Decrease the priority of a task by clicking on it or navigating to it with your arrow keys and hitting F8
  • F9 Kill: Kill a process
  • F10 Quit: Close htop

Awesome Shortcuts

You can use any of the following shortcuts simply by pressingthem on your keyboard. There are more available (press F1 for more details while inside htop), but for troubleshooting purposes, these are the main ones you’ll want to learn.

  • u: Display all processes owned by a specific user
  • p: Sort processes based on high CPU consumption
  • m: Sort processes based on high memory consumption
  • t: sort process on time.
  • Space: Navigate to the process and hit space to highlight it
  • Shift + u: Remove all tags
  • Shift + f: Highlight and follow a process.

Part 4. Using the Data Inside “htop” to Troubleshoot Performance Issues

The commands in part 4 can yield a lot of information to help you pinpoint performance issues. You’ll likely find that you’ll use F3, F4, F9, u, p, m, and twhen you’re insidehtop.

What we’re looking for here is what tasks in theCOMMANDcolumn are using the mostCPU%andMEM%. Once we know this, we can begin further diagnosis.

For example, if you’re seeing high PHP usage, it’s possible your server is experiencing a brute-force attack. Using the above commands, you should be able to narrow down a specific website and take action accordingly.

High MySQL may indicate database table locking or lack of proper caching.

Further Reading

If you haven’t already read the top article, we highly recommend you do so. Learn more abouthtopand further troubleshooting in the following guides:

  • How to use the top command to monitor system processes and resource usage
  • Diagnosing Performance Issues and 504 Timeouts
  • WordPress Debug and Query Monitor

You may also want to check out the Security and Performance sections of our knowledgebase here:

  • Performance
  • Security

You can also learn more about top directly on your server with:

man htop
How to Use the htop Command to Monitor System Processes and Resource Usage (2024)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Mr. See Jast

Last Updated:

Views: 6452

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.