-.\" $OpenBSD: nfsstat.1,v 1.7 2000/04/18 15:24:26 mickey Exp $
+.\" $OpenBSD: nfsstat.1,v 1.8 2000/04/18 20:17:54 mickey Exp $
.\" $NetBSD: nfsstat.1,v 1.8 1996/03/03 17:21:28 thorpej Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
statistics
.Sh SYNOPSIS
.Nm nfsstat
+.Op Fl M Ar core
+.Op Fl N Ar system
.Op Fl w Ar wait
.Op Fl s
.Op Fl c
.Pp
The options are as follows:
.Bl -tag -width Ds
+.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 /bsd .
.It Fl w Ar wait
Display a shorter summary of
.Tn NFS
.It Fl s
Display server statistics only.
.It Fl c
+.Sh FILES
+.Bl -tag -width /dev/kmem -compact
+.It Pa /bsd
+default kernel namelist
+.It Pa /dev/kmem
+default memory file
+.El
Display client statistics only.
.El
.Sh SEE ALSO
-/* $OpenBSD: nfsstat.c,v 1.8 2000/04/18 15:24:26 mickey Exp $ */
+/* $OpenBSD: nfsstat.c,v 1.9 2000/04/18 20:17:54 mickey Exp $ */
/* $NetBSD: nfsstat.c,v 1.7 1996/03/03 17:21:30 thorpej Exp $ */
/*
static char sccsid[] = "from: @(#)nfsstat.c 8.1 (Berkeley) 6/6/93";
static char *rcsid = "$NetBSD: nfsstat.c,v 1.7 1996/03/03 17:21:30 thorpej Exp $";
#else
-static char *rcsid = "$OpenBSD: nfsstat.c,v 1.8 2000/04/18 15:24:26 mickey Exp $";
+static char *rcsid = "$OpenBSD: nfsstat.c,v 1.9 2000/04/18 20:17:54 mickey Exp $";
#endif
#endif /* not lint */
#include <nfs/nfsproto.h>
#include <nfs/nfs.h>
#include <signal.h>
+#include <fcntl.h>
+#include <ctype.h>
#include <errno.h>
+#include <kvm.h>
+#include <nlist.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
+#include <paths.h>
#include <err.h>
#define SHOW_SERVER 0x01
#define SHOW_CLIENT 0x02
#define SHOW_ALL (SHOW_SERVER | SHOW_CLIENT)
+struct nlist nl[] = {
+#define N_NFSSTAT 0
+ { "_nfsstats" },
+ { "" },
+};
+kvm_t *kd;
u_char signalled; /* set if alarm goes off "early" */
int nfs_id;
void getnfsstats __P((struct nfsstats *));
-static __inline void printhdr __P((void));
-static __inline void intpr __P((u_int));
-static __inline void sidewaysintpr __P((u_int, u_int));
-static __inline void usage __P((void));
+void printhdr __P((void));
+void intpr __P((u_int));
+void sidewaysintpr __P((u_int, u_int));
+void usage __P((void));
int
main(argc, argv)
char *p;
u_int interval;
u_int display = SHOW_ALL;
+ char *memf, *nlistf;
int ch;
interval = 0;
+ memf = nlistf = NULL;
while ((ch = getopt(argc, argv, "M:N:w:sc")) != -1)
switch(ch) {
case 'M':
+ memf = optarg;
+ break;
case 'N':
- /* compat */
+ nlistf = optarg;
break;
case 'w':
interval = (u_int)strtol(optarg, &p, 0);
argc -= optind;
argv += optind;
- {
+#define BACKWARD_COMPATIBILITY
+#ifdef BACKWARD_COMPATIBILITY
+ if (*argv) {
+ interval = atoi(*argv);
+ if (*++argv) {
+ nlistf = *argv;
+ if (*++argv)
+ memf = *argv;
+ }
+ }
+#endif
+ if (nlistf || memf) {
+ char errbuf[_POSIX2_LINE_MAX];
+
+ if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == 0)
+ errx(1, "nfsstat: %s", errbuf);
+ if (kvm_nlist(kd, nl) != 0)
+ errx(1, "kvm_nlist: can't get names");
+ } else {
int mib[3];
size_t len;
errx(1, "cannot find nfs filesystem id");
}
-#define BACKWARD_COMPATIBILITY
-#ifdef BACKWARD_COMPATIBILITY
- if (*argv)
- interval = atoi(*argv);
-#endif
if (interval)
sidewaysintpr(interval, display);
else
getnfsstats(p)
struct nfsstats *p;
{
- int mib[3];
- size_t len = sizeof(*p);
+ if (kd) {
+ if (kvm_read(kd, nl[N_NFSSTAT].n_value, p, sizeof(*p)) != sizeof(*p))
+ errx(1, "kvm_read failed");
+ } else {
+ int mib[3];
+ size_t len = sizeof(*p);
- mib[0] = CTL_VFS;
- mib[1] = nfs_id; /* 2 */
- mib[2] = NFS_NFSSTATS;
+ mib[0] = CTL_VFS;
+ mib[1] = nfs_id; /* 2 */
+ mib[2] = NFS_NFSSTATS;
- if (sysctl(mib, 3, p, &len, NULL, 0))
- err(1, "sysctl");
+ if (sysctl(mib, 3, p, &len, NULL, 0))
+ err(1, "sysctl");
+ }
}
/*
* Print a description of the nfs stats.
*/
-static __inline void
+void
intpr(display)
u_int display;
{
* collected over that interval. Assumes that interval is non-zero.
* First line printed at top of screen is always cumulative.
*/
-static __inline void
+void
sidewaysintpr(interval, display)
u_int interval;
u_int display;
/*NOTREACHED*/
}
-static __inline void
+void
printhdr()
{
printf(" %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s\n",
signalled = 1;
}
-static __inline void
+void
usage()
{
extern char *__progname;
- fprintf(stderr, "usage: %s [-s] [-c] [-w interval]\n", __progname);
+ fprintf(stderr,
+ "usage: %s [-M core] [-N system] [-s] [-c] [-w interval]\n",
+ __progname);
exit(1);
}