Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for iproute2 using jq #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add support for iproute2 using jq #11

wants to merge 1 commit into from

Conversation

Shadow53
Copy link

From the netstat man page:

This program is obsolete. Replacement for netstat is ss. Replacement for netstat -r is ip route. Replacement for netstat -i is ip -s link. Replacement for netstat -g is ip maddr.

On my openSUSE Tumbleweed installation, netstat is part of the net-tools-deprecated package, which is not installed by default. So, I added support for the iproute2 set of tools.

A single run of ip -s link produces this output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped overrun mcast   
    4076       50       0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    4076       50       0       0       0       0       
2: enp34s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:d8:61:fd:51:b7 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast   
    4364847108 5157895  0       0       0       9117    
    TX: bytes  packets  errors  dropped carrier collsns 
    1522143739 3113517  0       0       0       0       

I have no experience with awk, but I'm assuming this is a different format than netstat provides, since manually running the contents of scripts/network-bandwidth.sh get_bandwidth_for_linux but replacing netstat -ie for ip -s link produces empty output.

Through some cludging around, I was able to determine that the following will process the information from iproute2 correctly. This uses jq instead of awk, since ip has the -json flag:

ip -s -json link | jq -rc '[(map(.stats64.rx.bytes) | add), (map(.stats64.tx.bytes) | add)] | .[]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant