24 lines
1.2 KiB
Bash
Executable file
24 lines
1.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
# This is not as good as activity monitor, as it shows per-core not overall usage
|
|
cpu=$(ps -Ac -o %cpu,comm | sort -nk1 | grep -vE "(top)" | tail -1 \
|
|
| awk -v OFMT=%.0f '{print int($1+0.5)"%",$2,$3}')
|
|
|
|
# nettop needs at least two samples (-L 2) to calculate a delta
|
|
# the beasty awk then throws away the first 50% samples (n=50) with bogus data
|
|
# and sorts it by bytes_in
|
|
bandwidth=$(nettop -t wifi -P -J bytes_in,bytes_out -d -x -L 2 \
|
|
| grep -v '^time' | sort -k1 | awk -v n=50 '{a[FNR]=$0; \
|
|
min=FNR-int(FNR*n/100)} {i=min; while(i in a) delete a[i--]} \
|
|
END{for(i=min+1;i<=FNR;++i) print a[i]}' - | sed 's/,$//' \
|
|
| sed 's#\.[0-9]*##g' | sort -t',' -k 3 -n | tail -1 | \
|
|
awk -F',' {'print $2,"↓ "int($3/1000) " KB/s ↑",int($4/1000) " KB/s"'}
|
|
)
|
|
|
|
# Pings the default gateway and returns avg ping. Three ping counts recommended
|
|
# for a reasonably meaningful average
|
|
rtt=$(ping -t 2 -q -c 3 "$(route -n get default | awk '$1 ~ "gateway:" \
|
|
{print $2}')" | awk -F'/' '$1 ~ "round-trip" {print int($5) " ms"}')
|
|
|
|
# Icons are shipped with a font from https://www.nerdfonts.com/font-downloads
|
|
echo " $rtt $bandwidth $cpu"
|