Skip to content

Commit

Permalink
Make cpu_collect compatible with OSX and use gstdbuf
Browse files Browse the repository at this point in the history
  • Loading branch information
slange-dev committed Jan 4, 2025
1 parent 29e150f commit 643f57b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scripts/cpu_collect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ set -e
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"

refresh_interval=$(get_tmux_option "status-interval" "5")
samples_count="60"
refresh_interval=$(get_tmux_option "status-interval" "5")/2
samples_count="2"
cpu_metric_file="$(get_tmux_option "@sysstat_cpu_tmp_dir" "/dev/null")/cpu_collect.metric"

get_cpu_usage() {
if is_osx; then
if command_exists "iostat"; then
iostat -w "$refresh_interval" -c "$samples_count" \
| stdbuf -o0 awk 'NR > 2 { print 100-$(NF-3); }'
| gstdbuf -o0 awk 'NR > 2 { print 100-$(NF-3); }'
else
top -l "$samples_count" -s "$refresh_interval" -n 0 \
| sed -u -nr '/CPU usage/s/.*,[[:space:]]*([0-9]+[.,][0-9]*)%[[:space:]]*idle.*/\1/p' \
| stdbuf -o0 awk '{ print 100-$0 }'
| gstdbuf -o0 awk '{ print 100-$0 }'
fi
elif ! command_exists "vmstat"; then
if is_freebsd; then
Expand Down

0 comments on commit 643f57b

Please sign in to comment.