피드 구독
Linux 

According to its man page, the top command—referred to below as Linux top—provides "a dynamic real-time view of a running system." As the man page explains, top displays "system summary information as well as a list of processes or threads currently being managed by the Linux kernel. The types of system summary information shown" by the Linux top command, and the "order and size of information displayed … are all user-configurable, and configuration changes can be made persistent across restarts."

Of course, at times you’ll need to dig deeper than the Linux top command; especially for application performance monitoring, log analytics, etc. Take a look at some of the solutions in my 100 Top Server Monitoring & Application Performance Monitoring (APM) Solutions list.

The Linux top command provides an “interactive interface for process manipulation as well as a much more extensive interface for personal configuration" that encompasses almost "every aspect of its operation.”

Customizing the Linux top command

To run Linux top , you simply type top on the command line. By default, the Linux top command looks similar to the screenshot below: 

The Linux top command in action.

 

To customize, let’s begin with the memory scale by pressing E (Shift+E) and then e. Then, save changes using W (Shift+W) and continue from there.

First, an explanation for E and then e. E refers to Extend-Memory-Scale in Summary Area. According to the top man page:

With this command, you can cycle through the available summary area memory scaling which ranges from KiB (kibibytes or 1,024 bytes) through EiB (exbibytes or 1,152,921,504,606,846,976 bytes). If you see a + between a displayed number and the following label, it means that top was forced to truncate some portion of that number. By raising the scaling factor, such truncation can be avoided.

The e option refers to Extend-Memory-Scale in Task Windows. According to the top man page:

With this command you can cycle through the available task window memory scaling which ranges from KiB (kibibytes or 1,024 bytes) through PiB (pebibytes or 1,125,899,906,842,624 bytes). While top will try to honor the selected target range, additional scaling might still be necessary in order to accommodate current values. If you wish to see a more homogeneous result in the memory columns, raising the scaling range will usually accomplish that goal. Raising it too high, however, is likely to produce an all zero result which cannot be suppressed with the 0 [numeric not the letter] interactive command.

Next, when monitoring MySQL, Apache (and/or Nginx), and other threaded software it can be useful to add a column for the number of threads (nTH). You can do this using Fields-Management.

Typing f and F activates Fields-Management. According to the top man page:

These keys display a separate screen where you can change which fields are displayed, their order, and also designate the sort field.

I’ve added PPID (Parent Process Id), SWAP, and nTH as well.

Here are the other customization options I’ve used, as taken from the top man page:

  • c: Command-Line/Program-Name toggle
    This command will be honored whether or not the COMMAND column is currently visible. Later, should that field come into view, the change you applied will be seen.

  • f | F: Fields-Management
    These keys display a separate screen where you can change which fields are displayed, their order, and also designate the sort field.

  • 1: Single/Separate-Cpu-States toggle
    This command affects how the t command’s Cpu States portion is shown. Although this toggle exists primarily to serve massively-parallel SMP machines, it is not restricted to solely SMP environments. When you see %Cpu(s): in the summary area, the 1 toggle is On and all cpu information is gathered in a single line. Otherwise, each cpu is displayed separately as %Cpu0, %Cpu1, ... up to available screen height.

  • b: Bold/Reverse toggle
    This command will impact how the x and y toggles are displayed. It may also impact the summary area when a bar graph has been selected for cpu states or memory usage via the t or m toggles.

  • x: Column-Highlight toggle
    Changes highlighting for the current sort field. If you forget which field is being sorted this command can serve as a quick visual reminder, providing the sort field is being displayed. The sort field might not be visible because: 1) there is insufficient Screen Width 2) the f interactive command turned it Off. Note: Whenever Searching and/or Other Filtering is active in a window, column highlighting is temporarily disabled.

  • y: Row-Highlight toggle
    Changes highlighting for "running" tasks … Use of this provision provides important insight into your system’s health. The only costs will be a few additional tty escape sequences.

  • z: Color/Monochrome toggle
    Switches the current window between your last used color scheme and the older form of black-on-white or white-on-black. This command will alter both the summary area and task area but does not affect the state of the x, y, or b toggles.

  • i: Idle-Process toggle
    Displays all tasks or just active tasks. When this toggle is Off, tasks that have not used any CPU since the last update will not be displayed. However, due to the granularity of the %CPU and TIME+ fields, some processes may still be displayed that appear to have used no CPU. If this command is applied to the last task display when in alternate-display mode, then it will not affect the window’s size, as all prior task displays will have already been painted.

  • Z: Change-Color-Mapping
    This key will take you to a separate screen where you can change the colors for the current window, or for all windows.

  • W: Write-the-Configuration-File
    This will save all of your options and toggles plus the current display mode and delay time. By issuing this command just before quitting top, you will be able [to] restart later in exactly that same state.

You can continue to customize by reading the full Linux top man pages using the command man top. You can find additional tips such as filtering Linux top command output by user, where you start top with top -u <user>. You can also press h while viewing top to open the "Help for Interactive Commands" screen.

This post should serve as a quick guide to encourage you to explore customization, allowing you to get the most out of the Linux top command. Below, or at the very top of this post (using color), you can see the result of these Linux top tweaks:

The top command after customization.

Reverting to default Linux top

When you save using W, notice that top displays the path to the file it creates to save custom settings. You can either empty, move, or delete that file to start over.

For example, in my case, I used:

mv ~/.toprc ~/.toprc_bk

If you don’t care to restore from that file, you can delete it with:

rm ~/.toprc

This article was originally posted on HaydenJames.io.

[Want to try out Red Hat Enterprise Linux? Download it now for free.]


저자 소개

Hayden James is a Linux Systems Analyst and Internet Entrepreneur from the Caribbean. He relocated to the US ten years ago, where he maintained Linux servers and sold small startups. Today, he supports clients remotely from his island home while also managing a niche web hosting venture. His web blog features Linux Sysadmin related articles: haydenjames.io.

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

채널별 검색

automation icon

오토메이션

기술, 팀, 인프라를 위한 IT 자동화 최신 동향

AI icon

인공지능

고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트

open hybrid cloud icon

오픈 하이브리드 클라우드

하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요

security icon

보안

환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보

edge icon

엣지 컴퓨팅

엣지에서의 운영을 단순화하는 플랫폼 업데이트

Infrastructure icon

인프라

세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보

application development icon

애플리케이션

복잡한 애플리케이션에 대한 솔루션 더 보기

Virtualization icon

가상화

온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래