tmux-plugins / tmux-cpu

Plug and play cpu percentage and icon indicator for Tmux.
MIT License
426 stars 65 forks source link

Force number of devices to 1 so as not to break the awk script. #2

Closed lglenn closed 9 years ago

lglenn commented 9 years ago

Sorry, I missed a not-so-edge case!

The awk snippet that grabs the cpu stats assumes that iostat's only reporting on one disk, like this:

          disk0       cpu     load average
    KB/t tps  MB/s  us sy id   1m   5m   15m
   33.00   8  0.26   6  7 87  1.46 1.49 1.57
    8.96  38  0.33   2  5 92  1.46 1.49 1.57

...and that idle cpu % will be in column 6.

If there's more than one disk, though, the cpu stats will wind up in the "wrong" column...

          disk0           disk2       cpu     load average
    KB/t tps  MB/s     KB/t tps  MB/s  us sy id   1m   5m   15m
   32.99   8  0.26   151.00   0  0.00   6  7 87  1.48 1.50 1.57
    0.00   0  0.00     0.00   0  0.00   3  5 92  1.48 1.50 1.57

This change calls iostat with -n 1, which forces it to report on only one disk.

ctjhoa commented 9 years ago

Nice ! Thanks @lglenn !

lglenn commented 9 years ago

Thank you!