Skip to content

Instantly share code, notes, and snippets.

@xiaq
Created January 21, 2021 00:55
Show Gist options
  • Save xiaq/81b1896416d9762b420bc5f332cfabdd to your computer and use it in GitHub Desktop.
Save xiaq/81b1896416d9762b420bc5f332cfabdd to your computer and use it in GitHub Desktop.
rx = 0
tx = 0
ip -j -s link | from-json | all (one) | each [iface]{
if (eq $iface[ifname] lo) {
continue
}
rx = (+ $rx $iface[stats64][rx][bytes])
tx = (+ $tx $iface[stats64][tx][bytes])
}
put $rx $tx
@Kingsy
Copy link

Kingsy commented Jan 21, 2021

ip link output

[{"ifindex":1,"ifname":"lo","flags":["LOOPBACK","UP","LOWER_UP"],"mtu":65536,"qdisc":"noqueue","operstate":"UP","linkmode":"DEFAULT","group":"default","txqlen":1000,"link_type":"loopback","address":"00:00:00:00:00:00","broadcast":"00:00:00:00:00:00","stats64":{"rx":{"bytes":92317024,"packets":23673,"errors":0,"dropped":0,"over_errors":0,"multicast":0},"tx":{"bytes":92317024,"packets":23673,"errors":0,"dropped":0,"carrier_errors":0,"collisions":0}}},{"ifindex":2,"ifname":"wlp4s0","flags":["BROADCAST","MULTICAST","UP","LOWER_UP"],"mtu":1500,"qdisc":"noqueue","operstate":"UP","linkmode":"DORMANT","group":"default","txqlen":1000,"link_type":"ether","address":"34:02:86:a6:26:d8","broadcast":"ff:ff:ff:ff:ff:ff","stats64":{"rx":{"bytes":704839624,"packets":566120,"errors":0,"dropped":0,"over_errors":0,"multicast":0},"tx":{"bytes":35807409,"packets":202287,"errors":0,"dropped":0,"carrier_errors":0,"collisions":0}}}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment