tmux-plugins / tmux-cpu

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

iostat output parsing is wrong for sysstat version 11.6.0 on Linux #21

Closed garymm closed 6 years ago

garymm commented 6 years ago

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.

ctjhoa commented 6 years ago

Can you describe your pc configuration? How many cores do you have on your cpu?

ctjhoa commented 6 years ago

Can you also give me the output of iostat - c 1 2?

garymm commented 6 years ago
$ iostat -c 1 2
Linux 4.9.0-5-amd64 (<hostname>)    01/10/2018  _x86_64_    (12 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.64    0.10    0.43    0.03    0.00   98.81

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.42    0.00    1.08    0.08    0.00   98.42

As the output shows, the machine has 12 CPU cores.

ctjhoa commented 6 years ago

Ok I reproduce the issue I will try to work on it

ctjhoa commented 6 years ago

OK so I reproduce your behavior with

$ iostat -c 1 2 | grep -v % | head -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}' | sed 's/,/./'

but this is not the command used in cpu_percentage.sh

iostat -c 1 2 | tail -n 2 | head -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}' | sed 's/,/./'
ctjhoa commented 6 years ago

Are you sure to have the latest version of tmux-cpu ?

garymm commented 6 years ago

Not sure exactly how to check what version I have, but I did run <prefix> + I and git status:

$ cd .tmux/plugins/tmux-cpu
$ git status
On branch master
Your branch is up to date with 'origin/master'.

The command in cpu_percentage.sh that I see both locally and in github is the same:

iostat -c 1 2 | tail -n 2 | head -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}' | sed 's/,/./'

And it always returns 100%%

Note the command we're looking at is under the is_linux_iostat branch.

ctjhoa commented 6 years ago

Do you have better result with

$ iostat -c 1 2 | sed '/^\s*$/d' | tail -n 1 | awk '{usage=100-$NF} END {printf("%5.1f%%", usage)}' | sed 's/,/./'

? Can you also give me your iostat version? Thanks

garymm commented 6 years ago

Do you have better result with

Yes, that seems to work.

Can you also give me your iostat version?

See first comment (11.6.0)

ctjhoa commented 6 years ago

@ricelid I have update master accordingly. Thanks for the report