tmux-plugins / tmux-cpu Goto Github PK
View Code? Open in Web Editor NEWPlug and play cpu percentage and icon indicator for Tmux.
License: MIT License
Plug and play cpu percentage and icon indicator for Tmux.
License: MIT License
Command to get CPU load on windows is so slow that tmux status bar blink sometimes.
% time ./cpu_percentage.sh
5.0%./cpu_percentage.sh 0.03s user 0.04s system 6% cpu 1.197 total
1.197
seconds against 0.016
with linux command for example.
If a windows expert have better command. I'll be glad.
Hello,
What is #{cpu_icon}
intended for? Does it change shape/color when CPU is loaded for example? Or is it just decorative?
Thanks.
Hello
thanks for this plugin ;)
just to mention on linux the calculation of the mem percent is wrong on linux host:
total used free shared buffers cached
Mem: 32114 29568 2546 680 1017 25988
-/+ buffers/cache: 2561 29552
Swap: 15258 25 15233
in the current calculation you are using only the "Mem" line but you need to use the "-/+ buffers/cache:" line to calculate the "real" memory usage
"free -/+ buffers/cache * 100 / Mem Total"
(in the example above : 29552 * 100 / 32114)
Thanks
Right now I have a config defined as:
CPU: #{cpu_icon}#{cpu_percentage}
which is generating
CPU: = 1.8%
There are two spaces between the symbol and the percentage that are being added by the plugin (Markdown appears to be removing one of the additional spaces). In theory the plugin should be stripping its output and letting the end config define its own padding.
It is possible I am just lacking knowledge about string formatting, but
set -g status-left '#{cpu_fg_color} CPU: #{cpu_percentage}' functions fine, as does
set -g status-left '#{cpu_fg_color} CPU% #{cpu_percentage}'
but:
set -g status-left '#{cpu_fg_color} CPU: #{cpu_percentage} %'
does not function at all. I just want a % sign after the numbers but can't seem to get it to format properly.
Also, set -g status-left '#{cpu_fg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M ' cuts off everything after the decimal place which is why I took out the string formatting options.
The cpu_percentage value on linux does not show the current CPU load, but the overall average CPU load since the computer was started. I guess this is not intentional.
On linux there simply is no easy way (without installing strange extra packages) to get the current CPU load in a range of 0-100%.
The following might be considered as an alternative, but it gives values >100% (due to ps' way of calculating CPU loads):
More exact, but requires bc:
printf "%.0f\n" $(ps -A -o pcpu | tail -n+2 | paste -sd+ | xargs -i echo "(" {} ") / $(nproc)" | bc)
Does the job without bc, in zsh you wouldn't need the sed part:
`echo $(($(ps -A -o pcpu | tail -n+2 | paste -sd+ | sed 's/.[0-9]//g' | xargs -i echo "(" {} ") / $(nproc)")))``
tpm
has new syntax for defining plugins:
set -g @plugin 'tmux-plugins/tmux-cpu'
Wanna update the readme?
Things like nvidia-smi
can take some time to run (up to a few seconds) so we should try to call them only once per update. Right now, using e.g. #{gpu_icon} #{gpu_percentage}
will call nvidia-smi
twice.
Fixing this will also help with #5
Can you add an option to specify a "minimum" CPU percentage below which the CPU percentage variable will just be blank? As it is right now, when my terminal is sitting idle, the CPU percentage is fluctuating around 3-10% which I am not really interested in seeing; it's really only interesting when the CPU is in use. Thanks
Hello,
Recently started to play with tmux, the CPU temperature doesn't show. Here's my config file:
set -g @plugin 'tmux-plugins/tmux-cpu'
set -g status-style bg=default
set-option -g status-right-length 140
set -g status-right 'CPU: #{cpu_percentage} MEM: #{ram_percentage} TMP: #{cpu_temp} | GPU: #{gpu_percentage} MEM: #{gram_percentage} TMP: #{gpu_temp}'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
My CPU is a i9-13900k, is it perhaps too recent to get the readings?
Like below figure, the left side words of cpu percentage are not aligned when cpu percentage's number of digits changes.
Figure: Not aligned left words of cpu percentageI want to align the left side words of cpu percentage not depending on cpu percentage's number of digits.
Hi friends,
I just came across this plugin and I installed it, however it does not appear to show anything. Any ideas what im doing wrong/missing?
Cloned the project and ran ./cpu_percentage.sh
1.0%%
I also did prefix+U - all - enter
tmux.conf
#Reload conf by Ctrl + B, then write :source-file ~/.tmux.conf
#set-option -g default-shell "/bin/bash"
# Status
set -g message-style bg='#181819',fg='#181819'
set -g status-style bg='#181819',fg='#181819'
set -g status-interval 1
#removes number and time
set -g status-left ''
set -g status-right ''
set-window-option -g window-status-style fg='#ffdd33',bg=default
set-window-option -g window-status-current-style fg='#ffdd33',bg='#181819',bold
set -g pane-active-border-style bg=default,fg='#ffdd33'
set -g pane-border-style fg='#ffdd33'
set -g status-justify centre
# Status end
set -g prefix C-b
set -g base-index 1
set-option -g mouse on
set -g set-clipboard on
set -g history-limit 10000
set -g default-terminal "xterm-256color"
set -g terminal-overrides "xterm-256color"
set -ga terminal-overrides ",xterm-256color:Tc"
set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm' # undercurl support
set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m' # underscore colours - needs tmux-3.0
# Keybinds
# Movement and resize vim controls
bind -r C-k resize-pane -U
bind -r C-j resize-pane -D
bind -r C-h resize-pane -L
bind -r C-l resize-pane -R
bind k select-pane -U
bind j select-pane -D
bind h select-pane -L
bind l select-pane -R
# Rebind splits
bind v split-window -h -c '#{pane_current_path}'
bind b split-window -v -c '#{pane_current_path}'
unbind Up
unbind Down
unbind Left
unbind Right
unbind C-Up
unbind C-Down
unbind C-Left
unbind C-Right
# Rebind rename to R
bind-key r command-prompt -I "#W" "rename-window '%%'"
# Plugins
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @plugin 'sainnhe/tmux-net-speed'
set -g @plugin 'sainnhe/tmux-plugin-sysstat'
set -g @plugin 'tmux-plugins/tmux-cpu'
set -g @continuum-restore 'on'
# Tmux package manager
run '~/.tmux/plugins/tpm/tpm'
# {{{tmux-plugin-sysstat
set -g @sysstat_cpu_view_tmpl '#[fg=magenta]C:#[default] #[fg=#{cpu.color}]#{cpu.pused}#[default]'
set -g @sysstat_mem_view_tmpl '#[fg=magenta]M:#[default] #[fg=#{mem.color}]#{mem.pused}#[default]'
set -g status-interval 3
# }}}
# {{{tmux-prefix-highlight
set -g @prefix_highlight_fg 'colour00'
set -g @prefix_highlight_bg 'red'
set -g @prefix_highlight_show_copy_mode 'on'
set -g @prefix_highlight_copy_mode_attr 'fg=colour00,bg=colour05,bold'
set -g @prefix_highlight_prefix_prompt 'PREFIX'
set -g @prefix_highlight_copy_prompt 'COPY'
# }}}
#set -g mouse on
# vim like copy and pate
setw -g mode-keys vi
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
bind P paste-buffer
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel xclip
# This tmux statusbar config was created by tmuxline.vim
# on Wed, 05 May 2021
set -g status-justify "centre"
set -g status "on"
set -g status-left-style "none"
set -g message-command-style "fg=#ffdd33,bg=#181819"
set -g status-right-style "none"
set -g pane-active-border-style bg=default,fg='#ffdd33'
set -g status-style "none,bg=#262626"
set -g message-style "fg=#ffdd33,bg=#181819"
set -g pane-border-style fg='#ffdd33'
set -g status-right-length "100"
set -g status-left-length "100"
setw -g window-status-activity-style "none,fg=#ffdd33,bg=#262626"
setw -g window-status-separator ""
setw -g window-status-style "none,fg=#ffdd33,bg=#262626"
set -g status-left "#[fg=#2c2e34,bg=#ffdd33] #S #[fg=#ffdd33,bg=#181819,nobold,nounderscore,noitalics]#[fg=#ffdd33,bg=#181819] %R #[fg=#181819,bg=#262626,nobold,nounderscore,noitalics]#[fg=#ffdd33,bg=#262626] #{sysstat_mem} #[fg=#ffffff]#{sysstat_ntemp} #[fg=#ffffff]?#{upload_speed} #[fg=#262626,bg=#262626,nobold,nounderscore,noitalics]"
set -g status-right "#[fg=#262626,bg=#262626,nobold,nounderscore,noitalics]#[fg=#ffdd33,bg=#262626]#[fg=#ffffff]#{download_speed} #[fg=#ffffff]#{sysstat_itemp} #{sysstat_cpu} #[fg=#181819,bg=#262626,nobold,nounderscore,noitalics]#[fg=#ffdd33,bg=#181819] %a #[fg=#ffdd33,bg=#181819,nobold,nounderscore,noitalics]#[fg=#2c2e34,bg=#ffdd33] Kay #{prefix_highlight} "
setw -g window-status-format "#[fg=#262626,bg=#262626,nobold,nounderscore,noitalics]#[fg=#ffdd33] #I #W #[fg=#262626,bg=#262626,nobold,nounderscore,noitalics]"
setw -g window-status-current-format "#[fg=#262626,bg=#181819,bold,nounderscore,noitalics]#[fg=#ffdd33,bg=#181819] #I #W #[fg=#181819,bg=#262626,nobold,nounderscore,noitalics]"
set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M '
tmux-cpu/scripts/cpu_temp_fg_color.sh
Lines 11 to 13 in 7228957
And GPU too
tmux-cpu/scripts/gpu_temp_fg_color.sh
Lines 11 to 13 in 7228957
The script fails to parse the iostat output and always returns 100%:
$ iostat -c 1 2 | grep -v % | head -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}' | sed 's/,/./'
100.0%%
$ iostat -V
sysstat version 11.6.0
I'm running Linux, Debian 4.9.65
I'm working around this for the moment by just using the sar command from the script.
@bruno- Can you give me the right to edit repository description and tags please ?
OpenBSD isn't detected and the unknown iostat warning is displayed.
Simply copying FreeBSD's checks and command will work to support OpenBSD 6.0 amd64.
diff --git a/scripts/cpu_percentage.sh b/scripts/cpu_percentage.sh
index e0679fd..366a5d4 100755
--- a/scripts/cpu_percentage.sh
+++ b/scripts/cpu_percentage.sh
@@ -13,6 +13,8 @@ print_cpu_percentage() {
iostat -c 2 disk0 | tail -n 1 | awk '{usage=100-$6} END {printf("%5.1f%%", usage)}'
elif is_freebsd; then
iostat -c 2 | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}'
+ elif is_openbsd; then
+ iostat -c 2 | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}'
else
echo "Unknown iostat version please create an issue"
fi
diff --git a/scripts/helpers.sh b/scripts/helpers.sh
index fce995c..032e802 100644
--- a/scripts/helpers.sh
+++ b/scripts/helpers.sh
@@ -17,6 +17,10 @@ is_freebsd() {
[ $(uname) == "FreeBSD" ]
}
+is_openbsd() {
+ [ $(uname) == "OpenBSD" ]
+}
+
is_linux() {
[ $(uname) == "Linux" ]
}
I'll try to make a pull request if I have some time later on.
it stopped working after i used dracula theme for tmux.
set -g @plugin 'dracula/tmux'
Hi, I share .tmux.conf
across machines and I don't have a GPU on my laptop.
Currently, the text displayed if there is no GPU is: "nvidia-smi/cuda-smi not found", which is quite long and takes away from already quite a small screen.
Would be great if instead it was said something like "No GPU" or "None".
Hi there is no CPU temp for RPI.
I think can be done with:
echo "$(sensors)" | sed -e 's/^temp/Core /' | awk -v format="$cpu_temp_format$cpu_temp_unit" '/^Core [0-9]+/ {gsub("[0-9.]", "", $2); sum+=$3; n+=1 } END {printf(format, sum/n)}'.
and an IF in cpu_temp.sh, for RPI 4b is:
if grep -q "Raspberry" /proc/cpuinfo; then
Output from sensors
:
rpi_volt-isa-0000
Adapter: ISA adapter
in0: N/A
cpu_thermal-virtual-0
Adapter: Virtual device
temp1: +53.6°C (crit = +110.0°C)
gpio_fan-isa-0000
Adapter: ISA adapter
fan1: 0 RPM (min = 0 RPM, max = 5000 RPM)
I can create a pull request.
I am running a Red Hat system with the following details
$ uname -a
Linux xxxxxxxxxxxxx 2.6.32-573.18.1.el6.x86_64 #1 SMP Wed Jan 6 11:20:49 EST 2016 x86_64 x86_64 x86_64 GNU/Linux
The cpu calculated always appears to be static. The cpu percentage is being calculated by the following logic which always returns the same static value.
elif [ -e "/proc/stat" ]; then
grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {printf("%5.1f%", usage)}'
fi
However this code path should not have been followed, this is a linux system with iostat installed. The is_linux_iostat function should have returned a zero return code in helpers.sh. However the iostat command does not appear to work that way.
The current function:
is_linux_iostat() {
iostat -V &> /dev/null
}
On testing
$ is_linux_iostat
$ echo $?
1
$ iostat -V
sysstat version 9.0.4
(C) Sebastien Godard (sysstat <at> orange.fr)
$ echo $?
1
Can we change this function to something like the following?
is_linux_iostat() {
which iostat >/dev/null 2>&1
}
$ is_linux_iostat
$ echo $?
0
I'm not entirely sure however on the need to background the iostat call as per the original solution
I'm using FreeBSD and have more than one disk installed. My iostat output is
tty ada0 ada1 ada2 cpu
tin tout KB/t tps MB/s KB/t tps MB/s KB/t tps MB/s us ni sy in id
0 1692 5.00 5 0.02 0.00 0 0.00 0.00 0 0.00 26 0 2 1 71
Following is correct command to get cpu usage. I guess the command of other platforms may need to fix as well.
iostat -c 2 | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}'
This is a feature request to use cuda-smi to get GPU stats on OSX. Or any other tool for OSX. Thanks!
Hi, I recently updated and CPU percentage is in the wrong format:
I am using ubuntu 19.10 on a dell xps 13 9370
.tmux.config:
set -g status-right 'CPU: #{cpu_percentage} | MEM: #{ram_percentage}| Battery: #{battery_percentage} | %H:%M '
Actual result:
(ram percentage is missing)
Didn't see anything in the "tmux-client-*.log" logs, let me know if I can share any other useful info
is there a way I can define custom colors for both fg and bg at the same time?
All directions were followed for install: iostat
, lm-sensors
, etc. installed on my Debian system. The plugin is working perfectly for all other variables but for some reason:
set -g @cpu_temp_format '%2.0f'
set -g @cpu_temp_units 'F'
-#{gpu_temp} shows "C" scale in status bar.
My .tmux.conf:
set -g @gpu_temp_format '%2.0f'
set -g @gpu_temp_units 'F'
Any suggestions?
I am running macOS Catalina 10.15.5, iTerm2 3.3.11, tmux 3.1b. I also tested it on CentOS 7.7.1908 and found the same behavior. I am assuming it is not installed even though I followed the steps in README and didn't give any errors. I am using tpm
.
I added the specified string in README
set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M '
to my .tmux.conf
. It still only shows the letters and seems to not parse the tags.
So, after installing the plugin I noticed that my status bar was updated too frequently. Apparently, the presence of tmux-cpu influences the update and status-interval
is ignored.
For example, if I set
tmux set -g status-right "%H:%M:%S"
tmux set -g status-interval 5
I can see the seconds updated every 5 seconds. On the other hand, if I add the tmux_cpu plugin:
tmux set -g status-right "%H:%M:%S #(/path/to/plugin/scripts/cpu_percentage.sh)"
tmux set -g status-interval 5
I will see the seconds and the CPU percentage updated almost every second, disregarding the value of status-interval. I think status-interval should be taken into account, and I see this behaviour as buggy.
I can help with the debug, but not being familiar with tmux-plugins in any way I don't know where to start.
I found that the CPU percentage for Linux seems to be the average CPU percentage since boot. As a result, it can hardly reflect current percentage if the machine has been up for long time.
Both for CPU and GPU
Thanks for this awesome plugin! One idea - it would be neat if you could prefix single digit CPU usage percentages with a zero - e.g. 05%
. Currently, when my computer hovers between single-digit and double-digit percentage usages (e.g. 9% to 10%), the width of the status bar changes constantly, which is slightly distracting. Prefixing single-digit percentage usages with a zero would prevent this.
The problem appears to be in
iostat -c 2 | tail -n 1 | tr -s ' ' ';' | cut -d ';' -f 7 | awk '{usage=100-$1} END {printf("%5.1f%%", usage)}'
This always returns 100%
in my case even though looking at the activity monitor there's nothing eating this much CPU, I'm not even consuming a whole core.
Hi,
I try to use @cpu_percentage_format
. The little annoying thing is seeing percentage position moving back and forth, for example, from 8% to 10%, then 10 to 8. I'd like to have 08%
or [space]8%
instead of 8%
so that I no longer see the percentage position moving back and forth on the right side of the status bar.
Sometimes I can see memory usage like this:
It stays like this for a short period of time (probably the update period) and then shows correctly:
That leads me to another issue - you can see how MEM is green, is there a way to reset the text color back to default?
I use Ubuntu 20.04 on WSL2. Tmux version is 3.0a. The relevant config section is:
set-option -g status-left-length 20
set-option -g status-left "#S | "
set-option -g status-left-style fg=#aaaaaa,bg=#050505
set-option -g status-style fg=#aaaaaa,bg=#050505
set-option -g status-right 'CPU: #{cpu_fg_color}#{cpu_percentage} MEM: #{ram_fg_color}#{ram_percentage}'
set-option -g status-right-style fg=#aaaaaa,bg=#050505
Hey guys,
I am using macOS Monterey on a Macbook pro 13" chip apple M1.
.tmux.config:
set -g status-right '#{battery_status_bg} #{battery_icon}#{battery_percentage} | #{cpu_icon} #{cpu_percentage} | %a %h %d %H:%M'
Actual result:
I tried to clone the repository and run scripts/cpu_percentage.sh
=> it works well.
I tried to put ram_percentage instead and looks fine also.
Just moved to use M1 today so I think am using the latest version for anything (tmux, tpm, tmux-cpu), and not sure it works or not with chip intel.
TIA for your time!
How i can solve this problem?
AMD Ryzen 1600X sensors doesn't have a per core readout so the sed/awk script fails:
$ sensors
k10temp-pci-00c3
Adapter: PCI adapter
Tctl: +56.6°C
Tdie: +36.6°C
Add a variable/option to use the Tdie
readout instead.
In my case sensors | sed -n 's/Tdie:\s*+//p'
is enough.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.