sbm

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

commit bf6c8660af75c7b143dda9ce17a53fb22167f173
parent 1f43dc21858947527d3463c33421338815adf6d1
Author: sin <sin@2f30.org>
Date:   Tue Feb 23 10:40:59 +0000

Add terse output option

This is useful when sbm is used in a script.

Diffstat:
sbm.1 | 6+++++-
sbm.c | 34+++++++++++++++++++++++-----------
2 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/sbm.1 b/sbm.1 @@ -1,4 +1,4 @@ -.Dd Feb 19, 2016 +.Dd Feb 23, 2016 .Dt SBM 1 .Os .Sh NAME @@ -9,6 +9,7 @@ .Op Fl c Ar count .Op Fl d Ar delay .Op Fl i Ar interface +.Op Fl t .Sh DESCRIPTION .Nm is a simple bandwidth monitor. @@ -28,6 +29,9 @@ ms. The default delay is 1000 ms. Monitor the selected .Ar interface . If not provided the first active, non-loopback interface will be used. +.It Fl t +Enable terse output. The first pair of values is down/up in bps and the +second pair is down/up in pps. .El .Sh AUTHORS .An Dimitris Papastamos Aq Mt sin@2f30.org diff --git a/sbm.c b/sbm.c @@ -41,6 +41,7 @@ #include "arg.h" char *argv0; +int tflag; void scan(char *ifname) @@ -173,16 +174,24 @@ print(char *ifname, uint64_t rxbits, uint64_t txbits, { char *rxsuffix, *txsuffix; - scale(&rxsuffix, &rxbits); - scale(&txsuffix, &txbits); - printf("%s: down %llu %s up %llu %s rxpps %llu txpps %llu\n", - ifname, - (unsigned long long)rxbits, - rxsuffix, - (unsigned long long)txbits, - txsuffix, - (unsigned long long)rxpps, - (unsigned long long)txpps); + if (!tflag) { + scale(&rxsuffix, &rxbits); + scale(&txsuffix, &txbits); + printf("%s: down %llu %s up %llu %s rxpps %llu txpps %llu\n", + ifname, + (unsigned long long)rxbits, + rxsuffix, + (unsigned long long)txbits, + txsuffix, + (unsigned long long)rxpps, + (unsigned long long)txpps); + } else { + printf("%llu %llu %llu %llu\n", + (unsigned long long)rxbits, + (unsigned long long)txbits, + (unsigned long long)rxpps, + (unsigned long long)txpps); + } fflush(stdout); } @@ -258,7 +267,7 @@ loop(char *ifname, long count, struct timeval *delay) void usage(void) { - fprintf(stderr, "usage: %s [-c count] [-d delay] [-i interface]\n", argv0); + fprintf(stderr, "usage: %s [-c count] [-d delay] [-i interface] [-t]\n", argv0); exit(1); } @@ -287,6 +296,9 @@ main(int argc, char *argv[]) strncpy(ifname, EARGF(usage()), sizeof(ifname)); ifname[IF_NAMESIZE - 1] = '\0'; break; + case 't': + tflag = 1; + break; default: usage(); } ARGEND