Lead Image © citalliance, 123RF.com

Lead Image © citalliance, 123RF.com

A Bash-based monitoring tool

New Top in Town

Article from ADMIN 58/2020
By
In a sea of top-like tools, bashtop impresses with an easy-to-use and efficient interface.

The simple monitoring tool top is often used to monitor individual systems and can be used for debugging. Because it is such a valuable and highly used tool, similar tools have been created to improve upon it. I did a survey article in late 2014 that mentions several top-like tools [1] (some of which have evolved since then and some that have not).

One of the more common top-like tools, htop [2], is a bit more interactive than top, but it provides very similar information. htop uses ncurses for the interface but reads the data from /proc, as top does. It has a nice graph at the top of the default screen that presents the load on each of the cores. htop is also known for its interactivity with processes.

Although htop is one of the most popular top-like tools, as of this writing (May 2020), the main branch hasn't been updated for 16 months. Although not necessarily a bad thing, it is something to be noticed.

Another top-like tool is atop [3]. Like top, the first part of the output is a summary of system statistics and a list of the major processes appears at the bottom. atop breaks out the system, user, and idle time for the system cores. (It would be fun to try this on a 64-core CPU.) The top portion also covers network and disk information.

atop has a few keyboard shortcuts that allow you to dive deeper into various system aspects. For example, pressing the m key allows you to see memory details, d allows you to see more disk (I/O) details, and u allows you to get information on a per-user basis. One very interesting atop feature is that it can show GPU activity on a system and per-process level (see the "GPUs" box.)

GPUs

I wrote the top-like tool review article about six years ago. A lot can happen in six years. In 2014, the top consumer GPUs [4] were the Nvidia GeForce GTX 970 and the AMD Radeon R9 290, and the top data center GPU was the Nvidia K80 [5], which was the last of the Kepler series of GPUs that started in 2012. One could argue that the Kepler series, particularly the K80, was the elbow in GPU computing popularity. Therefore, top-like tools in the original survey article did not really pay attention to monitoring GPUs.

Now, GPUs are much more pervasive, and it seems logical that top tools would be able to monitor them, even though it's not easy to gather statistics because they have different architectures. Given the interest in GPUs, though, the tools should be adapted to monitor them.

As of this writing, the main branch of atop is still under active development, with code updated within the last six days.

A third top-like tool that I've used is vtop [6], which is very unique, in that it has a strip chart at the top of the screen that shows system CPU usage over time. The bottom left of the default screen also shows memory usage in a similar manner. Unfortunately, the main branch of vtop has not been updated for a couple of years.

Fairly recently, a new top-like tool has received quite a bit of attention: bashtop [7], like other top-like tools, shows stats for the processor, memory, disks, network, and processes. Although it might sound like any other top tool, the interface is exceptional.

Bash Monitor

The bashtop resource monitor is written in Bash – quite a bit of Bash. This top-like tool accepts no mouse input. All input is from the keyboard, which I find very easy and efficient. At the top of the screen output (Figure 1), you'll find a plot of the CPU load as a function of time (a strip chart). The green color indicates that the workload is low. As the workload increases, the color switches from yellow to red. Just to the right of the strip chart is a CPU load summary with the CPU type and load for each core.

Figure 1: The bashtop interface.

Just below the strip chart on the left side of the screen, memory usage plots show used, cached, and free memory usage, as well as swap space. To the right of the memory charts is a set of plots for disk usage. Figure 1 shows three disks: root , home_rysnc , and home . For both the memory and disk statistics, the total memory used and the total disk space used are at the top. The disk space is given for each disk in the system. Notice that the charts get brighter as you near the top (or 100 percent) value. Read the values carefully because sometimes nearing 100 percent is a good thing, such as the amount of memory available.

To the right of the memory and disk charts, a list of processes shows the:

  • Pid
  • Program name
  • Arguments
  • Number of threads used in the process
  • User of the process
  • Percentage of Memory
  • Percentage of CPU

Notice how the text gets darker near the bottom of the list, which indicates that bashtop assumes these processes are not as important as the those near the top.

Pressing f creates a filter for the processes. For example, you could enter a specific process name. From the filter, you can then select the specific process you want by pressing the Up and Down arrow keys. When you find the process of interest, pressing Enter brings up information about the process in a new box (sub-box), which shows on the left side a small strip chart of CPU usage – very similar to the CPU chart – with green, yellow, and red colors. On the right side of the sub-box are listed:

  • Status
  • Elapsed time
  • Parent process
  • User
  • Number of threads
  • Memory usage (percentage of memory and actual memory used)
  • CMD (displayed vertically) – the command used to run the process

Pressing f removes the process filter box.

Rather than rely on entering a filter, in the process table, you can highlight a process with the Up and Down arrow keys and press one of three keys (t , k , or i ) to terminate, kill, or interrupt, respectively, the highlighted process.

Finally, on the screen at bottom left is a chart of network usage (shown in blue in Figure 1). A small table of net usage shows both download and upload totals. These charts auto-scale as the network usage changes.

Once you are done with bashtop, you press the q key to quit.

A standard system should have everything installed to run bashtop, which has no other dependencies. However, you might want to pay attention to your version of Bash. If you use lm-sensors, bashtop will display CPU temperatures as well.

If you remember computer games from a number of years ago, you will recognize the game-inspired menus in bashtop that come up when you press the m key (Figure 2).

Figure 2: The main bashtop menu.

Maneuvering to OPTIONS with the arrow keys shows details about the configuration (Figure 3). From here, you can change the color theme, check temperatures (I do not have lm-sensors installed), and change a few other settings. A fairly short YouTube video [8] about bashtop offers more information.

Figure 3: Bashtop OPTIONS menu.

In my humble opinion, bashtop has the most beautiful, usable interface of any top-like tool. Even better, it's written in about 3,400 lines of Bash. The main author is taking some time to rewrite parts of bashtop so that it uses psutil [9], a popular library of simple system monitoring tools, to further reduce the number of lines of code.

These changes do create Python and psutil dependencies, but Python is very commonly installed, and psutil is not very large, so the new code will not drift too far from the simplicity of Bash. Moreover, psutil is cross-platform, so rewriting with psutil can bring bashtop closer to being cross-platform, as well.

Summary

I love the creativeness of these top-like tools. They have taken the basic concepts in top and extended them to create really powerful tools. For a quick glance at what is happening on a system, I run top or maybe htop, but to be honest, bashtop really is much better. I'll be making it a part of my daily admin skills.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Bashtop, a Gorgeous Top-like Tool

    Fairly recently, a new top-like tool has received quite a bit of attention: bashtop, like other top-like tools, shows stats for the processor, memory, disks, network, and processes. Although it might sound like any other top tool, the interface is exceptional.

  • Top Top-Like Tools
    Admins solve problems ranging from slow servers to failing applications. The first tool I reach for when I need to check on a server with shell access is Top.
  • ASCII-based monitoring tools
    If you like ASCII-based monitoring tools, take a look at three new tools – Zenith, Bpytop, and Bottom.
  • New Monitoring Tools

    If you like ASCII-based monitoring tools, take a look at three new tools – Zenith, Bpytop, and Bottom.

  • TUI Tools for Containers

    Text-based user interface tools for a development container.

comments powered by Disqus