Install and Use htop Command on Rocky Linux 8 | Easy Setup

Posted on

Install and Use htop Command on Rocky Linux 8 | Easy Setup

Install and Use htop Command on Rocky Linux 8 | Easy Setup

In this guide, you will learn to Install and Use htop command on Rocky Linux 8. The htop command is a Linux utility designed to display critical information about your system’s processes in a dynamic, user-friendly way. Think of it as a more powerful and interactive counterpart to the Windows Task Manager, offering a wealth of information at a glance. What sets htop apart is its interactive nature; it supports mouse and keyboard operations, making it easy to navigate between values and tabs to quickly pinpoint resource-intensive processes. Mastering the htop command is essential for system administrators and developers seeking efficient resource monitoring and process management on Rocky Linux 8.

You can now proceed to the guide steps below on the Orcacore website to learn how to use the htop command on Rocky Linux 8.

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Rocky Linux 8.

1. Install htop on Rocky Linux 8

First, update your local package index to ensure you’re working with the latest package information. Execute the following command:

sudo dnf update -y

Next, you need to install the EPEL (Extra Packages for Enterprise Linux) Repository on your server. This repository provides access to additional packages not available in the base Rocky Linux 8 repositories. Use the following command:

sudo dnf install epel-release -y

With the EPEL repository enabled, you can now install htop using the following command:

sudo dnf install htop -y

Finally, verify your htop installation by checking its version. This confirms that the installation was successful.

htop --version
**Output**
htop 3.2.1

2. How to Use the htop Command?

With htop successfully installed, you can now launch it by simply typing the command:

htop
Install and Use htop Command on Rocky Linux 8

This will present a standard overview of your system’s processes and resource usage, suitable for most users who need to quickly check system stats. The htop interface provides real-time updates on CPU usage, memory consumption, swap usage, and a list of running processes.

Here are some common options for the htop command:

options for htop command

One of the most useful parameters is delaying the update frequency. Many users prefer to have htop constantly running to monitor system or network performance. However, frequent updates can consume resources.

htop -d 10

This command adds a ten-second delay between updates. You can specify any delay you want in seconds. A higher delay reduces the resource consumption of htop itself.

Below is a list of the most commonly used keys within the htop interface:

htop command shortcuts

3. Remove htop from Rocky Linux 8

If you no longer need htop on your server, you can easily remove it using the following command:

sudo dnf autoremove htop -y

This command will remove htop and any dependencies that are no longer required by other packages on your system.

Conclusion

In conclusion, installing and using the htop command on Rocky Linux 8 provides an enhanced, interactive way to monitor system resources and processes. With its user-friendly interface and real-time updates, htop is a valuable tool for system performance management and troubleshooting. The simplicity of installation coupled with its feature-rich interface makes htop command a must-have for any Rocky Linux 8 user.

Hope you enjoy it. Please subscribe to us on Facebook, Instagram, and YouTube.

You may also like these articles:

How To Set up MediaWiki on CentOS 7

How To Install Anaconda on Centos 7

Set up and Configure GlassFish on Debian 11

Alternative Solutions for System Monitoring on Rocky Linux 8

While htop is a powerful and user-friendly tool, there are alternative methods for monitoring system resources and processes on Rocky Linux 8. Here are two different approaches:

1. Using top command with custom scripts

The top command is a standard Linux utility that provides a dynamic real-time view of running processes. While not as visually appealing as htop, top can be incorporated into scripts for automated monitoring and alerting.

Explanation:

The top command offers a wealth of information similar to htop, including CPU usage, memory consumption, and process details. The key difference is that top is primarily text-based and less interactive. However, its output can be easily parsed by scripts, making it suitable for automated monitoring. By combining top with scripting languages like bash or Python, you can create custom monitoring solutions that trigger alerts when certain thresholds are exceeded.

Code Example (Bash Script):

This script monitors CPU usage and sends an email alert if it exceeds 90%.

#!/bin/bash

# Set threshold for CPU usage
CPU_THRESHOLD=90

# Get CPU usage from top command
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2 + $4}')

# Check if CPU usage exceeds threshold
if (( $(echo "$CPU_USAGE > $CPU_THRESHOLD" | bc -l) )) ; then
  # Send email alert
  echo "CPU usage is above $CPU_THRESHOLD%: $CPU_USAGE%" | mail -s "High CPU Usage Alert" your_email@example.com
fi

How it works:

  • top -bn1: Runs top in batch mode, taking only one snapshot.
  • grep "Cpu(s)": Filters the output to find the line containing CPU usage information.
  • awk '{print $2 + $4}': Extracts the user and system CPU usage percentages and adds them together.
  • bc -l: A command-line calculator used for floating point arithmetic. bc is necessary because standard shell arithmetic only handles integers.
  • mail -s "High CPU Usage Alert" your_email@example.com: Sends an email alert with the CPU usage information. You will likely need to configure a mail transfer agent (MTA) like postfix or sendmail on your Rocky Linux 8 system for this to work.

This is a basic example, and you can customize it to monitor other metrics like memory usage or specific process resource consumption.

2. Using nmon for Performance Analysis

nmon (Nigel’s Performance Monitor) is another powerful tool for monitoring system performance. It provides a comprehensive overview of CPU, memory, disk I/O, network, and other system resources.

Explanation:

nmon is designed to provide a detailed analysis of system performance. It displays information in a text-based interface, similar to top, but offers more granular details and historical data. nmon can also generate data files that can be analyzed later using the nmon analyser tool. This makes it useful for identifying performance bottlenecks and tracking system behavior over time.

Installation (if not already installed):

sudo dnf install nmon -y

Usage:

Simply run nmon from the command line. The interface will display various system statistics. You can press specific keys (like ‘c’ for CPU, ‘m’ for memory, ‘d’ for disk) to toggle the display of different metrics. To capture data to a file for later analysis, use the -f option:

nmon -f -s 30 -c 60

This command will run nmon for 60 intervals of 30 seconds each, saving the data to a file. You can then use the nmon analyser (typically a spreadsheet) to visualize and analyze the collected data.

Benefits of nmon:

  • Comprehensive overview of system resources.
  • Ability to capture data for historical analysis.
  • Useful for identifying performance bottlenecks.

These alternatives provide different approaches to system monitoring, each with its own strengths and weaknesses. While htop offers an interactive and user-friendly experience, top and nmon can be used for automated monitoring and detailed performance analysis. The best choice depends on your specific needs and preferences.

Leave a Reply

Your email address will not be published. Required fields are marked *