htop: Quick Guide & Customization

htop is an interactive system-monitor, but also a process-viewer, process-manager, strace tool and more. Sysadmins may opt to use htop in cases where Unix top does not provide enough information about system processes.

htop uses a cursor-controlled interface for sending signals to processes. One example where this comes in handy is: you don’t have to type in PIDs, simply select one or more processes using your mouse cursor or other input device.

Although similar to top, htop also allows you to scroll vertically and horizontally, so you can see all the processes running on the system as well as viewing them as a process tree. Below is a screenshot of htop, taken from a StackLinux VPS which is hosting this blog:

htop screenshot

 

htop – How to Customize it

Now for the fun part of customizing htop. Here’s a quick guide. Open htop, use your mouse or touchpad to navigate. Start, by clicking Setup (bottom left) or by pressing F2 or shift + s. This will open the following screen:

htop setup

Just about all of us use top and htop, however, more often than not, we don’t tweak to our liking. (Also read: how to customize top command and atop for Linux server performance analysis, here’s how). From the above screen you can tweak many settings. These settings are then saved to $HOME/.config/htop/htoprc

 

Here’s a copy of my htoprc config file.

Feel free to copy, replace and tweak some more. Backup your config file first.

# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
fields=50 0 48 17 18 38 39 40 2 46 47 49 1
sort_key=111
sort_direction=1
hide_threads=1
hide_kernel_threads=1
hide_userland_threads=1
shadow_other_users=0
show_thread_names=0
show_program_path=1
highlight_base_name=0
highlight_megabytes=0
highlight_threads=0
tree_view=1
header_margin=1
detailed_cpu_time=1
cpu_count_from_zero=1
update_process_names=0
account_guest_in_cpu_meter=0
color_scheme=6
delay=15
left_meters=CPU AllCPUs
left_meter_modes=2 1
right_meters=Blank Clock Uptime LoadAverage Tasks Swap Memory
right_meter_modes=2 2 2 2 2 2 2

 

htop Tweaks for Linux Administrators

The following is a list of the htop modifications to better suit Linux administration.

  • Added detailed CPU usage line at the very top (System/IO-wait/Hard-IRQ/Soft-IRQ/Steal/Guest).
  • hide userland process threads. (Are the only processes visible without scrolling MySQL threads? This solves that. Optional)
  • Added NLWP column. NLWP = Number of threads in a process. (Eg. MySql) Useful when the above change is made.
  • Added detailed memory usage line. (mem/used/buffers/cache)
  • Change process lists to tree view.
  • Changed CPU count to start from 0.
  • Change CPU cores from 2, to 1 column. (may need more for high  # of cores)

Here’s a visual comparison. My tweaked config on the left and default htop on the right. (full sized image here):

tweaked htop config

 

Also read: htop and top alternatives: Glances, nmon.

 

Tags: , ,