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

Added feature: Display units in Mbits/Mbytes #1

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

Conversation

mdre3a
Copy link

@mdre3a mdre3a commented Jul 6, 2023

No description provided.

@matttbe
Copy link
Owner

matttbe commented Jul 7, 2023

Thank you for this PR.

Note that I'm not the maintainer of ifstat, I created this repo to ease the packaging in different distributions.

Good idea to add this feature. But then you will also need to edit the man page and respect the alignment:

diff --git a/ifstat.1 b/ifstat.1
index 8288310..7328ed5 100644
--- a/ifstat.1
+++ b/ifstat.1
@@ -134,7 +134,7 @@
 ifstat \- Report InterFace STATistics
 .SH "SYNOPSIS"
 .IX Header "SYNOPSIS"
-\&\fBifstat\fR [\fB\-a\fR] [\fB\-l\fR] [\fB\-z\fR] [\fB\-n\fR] [\fB\-v\fR] [\fB\-h\fR] [\fB\-t\fR] [\fB\-i\fR if0,if1,...] [\fB\-d\fR drv[:opt]] [\fB\-s\fR [comm@][#]host[/nn]] [\fB\-T\fR] [\fB\-A\fR] [\fB\-w\fR] [\fB\-W\fR] [\fB\-S\fR] [\fB\-b\fR] [\fB\-q\fR] [delay[/delay] [count]]
+\&\fBifstat\fR [\fB\-a\fR] [\fB\-l\fR] [\fB\-z\fR] [\fB\-n\fR] [\fB\-v\fR] [\fB\-h\fR] [\fB\-t\fR] [\fB\-i\fR if0,if1,...] [\fB\-d\fR drv[:opt]] [\fB\-s\fR [comm@][#]host[/nn]] [\fB\-T\fR] [\fB\-A\fR] [\fB\-w\fR] [\fB\-W\fR] [\fB\-S\fR] [\fB\-b\fR] [\fB\-M\fR] [\fB\-q\fR] [delay[/delay] [count]]
 .SH "DESCRIPTION"
 .IX Header "DESCRIPTION"
 Ifstat is a little tool to report interface activity, just like iostat/vmstat do for other system statistics.
@@ -183,6 +183,9 @@ Keep stats updated on the same line if possible (no scrolling nor wrapping).
 .IP "\fB\-b\fR" 4
 .IX Item "-b"
 Reports bandwith in kbits/sec instead of kbytes/sec.
+.IP "\fB\-M\fR" 4
+.IX Item "-M"
+Reports bandwith in Mbytes/src (or Mbits/sec if used with \-b) instead of kbytes/sec.
 .IP "\fB\-q\fR" 4
 .IX Item "-q"
 Quiet mode, warnings are not printed.
diff --git a/ifstat.c b/ifstat.c
index 29466c0..35babf3 100644
--- a/ifstat.c
+++ b/ifstat.c
@@ -170,7 +170,8 @@ static void usage(int result) {
   fprintf(stderr,
 	  "usage: %s [-a] [-l] [-z] [-n] [-v] [-h] [-t] [-i if0,if1,...]\n"
 	  "       [-d drv[:opt]] [-s [comm@][#]host[/nn]] [-T] [-A] [-w]\n"
-	  "       [-W] [-S] [-M] [-b] [-q] [delay[/delay] [count]]\n", ifstat_progname);
+	  "       [-W] [-S] [-b] [-M] [-q] [delay[/delay] [count]]\n",
+	  ifstat_progname);
   exit(result);
 }
 
@@ -230,7 +231,7 @@ static RETSIGTYPE sigcont(int sig) {
 #define OPT_WRAP      64
 #define OPT_NOTITLE  128
 #define OPT_NOSCROLL 256
-#define OPT_UNITMEGA   512
+#define OPT_UNITMEGA 512
 
 #define SPACE "  "
 
@@ -282,10 +283,10 @@ static void print_legend(struct ifstat_data *ptr, int options, int line) {
     len = LEN(options, ptr->namelen);
     if (options & OPT_UNITMEGA) {
       print_center((options & OPT_UNITBITS) ? " Mbps in  Mbps out" :
-      " MB/s in  MB/s out", WIDTH, len);
+		  " MB/s in  MB/s out", WIDTH, len);
     } else {
       print_center((options & OPT_UNITBITS) ? " Kbps in  Kbps out" :
-      " KB/s in  KB/s out", WIDTH, len);
+		   " KB/s in  KB/s out", WIDTH, len);
     }
     if ((pos = pos_next(pos, len, options)) == 0 && ptr->next != NULL)
       return;
@@ -345,7 +346,8 @@ static void print_stats(struct ifstat_list *ifs,
   
   delay = end->tv_sec - start->tv_sec + ((double) (end->tv_usec - start->tv_usec))
     / (double) 1000000;
-  scale = delay * (options & OPT_UNITBITS ? 128 : 1024) * (options & OPT_UNITMEGA ? 1024 : 1);
+  scale = delay * (options & OPT_UNITBITS ? 128 : 1024)
+    * (options & OPT_UNITMEGA ? 1024 : 1);
   
   tkbin = tkbout = 0;
   for (ptr = ifs->first; ptr != NULL; ptr = ptr->next) {
diff --git a/ifstat.pod b/ifstat.pod
index 30cabec..fe1efb7 100644
--- a/ifstat.pod
+++ b/ifstat.pod
@@ -12,7 +12,7 @@ ifstat - Report InterFace STATistics
 
 =head1 SYNOPSIS
 
-B<ifstat> [B<-a>] [B<-l>] [B<-z>] [B<-n>] [B<-v>] [B<-h>] [B<-t>] [B<-i> if0,if1,...] [B<-d> drv[:opt]] [B<-s> [comm@][#]host[/nn]] [B<-T>] [B<-A>] [B<-w>] [B<-W>] [B<-S>] [B<-b>] [B<-q>] [delay[/delay] [count]]
+B<ifstat> [B<-a>] [B<-l>] [B<-z>] [B<-n>] [B<-v>] [B<-h>] [B<-t>] [B<-i> if0,if1,...] [B<-d> drv[:opt]] [B<-s> [comm@][#]host[/nn]] [B<-T>] [B<-A>] [B<-w>] [B<-W>] [B<-S>] [B<-b>] [B<-M>] [B<-q>] [delay[/delay] [count]]
 
 =head1 DESCRIPTION
 
@@ -80,6 +80,10 @@ Keep stats updated on the same line if possible (no scrolling nor wrapping).
 
 Reports bandwith in kbits/sec instead of kbytes/sec.
 
+=item B<-M>
+
+Reports bandwith in Mbytes/src (or Mbits/sec if used with -b) instead of kbytes/sec.
+
 =item B<-q>
 
 Quiet mode, warnings are not printed.

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.

2 participants