From d51849a38c3303331ade81fcb053d78a915bea47 Mon Sep 17 00:00:00 2001 From: Rich Murphey Date: Fri, 17 Jun 1994 06:42:39 +0000 Subject: [PATCH] slstat - report serial line IP statistics: bytes in/out, packets in/out, errors, compressed, and uncompressed packets in/out. --- usr.sbin/slstat/Makefile | 11 ++ usr.sbin/slstat/slstat.8 | 141 +++++++++++++++++++ usr.sbin/slstat/slstat.c | 287 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 439 insertions(+) create mode 100644 usr.sbin/slstat/Makefile create mode 100644 usr.sbin/slstat/slstat.8 create mode 100644 usr.sbin/slstat/slstat.c diff --git a/usr.sbin/slstat/Makefile b/usr.sbin/slstat/Makefile new file mode 100644 index 000000000000..de18bc83f46e --- /dev/null +++ b/usr.sbin/slstat/Makefile @@ -0,0 +1,11 @@ +# from: @(#)Makefile 5.6 (Berkeley) 4/23/91 +# $Id: Makefile,v 1.1 1993/11/16 04:16:46 brezak Exp $ + +PROG= slstat +MAN8= slstat.8 +DPADD= ${LIBUTIL} +LDADD= -lutil +BINGRP= kmem +BINMODE=2555 + +.include diff --git a/usr.sbin/slstat/slstat.8 b/usr.sbin/slstat/slstat.8 new file mode 100644 index 000000000000..0194cbf80e95 --- /dev/null +++ b/usr.sbin/slstat/slstat.8 @@ -0,0 +1,141 @@ +.\" Copyright (c) 1986 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)slstat.8 6.8 (Berkeley) 6/20/91 +.\" +.TH SLSTAT 1 "June 20, 1991" +.UC 4 +.SH NAME +slstat \- report serial line IP statistics +.SH SYNOPSIS +.nf +.ft B +slstat [ \-i interval ] [ \-v ] [ \-r ] [ unit ] [ system ] [ core ] +.ft R +.fi +.SH DESCRIPTION +.I Slstat +reports certain kernel statistics kept about serial line internet +protocol traffic. +.PP +The options are as follows: +.TP +\-i +Repeat the display indefinitely every +.I interval +seconds. +If no +.I interval +is specified, the default is 5 seconds. +.TP +\-v +Verbose display of extra fields of information. +.TP +\-r +Display all values in rate per second that ammount per interval. +.TP +unit +is a single digit specifying the slip interface. The default unit is +.I 0 +for interface +.I sl0. +.TP +system +Extract the name list from the specified system instead of the default, /386bsd. +.TP +core +Extract values associated with the name list from the specified +core instead of the default, /dev/kmem. +.PP +By default, +.I vmstat +displays the following information: +.PP +.TP +in +bytes received +.TP +out +bytes sent +.TP +pack +packets received or sent +.TP +comp +compressed packets received or sent +.TP +uncomp +uncompressed packets received or sent +.TP +unknwn +inbound packets of unknown type +.TP +toss +inbound packets tossed because of error +.TP +other +all other inbound or outbound ip packets +.TP +err +input or output errors +.TP +search +searches for connection state +.TP +miss +times we could not find a connectoin state +.TP +coll +collisions with end of clists. +If you get many collisions (more than one or two +a day) you probably do not have enough clists +and you should increase "nclist" in param.c. +.SH EXAMPLES +The command ``slstat -i 5'' will print what the system is doing every five +seconds. +.SH FILES +.ta \w'/dev/kmem 'u +/386bsd default kernel namelist +.br +/dev/kmem default memory file +.SH SEE ALSO +.IR fstat (1), +.IR netstat (1), +.IR nfsstat (1), +.IR ps (1), +.IR systat (1), +.IR iostat (8), +.IR pstat (8) +.sp +The sections starting with ``Interpreting system activity'' in +.IR "Installing and Operating 4.3BSD" . +.SH BUGS + diff --git a/usr.sbin/slstat/slstat.c b/usr.sbin/slstat/slstat.c new file mode 100644 index 000000000000..fe41c791a147 --- /dev/null +++ b/usr.sbin/slstat/slstat.c @@ -0,0 +1,287 @@ +/* + * print serial line IP statistics: + * slstat [-i interval] [-v] [interface] [system] [core] + * + * Copyright (c) 1989, 1990, 1991, 1992 Regents of the University of + * California. All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Van Jacobson (van@ee.lbl.gov), Dec 31, 1989: + * - Initial distribution. + */ + +#ifndef lint +static char rcsid[] = "$Id: slstat.c,v 1.1 1993/11/16 04:16:48 brezak Exp $"; +#endif + +#include +#include +#include +#include + +#define INET + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +struct nlist nl[] = { +#define N_SOFTC 0 + { "_sl_softc" }, + "", +}; + +char *system = _PATH_UNIX; +char *kmemf = NULL; + +int kflag; +int rflag; +int vflag; +unsigned interval = 5; +int unit; + +extern char *malloc(); +extern off_t lseek(); + +main(argc, argv) + int argc; + char *argv[]; +{ + int c; + --argc; ++argv; + while (argc > 0) { + if (strcmp(argv[0], "-v") == 0) { + ++vflag; + ++argv, --argc; + continue; + } + if (strcmp(argv[0], "-r") == 0) { + ++rflag; + ++argv, --argc; + continue; + } + if (strcmp(argv[0], "-i") == 0 && argv[1] && + isdigit(argv[1][0])) { + interval = atoi(argv[1]); + if (interval <= 0) + usage(); + ++argv, --argc; + ++argv, --argc; + continue; + } + if (isdigit(argv[0][0])) { + unit = atoi(argv[0]); + if (unit < 0) + usage(); + ++argv, --argc; + continue; + } + if (kflag) + usage(); + + system = *argv; + ++argv, --argc; + if (argc > 0) { + kmemf = *argv++; + --argc; + kflag++; + } + } + if (kvm_openfiles(system, kmemf, NULL) < 0) { + (void)fprintf(stderr, + "slstat: kvm_openfiles(%s,%s,0): %s\n", + system, kmemf, kvm_geterr()); + exit(1); + } + if ((c = kvm_nlist(nl)) != 0) { + if (c > 0) { + (void)fprintf(stderr, + "slstat: undefined symbols in %s:", system); + for (c = 0; c < sizeof(nl)/sizeof(nl[0]); c++) + if (nl[c].n_type == 0) + fprintf(stderr, " %s", nl[c].n_name); + (void)fputc('\n', stderr); + } else + (void)fprintf(stderr, "slstat: kvm_nlist: %s\n", + kvm_geterr()); + exit(1); + } + intpr(); + exit(0); +} + +#define V(offset) ((line % 20)? ((sc->offset - osc->offset) / (rflag ? interval : 1)) : sc->offset) +#define AMT (sizeof(*sc) - 2 * sizeof(sc->sc_comp.tstate)) + +usage() +{ + static char umsg[] = + "usage: slstat [-i interval] [-v] [unit] [system] [core]\n"; + + fprintf(stderr, umsg); + exit(1); +} + +u_char signalled; /* set if alarm goes off "early" */ + +/* + * Print a running summary of interface statistics. + * Repeat display every interval seconds, showing statistics + * collected over that interval. Assumes that interval is non-zero. + * First line printed at top of screen is always cumulative. + */ +intpr() +{ + register int line = 0; + int oldmask; + void catchalarm(); + struct sl_softc *sc, *osc; + off_t addr; + + addr = nl[N_SOFTC].n_value + unit * sizeof(struct sl_softc); + sc = (struct sl_softc *)malloc(AMT); + osc = (struct sl_softc *)malloc(AMT); + bzero((char *)osc, AMT); + + while (1) { + if (kread(addr, (char *)sc, AMT) < 0) + perror("kmem read"); + (void)signal(SIGALRM, catchalarm); + signalled = 0; + (void)alarm(interval); + + if ((line % 20) == 0) { + printf("%8.8s %6.6s %6.6s %6.6s %6.6s", + "in", "pack", "comp", "uncomp", "unknwn"); + if (vflag) + printf(" %6.6s %6.6s %6.6s", + "toss", "other", "err"); + printf(" | %8.8s %6.6s %6.6s %6.6s %6.6s", + "out", "pack", "comp", "uncomp", "other"); + if (vflag) + printf(" %6.6s %6.6s %6.6s %6.6s", + "search", "miss", "err", "coll"); + putchar('\n'); + } + printf("%8u %6d %6u %6u %6u", + V(sc_bytesrcvd), + V(sc_if.if_ipackets), + V(sc_comp.sls_compressedin), + V(sc_comp.sls_uncompressedin), + V(sc_comp.sls_errorin)); + if (vflag) + printf(" %6u %6u %6u", + V(sc_comp.sls_tossed), + V(sc_if.if_ipackets) - + V(sc_comp.sls_compressedin) - + V(sc_comp.sls_uncompressedin) - + V(sc_comp.sls_errorin), + V(sc_if.if_ierrors)); + printf(" | %8u %6d %6u %6u %6u", + V(sc_bytessent) / (rflag ? interval : 1), + V(sc_if.if_opackets), + V(sc_comp.sls_compressed), + V(sc_comp.sls_packets) - V(sc_comp.sls_compressed), + V(sc_if.if_opackets) - V(sc_comp.sls_packets)); + if (vflag) + printf(" %6u %6u %6u %6u", + V(sc_comp.sls_searches), + V(sc_comp.sls_misses), + V(sc_if.if_oerrors), + V(sc_if.if_collisions)); + putchar('\n'); + fflush(stdout); + line++; + oldmask = sigblock(sigmask(SIGALRM)); + if (! signalled) { + sigpause(0); + } + sigsetmask(oldmask); + signalled = 0; + (void)alarm(interval); + bcopy((char *)sc, (char *)osc, AMT); + } +} + +/* + * Called if an interval expires before sidewaysintpr has completed a loop. + * Sets a flag to not wait for the alarm. + */ +void +catchalarm() +{ + signalled = 1; +} + +#include +#include + +int kd; + +kopen(system, kmemf, errstr) + char *system; + char *kmemf; + char *errstr; +{ + if (strcmp(system, _PATH_UNIX) == 0 && + strcmp(kmemf, _PATH_KMEM) == 0) { + system = 0; + kmemf = 0; + } + kd = kvm_openfiles(system, kmemf, (void *)0); + if (kd == 0) + return -1; + + return 0; +} + +int +knlist(system, nl, errstr) + char *system; + struct nlist *nl; + char *errstr; +{ + if (kd == 0) + /* kopen() must be called first */ + abort(); + + if (kvm_nlist(nl) < 0 || nl[0].n_type == 0) { + fprintf(stderr, "%s: %s: no namelist\n", errstr, system); + return -1; + } + return 0; +} + +int +kread(addr, buf, size) + off_t addr; + char *buf; + int size; +{ + if (kvm_read((char *)addr, buf, size) != size) + return -1; + return 0; +}