add network bandwidth support for macOS #249
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So I went to enable network-bandwidth (on a mac) and noticed this wasn't supported yet, but it was only after getting some custom changes working locally that I even thought to check if there was already a PR for it haha.
I see #113 exists already, but it looks like the person who made that PR just got busy with work and hasn't had time to address all the feedback and resolve the conflicts, and progress seems to have stalled on that several years ago - so I really hope I'm not stepping on any toes by making a separate PR for the same feature, but I'd really love to get this merged into the repo so that I don't need to run a modified version of this repo and manually keep it in sync with my local changes when I update to newer versions.
please let me know if there's anything I should change, happy to ^.^
(I figure you'll probably want me to squash the commits, but I'll leave them as-is for now, for convenience)
and some notes to hopefully make reviewing this a bit easier:
route
instead ofip
to get the interface name on Darwin Architectures, which is installed by default on macOS.netstat
to get the tx and rx bytes, except instead of calling netstat twice, we can just do it once and return both values at the same time.interface_bytes
fn to no longer require a second argument ($2 which would always either be "tx" or "rx"), so instead now it just gets the interface name from $1 (the first argument) and returns BOTH the tx and rx bytes for that interface, in the format: "TX_Bytes RX_Bytes" where the upload (tx) bytes are listed first, as is the convention elsewhere, and then a whitespace character followed by the download (rx) bytes. This lets us reduce the number of calls tointerface_bytes
per interval from 4 to 2 while also making the code inget_bandwidth
a bit simpler and easier to read.bc
to useawk
for floating point math, the "%.2f" limits the output of printf to two decimal places. I believe it should be reasonable to expect awk to be installed already on most OS's and the repo's existing patterns seem to agree but please lmk if that's not a sound assumption.