Skip to content

Commit 7d86ab5

Browse files
committedJul 13, 2019
tmux: kludge a fix to erroneous cpu numbers in statusbar
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).
1 parent d0e732b commit 7d86ab5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
* include a ssh/config broken into a common fragment and (when needed)
77
per-machine fragments glued together using Include and a config.d dir
8+
* problem: how to condition on origin machine hostname?

‎tmux/.tmux.conf

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ bind C-z send-prefix
44
bind z last-window
55
bind r source-file ~/.tmux.conf
66

7+
# absurd way to run a 'stats daemon' which is then used by the status line
8+
new-window -d -a -t 99 -n vmstat 'echo dm1zdGF0IC1TIG0gMSB8IHRlZSAvZGV2L3N0ZGVyciB8IGdyZXAgLVAgJ15bMC05WzpzcGFjZTpdXSskJyAtLWxpbmUtYnVmZmVyZWQgfCBhd2sgJ3twcmludCAxMDAtJDE1OyBmZmx1c2goKX0nIHwgKHdoaWxlIHJlYWQgRiA7IGRvIGVjaG8gIiRGIiA+ICRYREdfUlVOVElNRV9ESVIvY3B1IDsgZG9uZSkK | base64 -d | zsh'
9+
710
set-option -g status-style "fg=cyan,bg=black"
811
set-option -g window-status-current-style "fg=cyan,bold,bg=blue"
9-
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')"
12+
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')"
1013
set-option -g status-interval 10

0 commit comments

Comments
 (0)
Failed to load comments.