Real-Time GPU Monitoring on Polybar Using Bash + NVIDIA-SMI


🚀 Introduction
As part of optimizing my Linux development environment, I recently implemented a lightweight GPU monitoring widget using Polybar and a custom Bash script. This setup fetches real-time GPU utilization and temperature using nvidia-smi
, integrates it seamlessly into Polybar, and refreshes at a short interval all without relying on bulky third-party tools.
The goal? Clean visibility into GPU performance, directly from my desktop bar, with zero overhead.
🔧 Stack & Tools
Tool | Purpose |
nvidia-smi | Query GPU stats (utilization, temp, etc.) |
bash | Shell scripting logic |
Polybar | Display widget in my Linux bar |
lm-sensors | (Optional) for extended thermal data |
This kind of setup is ideal if you're running a custom lightweight window manager (like Openbox or bspwm), and want telemetry that aligns with the rest of your minimalist workflow.
💻 Bash Script
Here’s the core script I wrote:
bashCopyEdit#!/bin/bash
TEMP=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits)
UTIL=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits)
echo "GPU: ${UTIL}% | Temp: ${TEMP}°C"
You can drop this in ~/.config/polybar/scripts/gpu.sh
and make it executable:
bashCopyEditchmod +x ~/.config/polybar/scripts/gpu.sh
This leverages nvidia-smi
's CLI output directly to avoid additional dependencies and overhead.
🧩 Integrating with Polybar
Add this module to your ~/.config/polybar/config.ini
:
iniCopyEdit[module/gpu]
type = custom/script
exec = ~/.config/polybar/scripts/gpu.sh
interval = 2
label = %output%
And then include it in your active bar setup:
iniCopyEditmodules-right = gpu ...
This ensures your GPU stats are updated every 2 seconds in real-time - no lag, no noise.
🖼️ Final Output
You’ll see clean stats like this on your bar:
yamlCopyEditGPU: 12% | Temp: 49°C
It’s functional, non-intrusive, and blends well into any custom theme.
Bonus: You can extend this with icons, conditional coloring, or integration into a dotfiles repo for portability.
🧠 Why I Did This
Minimal setups deserve minimal tools.
I prefer scriptable, version-controlled configurations over GUIs.
This is part of a larger push: building a fully automated, dev-optimized Linux system from the ground up.
🔮 What’s Next
This was step one. I’m currently:
Writing shell scripts to automate full dev machine provisioning
Extending Polybar to show CPU, RAM, and battery metrics
Exploring integrations with systemd timers and cron for power-aware switching
Designing a Linux distro tailored for developers, with smart GPU/battery management and LLM-aware optimization baked in
💬 Final Thoughts
If you're building your own Linux stack - start here.
Don’t install 10 apps to monitor your machine. Just write 10 lines of code.
If this helped or inspired you, connect on LinkedIn.
Subscribe to my newsletter
Read articles from Parag Ghatage directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Parag Ghatage
Parag Ghatage
Hey! I’m Parag , a full-stack developer, open-source contributor, and GSoC 2025 intern with AOSSIE. I’m passionate about building smarter, faster dev environments - from scripting custom Linux workflows to automating ML pipelines. Currently exploring the intersection of ML, system-level scripting, and web development. I love customizing my tools, my OS, and sometimes even my problems. GSoC '25 | Archcraft Power User | Building AI-ready dev setups | Web Dev meets Shell Wizardry Let’s connect - I love geeking out over Linux, open-source tools, and unconventional ideas.