Skip to content

Commit

Permalink
tmux: kludge a fix to erroneous cpu numbers in statusbar
Browse files Browse the repository at this point in the history
previously we invoked vmstat and parsed its output to report on
supposedly 'recent' CPU consumption.  however, as invoked, vmstat
outputs cumulative-since-boot CPU numbers, as that's all the kernel
interface supplies.  having vmstat wait a few seconds to report
last-few-seconds numbers is possible, but is not recommended
(see tmux/tmux#797 (comment) )
and results in status line updates at rapid and irregular intervals
(see tmux-plugins/tmux-cpu#15 ).  this is
distracting, and also makes tmux create high load on an ancient raspi.

so instead, we kludge using tmux as a sort of background job manager,
launching vmstat on a high-numbered window and parsing its output
into a file underneath our systemd-created session tmpfs, from which
the tmux status line reads it.

vmstat is used over iostat/mpstat/etc as it should be always available
(at least on Debian systems where procps is Priority: important).
  • Loading branch information
cdanis committed Jul 13, 2019
1 parent d0e732b commit 7d86ab5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

* include a ssh/config broken into a common fragment and (when needed)
per-machine fragments glued together using Include and a config.d dir
* problem: how to condition on origin machine hostname?
5 changes: 4 additions & 1 deletion tmux/.tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ bind C-z send-prefix
bind z last-window
bind r source-file ~/.tmux.conf

# absurd way to run a 'stats daemon' which is then used by the status line
new-window -d -a -t 99 -n vmstat 'echo dm1zdGF0IC1TIG0gMSB8IHRlZSAvZGV2L3N0ZGVyciB8IGdyZXAgLVAgJ15bMC05WzpzcGFjZTpdXSskJyAtLWxpbmUtYnVmZmVyZWQgfCBhd2sgJ3twcmludCAxMDAtJDE1OyBmZmx1c2goKX0nIHwgKHdoaWxlIHJlYWQgRiA7IGRvIGVjaG8gIiRGIiA+ICRYREdfUlVOVElNRV9ESVIvY3B1IDsgZG9uZSkK | base64 -d | zsh'

set-option -g status-style "fg=cyan,bg=black"
set-option -g window-status-current-style "fg=cyan,bold,bg=blue"
set-option -g status-right "#(vmstat | tail -n1 | awk '{print 100-$15}')%%cpu #(free | grep Mem | awk '{printf \"%%.0f\", $4/$2*100}')%%mem #H #(date -u '+%%H:%%M %%Z')"
set-option -g status-right "#(cat $XDG_RUNTIME_DIR/cpu)%%cpu #(free | grep Mem | awk '{printf \"%%.0f\", $4/$2*100}')%%mem #H #(date -u '+%%H:%%M %%Z')"
set-option -g status-interval 10

0 comments on commit 7d86ab5

Please sign in to comment.