improve speed format (#738)

* improve speed format

Convert network speed into human-readable format using numfmt, this will handle low and high values properly.

* Update nettraf

fix jitter
This commit is contained in:
jamazi 2020-07-02 17:59:54 +03:00 committed by GitHub
parent be9490155f
commit f11008c619
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,10 +19,10 @@ update() {
cache=${XDG_CACHE_HOME:-$HOME/.cache}/${1##*/} cache=${XDG_CACHE_HOME:-$HOME/.cache}/${1##*/}
[ -f "$cache" ] && read -r old < "$cache" || old=0 [ -f "$cache" ] && read -r old < "$cache" || old=0
printf %d\\n "$sum" > "$cache" printf %d\\n "$sum" > "$cache"
printf %d\\n $(( (sum - old) / 1024 )) printf %d\\n $(( sum - old ))
} }
rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes)
tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes)
printf "🔻%dKiB 🔺%dKiB\\n" "$rx" "$tx" printf "🔻%4sB 🔺%4sB\\n" $(numfmt --to=iec $rx) $(numfmt --to=iec-i $tx)