I’m pretty sure that most of you already struggled with some low performance systems. In order to analyse such cases several tools and utilities, like top, nmon, fuser or lsof are available under Linux. However trying to dig in processes analysis and looking for files and processes relations may be quite painful.
To get started with performance checks and analysis, a interesting utility is available: htop
What is htop
htop is an interactive process viewer developed by Hisham Muhammad. It can be seen as an “enhancement” of the traditional top tool that is better known. In my point of view it is a pretty handy entry point for performance analysis on Linux. It integrates most of the top functionnalities and add some new one. Here is a brief summary of its main functions:
- Scroll the process list horizontally and vertically using the arrow keys
- Kill or renice processes (already in top)
- Actions on multiple processes through tagging using the space bar
- Pretty good visual representation of CPU, Memory and Swap usage
- Process tree view
- List files used by a process
- Search function
How to install htop
htop is available on most of the Linux distribution and even already included in several repositories such the canonical or the EPEL one. However if like me you do not have it in a repo, you can easily find the binaries and sources on the project web site http://htop.sourceforge.net/index.php?page=downloads
For my tests, I installed it on Oracle Enterprise Linux 5.7 using the RHEL binaries
Note that if you want to be able to display the files used by a process within htop, then lsof must be installed too.
htop supports 2 options when started:
- -d –> to specify a refresh delay
- -u –> to specify a user to filter on
In my examples below, I have started htop by filtering on the oracle user to get an eye on my databases processes.
The first point I found nice once I started htop was the visual representation of the server load. It provides a pretty good overview using colors, which is close from the principle used in nmon and really easy and fast to read.
In addition this part can be fully customized through the Setup (F2 or shift + s)
Then an other good idea in the tool is that unlike top the main functions are displayed at the bottom. This seems to be trivial but is quite useful while starting to use the tool or for people not using it often.
As htop is based on the same principle than top, it also integrates almost the same shortcuts. This means that if now F9 is designed to kill a process the shortcut k is still available. This should ease the switch for top users to htop.
Beside these “cosmetic” enhancement, the coolest features in htop are:
- Tree View
- File trace
- Syscall trace
The Tree View can be activated using F5 or the t shortcut. Then processes having child processes can be expended using the + or – key, which allows also to collapse the tree.
Tag – Multiple Actions
If you need to run the same action such kill or renice on several processes, htop offers the Tag function for this purpose. Using the space bar, you will be able to tag processes and then run an action on all of them. Tagged processes are highlighted.
You untag a process by pressing the space bar again or easily untag all processes using the shortcut U (shift + u)
Kill – select the signal
The kill function has been made much more handy. Instead entering a PID, now you just need to tag the process(es) you want to kill. In addition the nich thing is that you can select the signal you want to send to the process.
During your analysis if you have identified some processes using htop, you may want to check the files accessed by them. If lsof is installed, you even don’t need to switch from one utility to another anymore. It is integrated within htop. Simply select the process and use the shortcut l.
In the same idea than the file trace, htop allows you to trace all system call made and signals received by a process. This feature requires strace to be installed too.
So I hope that you find some interessting stuff in this overview of htop. If you want to look at it a bit deeper have a look on the project web site, http://htop.sourceforge.net/index.php?page=screenshots, or simple install it