Make the -w option actually useful to people. Instead of it creating a
messy 130 column collage, output the system totals -or- info for a specific interface if -I is given. Also wait for <interval> before outputting the first sample so that it represents meaningful data (as opposed to the total since the system was booted - most busy systems wrap around many times during their operation, so these numbers are only misleading).
This commit is contained in:
parent
5ccab2afa9
commit
0b87c9157d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=14301
@ -277,14 +277,16 @@ sidewaysintpr(interval, off)
|
||||
register struct iftot *ip, *total;
|
||||
register int line;
|
||||
struct iftot *lastif, *sum, *interesting;
|
||||
int oldmask;
|
||||
int oldmask, first;
|
||||
u_long interesting_off;
|
||||
|
||||
if (kread(off, (char *)&firstifnet, sizeof (u_long)))
|
||||
return;
|
||||
lastif = iftot;
|
||||
sum = iftot + MAXIF - 1;
|
||||
total = sum - 1;
|
||||
interesting = iftot;
|
||||
interesting = NULL;
|
||||
interesting_off = 0;
|
||||
for (off = firstifnet, ip = iftot; off;) {
|
||||
char *cp;
|
||||
char name[16], tname[16];
|
||||
@ -295,8 +297,10 @@ sidewaysintpr(interval, off)
|
||||
break;
|
||||
tname[15] = '\0';
|
||||
snprintf(name, 16, "%s%d", tname, ifnet.if_unit);
|
||||
if (interface && strcmp(name, interface) == 0)
|
||||
if (interface && strcmp(name, interface) == 0) {
|
||||
interesting = ip;
|
||||
interesting_off = off;
|
||||
}
|
||||
snprintf(ip->ift_name, 16, "(%s)", name);;
|
||||
ip++;
|
||||
if (ip >= iftot + MAXIF - 2)
|
||||
@ -308,116 +312,96 @@ sidewaysintpr(interval, off)
|
||||
(void)signal(SIGALRM, catchalarm);
|
||||
signalled = NO;
|
||||
(void)alarm(interval);
|
||||
banner:
|
||||
printf(" input %s%-6.6s %soutput ", bflag ? " " : "",
|
||||
interesting->ift_name, bflag ? " " : "");
|
||||
if (lastif - iftot > 0) {
|
||||
if (dflag)
|
||||
printf(" ");
|
||||
printf(" input %s(Total) %soutput", bflag ? " " : "",
|
||||
bflag ? " " : "");
|
||||
}
|
||||
for (ip = iftot; ip < iftot + MAXIF; ip++) {
|
||||
ip->ift_ip = 0;
|
||||
ip->ift_ie = 0;
|
||||
ip->ift_ib = 0;
|
||||
ip->ift_op = 0;
|
||||
ip->ift_oe = 0;
|
||||
ip->ift_ob = 0;
|
||||
ip->ift_co = 0;
|
||||
ip->ift_dr = 0;
|
||||
ip->ift_ib = 0;
|
||||
ip->ift_ob = 0;
|
||||
}
|
||||
first = 1;
|
||||
banner:
|
||||
printf("%17s %14s %16s", "input",
|
||||
interesting ? interesting->ift_name : "(Total)", "output");
|
||||
putchar('\n');
|
||||
printf("%8.8s %5.5s ", "packets", "errs");
|
||||
if (bflag)
|
||||
printf("%10.10s ","bytes");
|
||||
printf("%8.8s %5.5s ", "packets", "errs");
|
||||
if (bflag)
|
||||
printf("%10.10s ","bytes");
|
||||
printf("%5.5s ", "colls");
|
||||
printf("%10s %5s %10s %10s %5s %10s %5s",
|
||||
"packets", "errs", "bytes", "packets", "errs", "bytes", "colls");
|
||||
if (dflag)
|
||||
printf("%5.5s ", "drops");
|
||||
if (lastif - iftot > 0) {
|
||||
printf(" %8.8s %5.5s", "packets", "errs");
|
||||
if (bflag)
|
||||
printf(" %10.10s", "bytes");
|
||||
printf(" %8.8s %5.5s", "packets", "errs");
|
||||
if (bflag)
|
||||
printf(" %10.10s", "bytes");
|
||||
printf(" %5.5s", "colls");
|
||||
if (dflag)
|
||||
printf(" %5.5s", "drops");
|
||||
}
|
||||
printf(" %5.5s", "drops");
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
line = 0;
|
||||
loop:
|
||||
sum->ift_ip = 0;
|
||||
sum->ift_ie = 0;
|
||||
sum->ift_op = 0;
|
||||
sum->ift_oe = 0;
|
||||
sum->ift_co = 0;
|
||||
sum->ift_dr = 0;
|
||||
sum->ift_ib = 0;
|
||||
sum->ift_ob = 0;
|
||||
for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
|
||||
if (kread(off, (char *)&ifnet, sizeof ifnet)) {
|
||||
off = 0;
|
||||
continue;
|
||||
}
|
||||
if (ip == interesting) {
|
||||
printf("%8u %5u ",
|
||||
if (interesting != NULL) {
|
||||
ip = interesting;
|
||||
if (kread(interesting_off, (char *)&ifnet, sizeof ifnet)) {
|
||||
printf("???\n");
|
||||
exit(1);
|
||||
};
|
||||
if (!first) {
|
||||
printf("%10u %5u %10u %10u %5u %10u %5u",
|
||||
ifnet.if_ipackets - ip->ift_ip,
|
||||
ifnet.if_ierrors - ip->ift_ie);
|
||||
if (bflag)
|
||||
printf("%10u ", ifnet.if_ibytes - ip->ift_ib);
|
||||
printf("%8u %5u ",
|
||||
ifnet.if_ierrors - ip->ift_ie,
|
||||
ifnet.if_ibytes - ip->ift_ib,
|
||||
ifnet.if_opackets - ip->ift_op,
|
||||
ifnet.if_oerrors - ip->ift_oe);
|
||||
if (bflag)
|
||||
printf("%10u ", ifnet.if_obytes - ip->ift_ob);
|
||||
printf("%5u", ifnet.if_collisions - ip->ift_co);
|
||||
ifnet.if_oerrors - ip->ift_oe,
|
||||
ifnet.if_obytes - ip->ift_ob,
|
||||
ifnet.if_collisions - ip->ift_co);
|
||||
if (dflag)
|
||||
printf(" %5u",
|
||||
ifnet.if_snd.ifq_drops - ip->ift_dr);
|
||||
printf(" %5u", ifnet.if_snd.ifq_drops - ip->ift_dr);
|
||||
}
|
||||
ip->ift_ip = ifnet.if_ipackets;
|
||||
ip->ift_ie = ifnet.if_ierrors;
|
||||
ip->ift_ib = ifnet.if_ibytes;
|
||||
ip->ift_op = ifnet.if_opackets;
|
||||
ip->ift_oe = ifnet.if_oerrors;
|
||||
ip->ift_ob = ifnet.if_obytes;
|
||||
ip->ift_co = ifnet.if_collisions;
|
||||
ip->ift_dr = ifnet.if_snd.ifq_drops;
|
||||
ip->ift_ib = ifnet.if_ibytes;
|
||||
ip->ift_ob = ifnet.if_obytes;
|
||||
sum->ift_ip += ip->ift_ip;
|
||||
sum->ift_ie += ip->ift_ie;
|
||||
sum->ift_op += ip->ift_op;
|
||||
sum->ift_oe += ip->ift_oe;
|
||||
sum->ift_co += ip->ift_co;
|
||||
sum->ift_dr += ip->ift_dr;
|
||||
sum->ift_ib += ip->ift_ib;
|
||||
sum->ift_ob += ip->ift_ob;
|
||||
off = (u_long) ifnet.if_next;
|
||||
} else {
|
||||
sum->ift_ip = 0;
|
||||
sum->ift_ie = 0;
|
||||
sum->ift_ib = 0;
|
||||
sum->ift_op = 0;
|
||||
sum->ift_oe = 0;
|
||||
sum->ift_ob = 0;
|
||||
sum->ift_co = 0;
|
||||
sum->ift_dr = 0;
|
||||
for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
|
||||
if (kread(off, (char *)&ifnet, sizeof ifnet)) {
|
||||
off = 0;
|
||||
continue;
|
||||
}
|
||||
sum->ift_ip += ifnet.if_ipackets;
|
||||
sum->ift_ie += ifnet.if_ierrors;
|
||||
sum->ift_ib += ifnet.if_ibytes;
|
||||
sum->ift_op += ifnet.if_opackets;
|
||||
sum->ift_oe += ifnet.if_oerrors;
|
||||
sum->ift_ob += ifnet.if_obytes;
|
||||
sum->ift_co += ifnet.if_collisions;
|
||||
sum->ift_dr += ifnet.if_snd.ifq_drops;
|
||||
off = (u_long) ifnet.if_next;
|
||||
}
|
||||
if (!first) {
|
||||
printf("%10u %5u %10u %10u %5u %10u %5u",
|
||||
sum->ift_ip - total->ift_ip,
|
||||
sum->ift_ie - total->ift_ie,
|
||||
sum->ift_ib - total->ift_ib,
|
||||
sum->ift_op - total->ift_op,
|
||||
sum->ift_oe - total->ift_oe,
|
||||
sum->ift_ob - total->ift_ob,
|
||||
sum->ift_co - total->ift_co);
|
||||
if (dflag)
|
||||
printf(" %5u", sum->ift_dr - total->ift_dr);
|
||||
}
|
||||
*total = *sum;
|
||||
}
|
||||
if (lastif - iftot > 0) {
|
||||
printf(" %8u %5u",
|
||||
sum->ift_ip - total->ift_ip,
|
||||
sum->ift_ie - total->ift_ie);
|
||||
if (bflag)
|
||||
printf(" %10u", sum->ift_ib - total->ift_ib);
|
||||
printf(" %8u %5u",
|
||||
sum->ift_op - total->ift_op,
|
||||
sum->ift_oe - total->ift_oe);
|
||||
if (bflag)
|
||||
printf(" %10u", sum->ift_ob - total->ift_ob);
|
||||
printf(" %5u", sum->ift_co - total->ift_co);
|
||||
if (dflag)
|
||||
printf(" %5u", sum->ift_dr - total->ift_dr);
|
||||
}
|
||||
*total = *sum;
|
||||
putchar('\n');
|
||||
if (!first)
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
line++;
|
||||
oldmask = sigblock(sigmask(SIGALRM));
|
||||
if (! signalled) {
|
||||
sigpause(0);
|
||||
@ -425,9 +409,12 @@ sidewaysintpr(interval, off)
|
||||
sigsetmask(oldmask);
|
||||
signalled = NO;
|
||||
(void)alarm(interval);
|
||||
line++;
|
||||
first = 0;
|
||||
if (line == 21)
|
||||
goto banner;
|
||||
goto loop;
|
||||
else
|
||||
goto loop;
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
|
@ -88,9 +88,9 @@ With the default display,
|
||||
show the state of all sockets; normally sockets used by
|
||||
server processes are not shown.
|
||||
.It Fl b
|
||||
With either interface display (option
|
||||
With the interface display (option
|
||||
.Fl i
|
||||
or an interval, as described below),
|
||||
, as described below),
|
||||
show the number of bytes in and out.
|
||||
.It Fl d
|
||||
With either interface display (option
|
||||
@ -261,15 +261,10 @@ interval argument, it displays a running count of statistics related to
|
||||
network interfaces.
|
||||
An obsolescent version of this option used a numeric parameter
|
||||
with no option, and is currently supported for backward compatibility.
|
||||
This display consists of a column for the primary interface (the first
|
||||
interface found during autoconfiguration) and a column summarizing
|
||||
information for all interfaces.
|
||||
The primary interface may be replaced with another interface with the
|
||||
By default, this display summarizes information for all interfaces.
|
||||
Information for a specific interface may be displayed with the
|
||||
.Fl I
|
||||
option.
|
||||
The first line of each screen of information contains a summary since the
|
||||
system was last rebooted. Subsequent lines of output show values
|
||||
accumulated over the preceding interval.
|
||||
.Sh SEE ALSO
|
||||
.Xr nfsstat 1 ,
|
||||
.Xr ps 1 ,
|
||||
|
Loading…
Reference in New Issue
Block a user