From 6614c5a7b35ffc8ac375314a6c0ea7bb1c32ea3f Mon Sep 17 00:00:00 2001 From: glass Date: Tue, 15 Nov 1994 07:20:52 +0000 Subject: [PATCH] pppstats(8) and slstats(8) has been rewritten and merged semantics and interface now follow the iostat/vmstat standard for statistics reporting. man page rewritten to match new semantics and interface. now shared. --- usr.sbin/pppd/pppstats/Makefile | 4 +- usr.sbin/pppd/pppstats/pppstats.8 | 177 +++++++++++---- usr.sbin/pppd/pppstats/pppstats.c | 366 +++++++++++++++++------------- usr.sbin/slstats/Makefile | 6 +- 4 files changed, 355 insertions(+), 198 deletions(-) diff --git a/usr.sbin/pppd/pppstats/Makefile b/usr.sbin/pppd/pppstats/Makefile index c7eea00a0ff8..3396573fb145 100644 --- a/usr.sbin/pppd/pppstats/Makefile +++ b/usr.sbin/pppd/pppstats/Makefile @@ -1,10 +1,12 @@ -# $Id: Makefile,v 1.5 1994/08/26 05:13:11 paulus Exp $ +# $Id: Makefile,v 1.6 1994/11/15 07:20:52 glass Exp $ PROG= pppstats SRCS= pppstats.c +CFLAGS+= -DPPP LDADD= -lkvm DPADD= ${LIBKVM} MAN8= pppstats.0 +MLINKS= pppstats.8 slstats.8 BINMODE=2555 BINGRP= kmem BINDIR= /usr/sbin diff --git a/usr.sbin/pppd/pppstats/pppstats.8 b/usr.sbin/pppd/pppstats/pppstats.8 index 7d82762d35eb..1936dd217e6e 100644 --- a/usr.sbin/pppd/pppstats/pppstats.8 +++ b/usr.sbin/pppd/pppstats/pppstats.8 @@ -1,39 +1,140 @@ -.\" @(#) $Id: pppstats.8,v 1.1 1994/08/26 05:13:13 paulus Exp $ -.TH PPPSTATS 8 "23 Aug 1994" -.SH NAME -pppstats \- print PPP statistics -.SH SYNOPSIS -.B pppstats -[ -.B -v -] [ -.B -i -.I -] [ -.I -] -.ti 12 -.br -[ -.I objectfile -[ -.I corefile -]] -.SH DESCRIPTION -.B pppstats -prints PPP-related statistics. -.PP +.\" @(#) $Header: /cvsroot/src/usr.sbin/pppd/pppstats/Attic/pppstats.8,v 1.2 1994/11/15 07:28:02 glass Exp $ (LBL) +.Dd November 15, 1994 +.Dt PPPSTATS/SLSTATS 8 +.Sh NAME +.Nm pppstats , +.Nm slstats +.Nd report statistics for the specified PPP or SLIP interface +.Sh SYNOPSIS +.Nm pppstats +.Op Fl v +.Op Fl c Ar count +.Op Fl w Ar wait +.Op Fl M Ar core +.Op Fl N Ar system +.Op Ar interface +.Nm slstats +.Op Fl v +.Op Fl c Ar count +.Op Fl w Ar wait +.Op Fl M Ar core +.Op Fl N Ar system +.Op Ar interface +.Sh DESCRIPTION +.Pp +The +.Nm pppstats +utility reports PPP-related statistics for the specified PPP +.Ar interface . +If the +.Ar interface +is unspecified, it will default to ppp0. +.Pp The -.B -v -flag causes -.B pppstats -to display additional statistics, such as the number of packets tossed. -.PP -The -.B -i -flag is used to specify the interval between printouts. The default is -5 seconds. -.PP -.B pppstats -must be installed set-group-id to kmem, or the user must have read -access to /dev/kmem. +.Nm slstats +utility reports SLIP-related statistics for the specified SLIP +.Ar interface . +If the +.Ar interface +is unspecified, it will default to sl0. +.Pp +Otherwise +.Nm pppstats +and +.Nm slstats +function identically. Both programs will report interface-specific +statistics at regular intervals. The display is split horizontally +into input and output sections containing columns of statistics +describing the properties and volume of packets received and +transmitted by the interface. +.Pp +The first report will consist of a snapshot of the interface's +statistics. Further output, if any, will describe activity between +report intervals. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl c Ar count +Repeat the display +.Ar count +times. The first display is for the time since a reboot and each +subsequent report is for the time period since the last display. If +no +.Ar wait +interval is specified, the default is 5 seconds. +.It Fl v +Display additional statistics demonstrating the efficacy of VJ header +compression and providing more explicit information on failure +distribution. +.It Fl w Ar wait +Pause +.Ar wait +seconds between each display. If no repeat +.Ar count +is specified, the default is infinity. +.It Fl M Ar core +Extract values associated with the name list from the specified core +instead of the default +.Pa /dev/kmem . +.It Fl N Ar system +Extract the name list from the specified system instead of the default +.Pa /netbsd . +.El +.Pp +The following fields are printed on the input side: +.Bl -tag -width search +.It Li IN +The total number of bytes received by this interface. +.It Li PACK +The total number of packets received by this interface. +.It Li COMP +The number of compressed TCP packets received by this interface. +.It Li UNCOMP +The number of uncompressed TCP packets received by this interface. +.It Li ERR +The number of packets received by this interface of unknown type. +.It Li TOSS +The number of packets dropped on reception by this interface. Only +reported when the +.Fl v +option is specified. +.It Li IP +The total number of non-TCP packets received by this interface. Only +reported when the +.Fl v +option is specified. +.El +.Pp +The following fields are printed on the output side: +.Bl -tag -width search +.It Li OUT +The total number of bytes transmitted from this interface. +.It Li PACK +The total number of packets transmitted from this interface. +.It Li COMP +The number of TCP packets compressed and then transmitted from this interface. +.It Li UNCOMP +The number of uncompressed TCP packets transmitted from this interface. +.It Li IP +The total number of non-TCP packets transmitted from this interface. +.It Li SEARCH +The number of searches for the cached header entry for a compressed +packet. Only reported when the +.Fl v +option is specified. +.It Li MISS +The number of failed searches for the cached header entry for a +compressed packet. Only reported when the +.Fl v +option is specified. +.El +.Sh FILES +.Bl -tag -width /dev/kmem -compact +.It Pa /netbsd +Default kernel namelist. +.It Pa /dev/kmem +Default memory file. +.El +.Sh SEE ALSO +.Xr pppd 8 , +.Xr slattach 8 diff --git a/usr.sbin/pppd/pppstats/pppstats.c b/usr.sbin/pppd/pppstats/pppstats.c index 66b2a9390ef5..d3be95b212bb 100644 --- a/usr.sbin/pppd/pppstats/pppstats.c +++ b/usr.sbin/pppd/pppstats/pppstats.c @@ -1,13 +1,16 @@ /* - * print PPP statistics: - * pppstats [-i interval] [-v] [interface] [system] [core] + * print PPP interface statistics: + * pppstats [-v] [-c count] [-w wait] [-M core] [-N system ] [interface] + * print SLIP interface statistics: + * slstats [-v] [-c count] [-w wait] [-M core] [-N system ] [interface] + * * * Brad Parker (brad@cayman.com) 6/92 * * from the original "slstats" by Van Jacobson * - * Copyright (c) 1989 Regents of the University of California. - * All rights reserved. + * 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 @@ -21,118 +24,89 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: + * Van Jacobson (van@ee.lbl.gov), Dec 31, 1989: * - Initial distribution. */ #ifndef lint -static char rcsid[] = "$Id: pppstats.c,v 1.7 1994/05/14 19:00:35 cgd Exp $"; +/*static char rcsid[] = + "@(#) $Header: /cvsroot/src/usr.sbin/pppd/pppstats/Attic/pppstats.c,v 1.8 1994/11/15 07:20:54 glass Exp $ (LBL)";*/ +static char rcsid[] = "$Id: pppstats.c,v 1.8 1994/11/15 07:20:54 glass Exp $"; #endif -#include -#include -#include -#include -#include -#include -#include #include #include #include #include +#include #include + #include #include #include #include #include -#define VJC 1 +#define VJC 1 /* XXX */ +#define INET /* XXX */ + #include +#include #include -char *kmemf; -kvm_t *kd; +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define V(offset) ((line != 0) ? sc->offset - osc->offset : sc->offset) + +#ifdef PPP +#define STRUCT struct ppp_softc +#define NLIST_ENTRY "_ppp_softc" +#define INTERFACE_PREFIX "ppp" +#else +#define STRUCT struct sl_softc +#define NLIST_ENTRY "_sl_softc" +#define INTERFACE_PREFIX "sl" +#endif struct nlist nl[] = { #define N_SOFTC 0 - { "_ppp_softc" }, + { NLIST_ENTRY }, "", }; -char *system = _PATH_UNIX; - -int kflag; -int vflag; -unsigned interval = 5; -int unit; - -extern char *malloc(); - -main(argc, argv) - int argc; - char *argv[]; -{ - --argc; ++argv; - while (argc > 0) { - if (strcmp(argv[0], "-v") == 0) { - ++vflag; - ++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++; - } - } - /* BSD4.3+ */ - kd = kvm_open(system, kmemf, (char *)0, O_RDONLY, "pppstats"); - if (kd == NULL) - exit(1); - - if (kvm_nlist(kd, nl)) { - fprintf(stderr, "pppstats: can't find symbols in nlist\n"); - exit(1); - } - intpr(); - exit(0); -} +kvm_t *kd; +char *progname, interface[IFNAMSIZ]; +int count, infinite, interval, signalled, unit, vflag; +void usage() { - fprintf(stderr,"usage: pppstats [-i interval] [-v] [unit] [system] [core]\n"); + fprintf(stderr, + "usage: %s [-v] [-c count] [-w wait] [-M core] [-N system ] [interface]\n", + progname); exit(1); } -u_char signalled; /* set if alarm goes off "early" */ - -#define V(offset) ((line % 20)? sc->offset - osc->offset : sc->offset) - -#define STRUCT struct ppp_softc -#define COMP sc_comp -#define STATS sc_if +/* + * Called if an interval expires before intpr has completed a loop. + * Sets a flag to not wait for the alarm. + */ +void +catchalarm() +{ + signalled = 1; +} /* * Print a running summary of interface statistics. @@ -140,90 +114,168 @@ u_char signalled; /* set if alarm goes off "early" */ * collected over that interval. Assumes that interval is non-zero. * First line printed at top of screen is always cumulative. */ +void intpr() { - register int line = 0; - int oldmask; -#ifdef __STDC__ - void catchalarm(int); -#else - void catchalarm(); -#endif + STRUCT *sc, *osc; + off_t addr; + int oldmask, line = 0; - STRUCT *sc, *osc; - - nl[N_SOFTC].n_value += unit * sizeof(STRUCT); - sc = (STRUCT *)malloc(sizeof(STRUCT)); - osc = (STRUCT *)malloc(sizeof(STRUCT)); - - bzero((char *)osc, sizeof(STRUCT)); + addr = nl[N_SOFTC].n_value + unit * sizeof(STRUCT); + sc = (STRUCT *) malloc(sizeof(STRUCT)); + osc = (STRUCT *) malloc(sizeof(STRUCT)); + memset(osc, 0, sizeof(STRUCT)); while (1) { - if (kvm_read(kd, nl[N_SOFTC].n_value, sc, - sizeof(STRUCT)) != sizeof(STRUCT)) { - perror("kvm_read"); - exit(1); - } + if (kvm_read(kd, addr, sc, + sizeof(STRUCT)) != sizeof(STRUCT)) + errx(1, "reading statistics: %s", kvm_geterr(kd)); + + (void)signal(SIGALRM, catchalarm); + signalled = 0; + (void)alarm(interval); - (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", "ERR"); + if (vflag) + printf(" %6.6s %6.6s", "TOSS", "IP"); + printf(" | %8.8s %6.6s %6.6s %6.6s %6.6s", + "OUT", "PACK", "COMP", "UNCOMP", "IP"); + if (vflag) + printf(" %6.6s %6.6s", "SEARCH", "MISS"); + putchar('\n'); + } + printf("%8u %6d %6u %6u %6u", + V(sc_if.if_ibytes), + 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", + 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)); + printf(" | %8u %6d %6u %6u %6u", + V(sc_if.if_obytes), + 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", + V(sc_comp.sls_searches), + V(sc_comp.sls_misses)); - if ((line % 20) == 0) { - printf("%6.6s %6.6s %6.6s %6.6s %6.6s", - "in", "pack", "comp", "uncomp", "err"); - if (vflag) - printf(" %6.6s %6.6s", "toss", "ip"); - printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s", - "out", "pack", "comp", "uncomp", "ip"); - if (vflag) - printf(" %6.6s %6.6s", "search", "miss"); putchar('\n'); - } + fflush(stdout); + line++; - printf("%6d %6d %6d %6d %6d", - V(STATS.if_ibytes), - V(STATS.if_ipackets), - V(COMP.sls_compressedin), - V(COMP.sls_uncompressedin), - V(COMP.sls_errorin)); - if (vflag) - printf(" %6d %6d", - V(COMP.sls_tossed), - V(STATS.if_ipackets) - V(COMP.sls_compressedin) - - V(COMP.sls_uncompressedin) - V(COMP.sls_errorin)); - printf(" | %6d %6d %6d %6d %6d", - V(STATS.if_obytes), - V(STATS.if_opackets), - V(COMP.sls_compressed), - V(COMP.sls_packets) - V(COMP.sls_compressed), - V(STATS.if_opackets) - V(COMP.sls_packets)); - if (vflag) - printf(" %6d %6d", - V(COMP.sls_searches), - V(COMP.sls_misses)); - - 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, sizeof(STRUCT)); + count--; + if (!infinite && !count) + break; + oldmask = sigblock(sigmask(SIGALRM)); + if (signalled == 0) + sigpause(0); + sigsetmask(oldmask); + signalled = 0; + (void)alarm(interval); + memcpy(osc, sc, sizeof(STRUCT)); } } -/* - * Called if an interval expires before sidewaysintpr has completed a loop. - * Sets a flag to not wait for the alarm. - */ -void catchalarm(arg) -int arg; +int +main(argc, argv) + int argc; + char *argv[]; { - signalled = 1; + char errbuf[_POSIX2_LINE_MAX], tmp[IFNAMSIZ]; + struct ifreq ifr; + char *kernel, *core; + int c, s; + + kernel = core = NULL; + strcpy(interface, INTERFACE_PREFIX); + strcat(interface, "0"); + if ((progname = strrchr(argv[0], '/')) == NULL) + progname = argv[0]; + else + ++progname; + + while ((c = getopt(argc, argv, ":c:vw:M:N:")) != -1) { + switch (c) { + case 'c': + count = atoi(optarg); + if (count <= 0) + usage(); + break; + case 'v': + ++vflag; + break; + case 'w': + interval = atoi(optarg); + if (interval <= 0) + usage(); + break; + case 'M': + core = optarg; + break; + case 'N': + kernel = optarg; + break; + case ':': + fprintf(stderr, + "option -%c requires an argument\n", optopt); + usage(); + break; + case '?': + fprintf(stderr, "unrecognized option: -%c\n", optopt); + usage(); + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (!interval && count) + interval = 5; + if (interval && !count) + infinite = 1; + if (!interval && !count) + count = 1; + + if (argc > 1) + usage(); + if (argc > 0) { + if (strlen(argv[0]) > sizeof(interface)) + errx(1, "invalid interface specified %s", interface); + strcpy(interface, argv[0]); + } + + strcpy(tmp, INTERFACE_PREFIX); + strcat(tmp, "%d"); + if (sscanf(interface, tmp, &unit) != 1) + errx(1, "invalid interface '%s' specified", interface); + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) + err(1, "creating socket"); + strcpy(ifr.ifr_name, interface); + if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) + errx(1, "unable to confirm existence of interface '%s'", + interface); + close(s); + + kd = kvm_openfiles(kernel, core, NULL, O_RDONLY, errbuf); + if (kd == NULL) + errx(1, "%s", errbuf); + if (kvm_nlist(kd, nl) != 0) + errx(1, "%s", kvm_geterr(kd)); + + intpr(); + exit(0); } diff --git a/usr.sbin/slstats/Makefile b/usr.sbin/slstats/Makefile index 6ee9a761ee04..76238719f7be 100644 --- a/usr.sbin/slstats/Makefile +++ b/usr.sbin/slstats/Makefile @@ -1,8 +1,10 @@ # from: @(#)Makefile 5.6 (Berkeley) 4/23/91 -# $Id: Makefile,v 1.3 1994/01/28 01:00:24 cgd Exp $ +# $Id: Makefile,v 1.4 1994/11/15 07:21:40 glass Exp $ PROG= slstats -MAN8= slstats.0 +SRCS= pppstats.c +.PATH: ${.CURDIR}/../pppd/pppstats +NOMAN= DPADD= ${LIBKVM} LDADD= -lkvm BINGRP= kmem