A simple yet flexible tool designed to display CPU and memory usage in the Tmux status bar.
-
Install it with the Tmux Plugin Manager (TPM) by including the following line in your
.tmux.conf
file.set -g @plugin 'hendrikmi/tmux-cpu-mem-monitor'
-
Then trigger the installation with
Prefix + I
.
Once installed, the plugin exposes the placeholders #{cpu}
and #{mem}
, which can be used in status-right
and status-left
. By default, these placeholders display the current CPU and memory usage as a raw percentage.
You can customize the display by passing additional options. For example, #{mem --total}
will display memory usage as used/total in GB.
-i <num>, --interval <num>
(default1
):0
: Compares system CPU times elapsed since last call (non-blocking).>0
: Compares system CPU times (seconds) elapsed before and after the interval (blocking).
--precpu
: Shows the utilization as a percentage for each CPU.
For more details, see the documentation of the underlying psutil library.
-t, --total
: Display memory usage as used/total in GB instead of a percentage.
-p <path>, --path <path>
: Specify the path to monitor. Defaults:C:
for Windows,/System/Volumes/Data
for Mac, and/
for Linux.-t, --total
: Display disk usage as used/total in GB instead of a percentage.-f, --free
: Display free disk space in GB.
set -g status-right "#{cpu} | #{mem} | #{disk}"
set -g status-right " CPU: #{cpu} | MEM: #{mem -t} | DISK: #{disk -t}"
set -g status-right " CPU: #{cpu -i 3} | MEM: #{mem} | DISK: #{disk -f}"
This plugin was created as a personal project to learn more about Tmux plugins and Python scripting. While exploring existing plugins that display CPU and memory usage, I noticed a few limitations that sparked my interest in building something exactly how I wanted it:
-
Predefined Styling: Many of the plugins I found came with predefined styling that didn't quite match what I was looking for.
-
Missing Metrics: Either CPU or memory metrics were missing.
-
Lack of Configurability: I found that other plugins often didn't offer the level of configurability I wanted. For example, I wanted to add icons to the display.
Overall, I prefer a minimalist approach, where I can simply use placeholders like #{cpu}
and #{mem}
with full flexibility to choose how they're presented.
I chose to write this plugin in Python instead of Shell as part of my learning journey, and because of several practical reasons:
-
Powerful Libraries: Python’s psutil library provides a wide range of system and process utilities that are easy to use. For example, displaying CPU usage per core (
--precpu
) is much simpler withpsutil
compared to implementing it in a shell script. -
Ease of Adaptation: Working with Python makes it easier for me to adapt and add functionalities.
-
Simplified Argument Parsing: Python's built-in
argparse
module makes it straightforward to handle command-line arguments, allowing me to easily add and manage options like--interval
and--total
. Additional features ofpsutil
can be easily adapted. -
Cross-Platform Compatibility: Python with
psutil
, offers a consistent way to gather system metrics across different operating systems, which avoids dealing with the quirks of different shell environments.