BTop Resource Monitor

Published: Jun 29, 2023 by Isaac Johnson

I recently found out about BTOP++ from a post on Lemmy. At its core, it is a command line resource monitor for cpu, memory, storage and more.

However, the part of me that is a sucker for any slick looking retro 8-bit game on steam saw the screenshots and knew I had to give it a whirl.

We’ll set this up in WSL, Linux, then create an Ansible Playbook to automate installation. We’ll tour many of the features (lots of videos in this post) and lastly watch as we respin a k3s cluster while monitoring nodes in BTop.

Installation

We’ll start with WSL on Windows.

We can easily install with homebrew for linux:

$ brew install btop
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 3 taps (codefresh-io/cli, homebrew/core and homebrew/cask).
==> New Formulae
ansible@7             core-lightning        gotestsum             judy                  mariadb@10.11         shub                  votca
argparse              ddns-go               grpc@1.54             libecpint             minigraph             shush                 wzprof
aws-amplify           fastgron              grype                 libint                nexttrace             slsa-verifier         xbyak
bashate               getmail6              hivex                 libomemo-c            openfga               spotify_player        zrok
cargo-generate        gffread               joshuto               libpaho-mqtt          ord                   swift-outdated
charls                git-credential-oauth  jsign                 lowdown               procps@3              tern
conda-lock            git-tools             jsmn                  ls-lint               protobuf@21           typical
==> New Casks
apple-hewlett-packard-printer-drivers              eset-cyber-security                                mumu-x
audiocupcake                                       frappe-books                                       rio
command-x                                          graalvm-jdk                                        rode-connect
copilot                                            grs-bluewallet                                     yealink-meeting
devpod                                             loupedeck
engine-dj                                          motu-m-series

You have 34 outdated formulae installed.

==> Fetching dependencies for btop: linux-headers@5.15
==> Fetching linux-headers@5.15
==> Downloading https://ghcr.io/v2/homebrew/core/linux-headers/5.15/manifests/5.15.118
################################################################################################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/linux-headers/5.15/blobs/sha256:0761b242bd3838861b85d96df1b8c12332bc953035e2a658b28c291489c76506
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:0761b242bd3838861b85d96df1b8c12332bc953035e2a658b28c291489c76506?se=
################################################################################################################################################## 100.0%
==> Fetching btop
==> Downloading https://ghcr.io/v2/homebrew/core/btop/manifests/1.2.13
################################################################################################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/btop/blobs/sha256:af5c08bf52c9d84b54b3fe3992240a50c048ff3b897e8ee13f428fac4db76e0f
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:af5c08bf52c9d84b54b3fe3992240a50c048ff3b897e8ee13f428fac4db76e0f?se=
################################################################################################################################################## 100.0%
==> Installing dependencies for btop: linux-headers@5.15
==> Installing btop dependency: linux-headers@5.15
==> Pouring linux-headers@5.15--5.15.118.x86_64_linux.bottle.tar.gz
🍺  /home/linuxbrew/.linuxbrew/Cellar/linux-headers@5.15/5.15.118: 961 files, 5.7MB
==> Installing btop
==> Pouring btop--1.2.13.x86_64_linux.bottle.tar.gz

... snip ...

Removing: /home/builder/.cache/Homebrew/Logs/fontconfig... (7.8KB)
Removing: /home/builder/.cache/Homebrew/Logs/python@3.10... (2 files, 5.8KB)
Removing: /home/builder/.cache/Homebrew/Logs/python@3.11... (2 files, 5.8KB)
Pruned 0 symbolic links and 4 directories from /home/linuxbrew/.linuxbrew

Usage

I can now fire up btop to see a nice Overview of my machine. I liked how it even managed to track all 16 cores in the small window

/content/images/2023/06/btop-01.png

We can click around the processes and you’ll see it changes highlights. I can press letters (like “s” for signal) to bring up a signal page

We can expand some areas by hiding others.. the little icons are shown, but they might be hard to read (are for me). 1 = CPU, 2 = Memory, 3 = Net and 4 = Process box…

Here is me scrolling through each (twice)

The size of your window affects the layout. Here I’ll expand the whole screen a bit

/content/images/2023/06/btop-04.png

And here it is in a much smaller space

/content/images/2023/06/btop-05.png

Filters

We can use the filter to find specific processes. Perhaps I want to find all the node processes running. I’ll press “f” and type in Node

Configuration

We can tweak setting under menu

/content/images/2023/06/btop-07.png

We can turn off the black background (in WSL that would have no affect)

/content/images/2023/06/btop-08.png

We can change the graphing to use block instead of dots, which has a very different look

/content/images/2023/06/btop-09.png

As we can see

/content/images/2023/06/btop-10.png

There are quite a few pre-baked themes. I like bright colours, so I might use the “whiteout” theme

/content/images/2023/06/btop-11.png

“Nightowl” shows a subtle dark blue (instead of black)

/content/images/2023/06/btop-12.png

Though there is something subtly nice about “everforest-dark-hard”

/content/images/2023/06/btop-13.png

I decided I would just scroll a bit through the 20+ themes:

I also wanted to show the fastest it can update, 100ms which shows a very slick real time graph

Ubuntu Terminal

Let’s move from WSL (which in truth was Ubuntu) to a remote host on SSH.

We’ll follow the make installation instructions

I’ll install the required libraries with apt

$ sudo apt update
$ sudo apt install coreutils sed git build-essential gcc-11 g++-11
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package gcc-11
E: Unable to locate package g++-11

$ sudo apt install coreutils sed git build-essential gcc-10 g++-10
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 3778732 (unattended-upgr)
Reading package lists... Done
Building dependency tree
Reading state information... Done
coreutils is already the newest version
... snip ...
Get:9 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Hit:10 http://ppa.launchpad.net/rmescandon/yq/ubuntu focal InRelease
Get:11 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,649 kB]
Get:12 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [275 kB]
Get:13 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1,074 kB]
Get:14 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [410 kB]
Get:15 http://us.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B]
Get:16 http://us.archive.ubuntu.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [8,012 B]
Get:17 http://us.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.5 kB]
Get:18 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [60.0 kB]
Get:19 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [95.7 kB]
Get:20 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [940 B]
Fetched 4,945 kB in 2s (2,109 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
90 packages can be upgraded. Run 'apt list --upgradable' to see them.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://repo.zabbix.com/zabbix/6.0/ubuntu focal InRelease' doesn't support architecture 'i386'
builder@anna-MacBookAir:~$ sudo apt install coreutils sed git build-essential gcc-11 g++-11
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package gcc-11
E: Unable to locate package g++-11
builder@anna-MacBookAir:~$ sudo apt install coreutils sed git build-essential gcc-10 g++-10
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 3778732 (unattended-upgr)
Reading package lists... Done
Building dependency tree
Reading state information... Done
coreutils is already the newest version (8.30-3ubuntu2).
coreutils set to manually installed.
sed is already the newest version (4.7-1).
sed set to manually installed.
build-essential is already the newest version (12.8ubuntu1.1).
build-essential set to manually installed.
git is already the newest version (1:2.25.1-1ubuntu3.11).
The following packages were automatically installed and are no longer required:
  libfprint-2-tod1 libfwupdplugin1 libllvm10 libllvm11 shim
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  gcc-10-locales g++-10-multilib gcc-10-doc gcc-10-multilib libstdc++-10-doc
The following NEW packages will be installed:
  cpp-10 g++-10 gcc-10 libasan6 libgcc-10-dev libstdc++-10-dev
0 upgraded, 6 newly installed, 0 to remove and 90 not upgraded.
Need to get 42.1 MB of archives.
After this operation, 151 MB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 cpp-10 amd64 10.3.0-1ubuntu1~20.04 [8,610 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libasan6 amd64 10.3.0-1ubuntu1~20.04 [2,062 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 libgcc-10-dev amd64 10.3.0-1ubuntu1~20.04 [2,342 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 gcc-10 amd64 10.3.0-1ubuntu1~20.04 [17.5 MB]
Get:5 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 libstdc++-10-dev amd64 10.3.0-1ubuntu1~20.04 [1,759 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu focal-updates/universe amd64 g++-10 amd64 10.3.0-1ubuntu1~20.04 [9,803 kB]
Fetched 42.1 MB in 1s (31.6 MB/s)
Selecting previously unselected package cpp-10.
(Reading database ... 370633 files and directories currently installed.)
Preparing to unpack .../0-cpp-10_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking cpp-10 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libasan6:amd64.
Preparing to unpack .../1-libasan6_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libasan6:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libgcc-10-dev:amd64.
Preparing to unpack .../2-libgcc-10-dev_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libgcc-10-dev:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package gcc-10.
Preparing to unpack .../3-gcc-10_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking gcc-10 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package libstdc++-10-dev:amd64.
Preparing to unpack .../4-libstdc++-10-dev_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking libstdc++-10-dev:amd64 (10.3.0-1ubuntu1~20.04) ...
Selecting previously unselected package g++-10.
Preparing to unpack .../5-g++-10_10.3.0-1ubuntu1~20.04_amd64.deb ...
Unpacking g++-10 (10.3.0-1ubuntu1~20.04) ...

...snip...

By default, make will use an older GCC on Ubuntu

builder@anna-MacBookAir:~/tmp/btop$ make QUIET=true
Makefile:78: *** ERROR: Compiler too old. (Requires Clang 16.0.0, GCC 10.1.0).  Stop.

You’ll want to specify the GCC we installed above (10 or 11) as a parameter with “CXX”

builder@anna-MacBookAir:~/tmp/btop$ make QUIET=true CXX=g++-10

Building btop++ (v1.2.13) Linux x86_64
10%  -> obj/btop_config.o             (1.5MiB) (11s)
20%  -> obj/btop_input.o              (1.4MiB) (11s)
40%  -> obj/btop.o                    (2.7MiB) (15s)
40%  -> obj/btop_draw.o               (2.3MiB) (15s)
50%  -> obj/btop_menu.o               (2.0MiB) (16s)
60%  -> obj/btop_shared.o             (1.7MiB) (17s)
70%  -> obj/btop_theme.o              (1.4MiB) (13s)
80%  -> obj/btop_tools.o              (1.4MiB) (16s)
90%  -> obj/linux/btop_collect.o      (2.9MiB) (13s)
100% -> bin/btop                      (1.6MiB) (29s)

Build complete in (01m:11s)

Now we can make install

builder@anna-MacBookAir:~/tmp/btop$ sudo make install CXX=g++-10
Installing binary to: /usr/local/bin/btop
Installing doc to: /usr/local/share/btop
Installing themes to: /usr/local/share/btop/themes
Installing desktop entry to: /usr/local/share/applications/btop.desktop
Installing PNG icon to: /usr/local/share/icons/hicolor/48x48/apps/btop.png
Installing SVG icon to: /usr/local/share/icons/hicolor/scalable/apps/btop.svg

I can now launch btop fully remotely

/content/images/2023/06/btop-16.png

This means I could, for instance, search for fluentbit on the host

/content/images/2023/06/btop-17.png

and press k to kill

/content/images/2023/06/btop-18.png

Ansible

If I do something once, fine, even twice I’ll use bash.

But this is a slick tool so it gets its own Ansible Playbook

---
- name: Install BTop
  hosts: all

  tasks:
  - name: Update apt
    ansible.builtin.shell: |
      apt-get update
    become: true
    args:
      chdir: /tmp

  - name: Install Dependencies
    ansible.builtin.shell: |
      apt-get install -y coreutils sed git build-essential gcc-10 g++-10
    become: true
    args:
      chdir: /tmp

  - name: Download btop
    ansible.builtin.shell: |
      # Clean if needed
      rm -rf /tmp/btop || true
      rmdir /tmp/btop || true

      # Clone
      git clone --recursive https://github.com/aristocratos/btop.git /tmp/btop
    become: true
    args:
      chdir: /tmp

  - name: Make
    ansible.builtin.shell: |
      make QUIET=true CXX=g++-10
    become: true
    args:
      chdir: /tmp/btop

  - name: Make
    ansible.builtin.shell: |
      umask 0002
      make QUIET=true CXX=g++-10
    become: true
    args:
      chdir: /tmp/btop

  - name: Make Install
    ansible.builtin.shell: |
      umask 0002
      make install CXX=g++-10
    become: true
    args:
      chdir: /tmp/btop

  - name: Test
    ansible.builtin.shell: |
      btop --version
    become: true
    args:
      chdir: /tmp/btop

(I put it here if you want to download the latest)

I’ll then add as a template in the inventory

/content/images/2023/06/btop-19.png

I can then launch it

/content/images/2023/06/btop-20.png

I’ll fire it off

/content/images/2023/06/btop-21.png

And, for the first time in a while, it worked the first time (no typos on my part)

/content/images/2023/06/btop-23.png

I can check the node and see it is installed

builder@DESKTOP-QADGF36:~/Workspaces/ansible-playbooks$ kubectx mac81
Switched to context "mac81".
builder@DESKTOP-QADGF36:~/Workspaces/ansible-playbooks$ kubectl get nodes
NAME                  STATUS   ROLES                  AGE   VERSION
anna-macbookair       Ready    control-plane,master   25d   v1.27.1+k3s1
isaac-macbookpro      Ready    <none>                 25d   v1.27.1+k3s1
builder-macbookpro2   Ready    <none>                 25d   v1.27.1+k3s1
builder@DESKTOP-QADGF36:~/Workspaces/ansible-playbooks$ kubectl describe node builder-macbookpro2 | grep 192
                    flannel.alpha.coreos.com/public-ip: 192.168.1.159
                    k3s.io/internal-ip: 192.168.1.159
  InternalIP:  192.168.1.159
builder@DESKTOP-QADGF36:~/Workspaces/ansible-playbooks$ ssh builder@192.168.1.159
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.15.0-71-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

86 updates can be applied immediately.
To see these additional updates run: apt list --upgradable

New release '22.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Your Hardware Enablement Stack (HWE) is supported until April 2025.
*** System restart required ***
Last login: Mon Jun 26 07:16:23 2023 from 192.168.1.215
builder@builder-MacBookPro2:~$ which btop
/usr/local/bin/btop

This is a very old host so let’s see how the little fella is doing

/content/images/2023/06/btop-24.png

Now I’ll have some fun. This cluster needs a respin. It’s got a ridiculous number of log monitors on it and they are filling up my NAS unnecessarily.

Let’s watch things as I scrub it with a reload

Windows

Someone did port Btop to windows.

We’ll need to use scoop as there isn’t a choco package for it.

We’ll use a non-Admin powershell window

PS C:\Users\isaac> irm get.scoop.sh | iex
Initializing...
Downloading ...
Creating shim...
Adding ~\scoop\shims to your path.
Scoop was installed successfully!
Type 'scoop help' for instructions.
PS C:\Users\isaac>

Now we can install

PS C:\Users\isaac> scoop install btop
Installing 'btop' (1.0.4) [64bit] from main bucket
btop4win-x64.zip (963.6 KB) [=================================================================================] 100%
Checking hash of btop4win-x64.zip ... ok.
Extracting btop4win-x64.zip ... done.
Running pre_install script...
Linking ~\scoop\apps\btop\current => ~\scoop\apps\btop\1.0.4
Creating shim for 'btop'.
Persisting themes
Persisting btop.conf
'btop' (1.0.4) was installed successfully!
'btop' suggests installing 'extras/vcredist2022'.

You can see from the Processes and window decoration, this is running on Windows, not WSL

/content/images/2023/06/btop-22.png

Summary

BTop and BTop4win are awesome little monitors. From the releases it would appear its been around since Sept 2021. Since it’s Open Source, I would expect it to keep growing.

I liked it enough to buy the person a coffee which I think is a great model for small Open Source software like this.

BTop Monitoring

Have something to add? Feedback? Try our new forums

Isaac Johnson

Isaac Johnson

Cloud Solutions Architect

Isaac is a CSA and DevOps engineer who focuses on cloud migrations and devops processes. He also is a dad to three wonderful daughters (hence the references to Princess King sprinkled throughout the blog).

Theme built by C.S. Rhymes