sbm

simple bandwidth monitor
git clone git://git.2f30.org/sbm
Log | Files | Refs | LICENSE

commit b07ad42aea8df21ee44ce42b697993ea9ec2f329
parent d364489be48241b14554b8106a49611a44e71302
Author: sin <sin@2f30.org>
Date:   Fri, 12 Feb 2016 12:08:11 +0000

Show receive pps and transmit pps as well

Diffstat:
Msbm.c | 28+++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/sbm.c b/sbm.c @@ -66,7 +66,8 @@ scan(char *ifname) } void -sample(char *ifname, unsigned long long *rx, unsigned long long *tx) +sample(char *ifname, unsigned long long *rxbytes, unsigned long long *txbytes, + unsigned long long *rxpps, unsigned long long *txpps) { int mib[6]; char *buf, *next; @@ -96,8 +97,10 @@ sample(char *ifname, unsigned long long *rx, unsigned long long *tx) continue; if (strncmp(sdl->sdl_data, ifname, sdl->sdl_nlen) != 0) continue; - *rx = ifm->ifm_data.ifi_ibytes; - *tx = ifm->ifm_data.ifi_obytes; + *rxbytes = ifm->ifm_data.ifi_ibytes; + *txbytes = ifm->ifm_data.ifi_obytes; + *rxpps = ifm->ifm_data.ifi_ipackets; + *txpps = ifm->ifm_data.ifi_opackets; break; } } @@ -123,14 +126,15 @@ scale(char **suffix, unsigned long long *bits) } void -print(char *ifname, unsigned long long rxbits, unsigned long long txbits) +print(char *ifname, unsigned long long rxbits, unsigned long long txbits, + unsigned long long rxpps, unsigned long long txpps) { char *rxsuffix, *txsuffix; scale(&rxsuffix, &rxbits); scale(&txsuffix, &txbits); - printf("%s: down %lld %s up %lld %s\n", - ifname, rxbits, rxsuffix, txbits, txsuffix); + printf("%s: down %lld %s up %lld %s rxpps %lld txpps %lld\n", + ifname, rxbits, rxsuffix, txbits, txsuffix, rxpps, txpps); } void @@ -138,15 +142,21 @@ loop(char *ifname) { unsigned long long oldrxbytes, rxbytes; unsigned long long oldtxbytes, txbytes; + unsigned long long oldrxpps, rxpps; + unsigned long long oldtxpps, txpps; - sample(ifname, &oldrxbytes, &oldtxbytes); + sample(ifname, &oldrxbytes, &oldtxbytes, &oldrxpps, &oldtxpps); for (;;) { - sample(ifname, &rxbytes, &txbytes); + sample(ifname, &rxbytes, &txbytes, &rxpps, &txpps); print(ifname, (rxbytes - oldrxbytes) * 8, - (txbytes - oldtxbytes) * 8); + (txbytes - oldtxbytes) * 8, + rxpps - oldrxpps, + txpps - oldtxpps); oldrxbytes = rxbytes; oldtxbytes = txbytes; + oldrxpps = rxpps; + oldtxpps = txpps; sleep(1); } }