tmux-plugins / tmux-cpu

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

Incorrect detection For Linux Iostat #10

Closed pbowditch closed 8 years ago

pbowditch commented 8 years ago

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

ctjhoa commented 8 years ago

Hi,

Unfortunately, I cannot use this:

is_linux_iostat() {
    which iostat >/dev/null 2>&1
}

because iostat exist for both BSD and Linux but option and result are very different. I will install a redhat VM tonight and do some tests. I'll keep you in touch.

ctjhoa commented 8 years ago

@pbowditch This is a bug from early versions of linux iostat. I use another detection technique. Let me know if you're encounter trouble again.