Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Mac, uw_load is wrong when there are multiple volumes mounted #7

Open
aurelienshz opened this issue Mar 10, 2020 · 1 comment
Open

Comments

@aurelienshz
Copy link

aurelienshz commented Mar 10, 2020

On a Mac, with an external disk or a dmg mounted, the columns in the output of the iostat command get shifted to the right (each disk adds 3 columns). This causes the result of uw_load to be very wrong.

Reproduction steps:

Mount a dmg to add a new volume.

Usagewatch.uw_load
# => 11.0

Eject the dmg:

Usagewatch.uw_load
# => 2.78

Why is this happening?

The command used to get the current CPU load is iostat -w1 -c 2 | awk '{print $7}'.

That's happening because, with a mounted volume, the output of iostat -w1 -c 2 contains 3 more columns to the left of the load average columns, which messes up the result of the awk command.

# With an external volume:
$ iostat -w1 -c 2
              disk0               disk2       cpu    load average
    KB/t  tps  MB/s     KB/t  tps  MB/s  us sy id   1m   5m   15m
   18.83   29  0.53   352.03    0  0.00  15 13 72  1.97 2.44 2.99
    4.00   14  0.05     0.00    0  0.00   6  9 85  1.97 2.44 2.99

# Without an external volume:
$ iostat -w1 -c 2
              disk0       cpu    load average
    KB/t  tps  MB/s  us sy id   1m   5m   15m
   18.83   29  0.53  15 13 72  2.54 2.53 3.01
    6.13   30  0.18  32 24 44  2.90 2.60 3.03

Cc @Lyriaaw

@aurelienshz
Copy link
Author

Potential fix: use echo $x | awk '{print $(NF-2)}'. This would take the 3rd to last column (ie 3rd starting from the rightmost column) instead of the 7th (starting from the left). Let me know if you can see any good reason not to do this, otherwise I'm happy to submit a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant