sbm

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

commit ff0ec4bc82f98c29938dd4666fa16bf63420ba51
parent f56cdf9b6043a31a2846bb3dec97f49dc2a26a84
Author: Quentin Rameau <quinq@fifth.space>
Date:   Tue, 23 Feb 2016 12:44:50 +0100

Add an option for printing Bytes instead of bits

Diffstat:
Msbm.1 | 4+++-
Msbm.c | 17++++++++++++-----
2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/sbm.1 b/sbm.1 @@ -6,15 +6,17 @@ .Nd simple bandwidth monitor .Sh SYNOPSIS .Nm sbm +.Op Fl B | t .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. .Sh OPTIONS .Bl -tag -width "-i interface" +.It Fl B +Show values in bytes instead of bits in default output. .It Fl c Ar count Stop monitoring after .Ar count diff --git a/sbm.c b/sbm.c @@ -41,6 +41,7 @@ #include "arg.h" char *argv0; +int Bflag; int tflag; void @@ -156,14 +157,17 @@ sample(char *ifname, uint64_t *rxbytes, uint64_t *txbytes, void scale(char **suffix, uint64_t *bits) { - static char *suffixes[] = { "bps", "Kbps", "Mbps" }; + static char *suffixes[][3] = { { "bps", "Kbps", "Mbps" }, + { "Bps", "KBps", "MBps" } }; - *suffix = suffixes[0]; + if (Bflag) + *bits /= 8; + *suffix = suffixes[Bflag][0]; if (*bits >= 1000 && *bits < 1000 * 1000) { - *suffix = suffixes[1]; + *suffix = suffixes[Bflag][1]; *bits /= 1000; } else if (*bits >= 1000 * 1000) { - *suffix = suffixes[2]; + *suffix = suffixes[Bflag][2]; *bits /= 1000 * 1000; } } @@ -267,7 +271,7 @@ loop(char *ifname, long count, struct timeval *delay) void usage(void) { - fprintf(stderr, "usage: %s [-c count] [-d delay] [-i interface] [-t]\n", argv0); + fprintf(stderr, "usage: %s [-B | -t] [-c count] [-d delay] [-i interface]\n", argv0); exit(1); } @@ -280,6 +284,9 @@ main(int argc, char *argv[]) long count = 0, delay = 1000; ARGBEGIN { + case 'B': + Bflag = 1; + break; case 'c': errno = 0; count = strtol(EARGF(usage()), &end, 10);