Skip to content

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

@aurelienshz

Description

@aurelienshz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions