Closed jolbax closed 6 years ago
Same thing with me. It looks like it's missing stdbuf
... this answer helped me out a bit: https://apple.stackexchange.com/questions/193141/to-use-stdbuf-from-homebrews-coreutils
I had to install coreutils from brew, and then add /usr/local/opt/coreutils/libexec/gnubin before /usr/bin in the path, as noted in the "Caveats" output after running 'brew install coreutils':
export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH
That helped get it working for me; this helped too: https://apple.stackexchange.com/questions/193141/to-use-stdbuf-from-homebrews-coreutils
@dubaaron Thanks for your tip. I actually have done this all.
While checking the whole configuration of stdbuf
I realised that the update of the CPU state is working but not as expected.
I can see sometimes the current CPU load on TMUX but it does not update. It keeps showing me the same value for hours.. and suddenly it changes again updating it with a new value and behaving in the same way.
Not sure if read -r value
the problem is...
Here's the problem and solution.
Problem: Some systems have more than one disk device and all are displayed in the iostat output, e.g.:
≻ iostat -c 2 -w 5
disk0 disk2 disk3 cpu load average
KB/t tps MB/s KB/t tps MB/s KB/t tps MB/s us sy id 1m 5m 15m
24.83 27 0.64 245.89 0 0.00 240.41 0 0.00 13 15 72 2.09 2.65 2.61
0.00 0 0.00 0.00 0 0.00 0.00 0 0.00 12 14 74 2.01 2.62 2.60
The script is expecting that the output has a single device followed by the cpu stats and expects the cpu idle % to be the 6th number. To solve this, modify the iostat command to display NO devices with -n 0
so the idle cpu % will always be the 3rd number in the output:
≻ iostat -n 0 -c 2 -w 5
cpu load average
us sy id 1m 5m 15m
13 15 72 2.41 2.25 2.40
10 12 78 2.29 2.22 2.39
Modify line 41 of cpu.sh to:
iostat -n 0 -c 2 -w "$refresh_interval" | tail -n 1 | awk '{ print 100-$3 }'
Hi,
In my case the problem was resolved setting samples_count
to 2.
Anyhow the while loop in the main
function cannot access the parsed values while iostat is running.
Having this issue too. It appears that stdbuf -o0
isn't actually unbuffering the output of iostat when running from the script, as setting a samples_count
to 2 causes my CPU stat to refresh every 2 * {refresh_rate}
seconds.
Could someone create fix(pull request) for this problem? @jolbax @interi-mhickman @aaronlna
Posted a pull request with what I changed to get it working for my OSX Sierra environment.
There might be a more ideal solution that involves getting iostat+stdbuf to actually output correctly, but I don't have time to investigate the issue further.
@aaronlna thank you!
Hi,
I hope you can help me/us. On my machine I can see that the
iostat
command defined in thecpu_collect.sh
script in the line 18 is hanging. If I run the script in debug mode I see it hanging here:If I copy the command in this way
iostat -w 5 -c 60 | stdbuf -o0 awk 'NR > 2 { print 100-$(NF-3); }'
it works without a problem, but in the script It does not work.Do you have any idea? Regards jolbax