Skip to content

Displays CPU and memory usage in the Tmux status bar using customizable placeholders.

License

Notifications You must be signed in to change notification settings

hendrikmi/tmux-cpu-mem-monitor

Repository files navigation

Tmux CPU & Memory Monitor

A simple yet flexible tool designed to display CPU and memory usage in the Tmux status bar.

Installation

  1. 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'
  2. Then trigger the installation with Prefix + I.

Basic Usage

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.

Options

#{cpu} Placeholder

  • -i <num>, --interval <num> (default 1):
    • 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.

#{mem} Placeholder

  • -t, --total: Display memory usage as used/total in GB instead of a percentage.

#{disk} Placeholder

  • -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.

Examples

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}"

Why Another Plugin?

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:

  1. Predefined Styling: Many of the plugins I found came with predefined styling that didn't quite match what I was looking for.

  2. Missing Metrics: Either CPU or memory metrics were missing.

  3. 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.

Why Python?

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 with psutil 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 of psutil 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.

About

Displays CPU and memory usage in the Tmux status bar using customizable placeholders.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published