sbm

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

commit 1ca82c18fc7a95002a59b8cda651cf1547e92c15
parent 50474415607371eaaf9c99342ffb4134c7baf837
Author: Quentin Rameau <quinq@fifth.space>
Date:   Sat Jul 30 11:58:13 +0200

Fix total traffic accumulation

Don't forget that we scale bits, not bytes.

Diffstat:
sbm.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/sbm.c b/sbm.c @@ -32,7 +32,7 @@ char *argv0; char *ifname; -uint64_t orxb, otxb, crxb, ctxb; +uint64_t origrxbytes, origtxbytes, rxbytes, txbytes; int Bflag; int tflag; @@ -226,16 +226,15 @@ void loop(long count, struct timeval *delay) { struct timeval old, now, diff; - uint64_t oldrxbytes, rxbytes, diffrxbits; - uint64_t oldtxbytes, txbytes, difftxbits; + uint64_t oldrxbytes, diffrxbits; + uint64_t oldtxbytes, difftxbits; uint64_t oldrxpps, rxpps, diffrxpps; uint64_t oldtxpps, txpps, difftxpps; long n = 0; getmonotime(&old); sample(&oldrxbytes, &oldtxbytes, &oldrxpps, &oldtxpps); - orxb = oldrxbytes; - otxb = oldtxbytes; + origrxbytes = oldrxbytes, origtxbytes = oldtxbytes; for (;;) { tvsleep(delay); sample(&rxbytes, &txbytes, &rxpps, &txpps); @@ -251,7 +250,6 @@ loop(long count, struct timeval *delay) print(diffrxbits, difftxbits, diffrxpps, difftxpps); oldrxbytes = rxbytes, oldtxbytes = txbytes; oldrxpps = rxpps, oldtxpps = txpps; - crxb = rxbytes - orxb, ctxb = txbytes - otxb; if (count && ++n >= count) break; } @@ -262,9 +260,11 @@ printrxtx(int sig) { char *rxsuffix, *txsuffix; double rxround, txround; + uint64_t rxbits = (rxbytes - origrxbytes) * 8, + txbits = (txbytes - origtxbytes) * 8; - rxround = scale(&rxsuffix, crxb); - txround = scale(&txsuffix, ctxb); + rxround = scale(&rxsuffix, rxbits); + txround = scale(&txsuffix, txbits); printf("%*s %6.2f %2s Rx %6.2f %2s Tx\n", (int)strlen(ifname) + 1, "",