19b50d902SRodney W. Grimes /* 29b50d902SRodney W. Grimes * Copyright (c) 1983, 1989, 1993 39b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 49b50d902SRodney W. Grimes * 59b50d902SRodney W. Grimes * This code is derived from software contributed to Berkeley by 69b50d902SRodney W. Grimes * Rick Macklem at The University of Guelph. 79b50d902SRodney W. Grimes * 89b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 99b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 109b50d902SRodney W. Grimes * are met: 119b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 129b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 139b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 149b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 159b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 169b50d902SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 179b50d902SRodney W. Grimes * must display the following acknowledgement: 189b50d902SRodney W. Grimes * This product includes software developed by the University of 199b50d902SRodney W. Grimes * California, Berkeley and its contributors. 209b50d902SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 219b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 229b50d902SRodney W. Grimes * without specific prior written permission. 239b50d902SRodney W. Grimes * 249b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 259b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 269b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 279b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 289b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 299b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 309b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 319b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 329b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 339b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 349b50d902SRodney W. Grimes * SUCH DAMAGE. 359b50d902SRodney W. Grimes */ 369b50d902SRodney W. Grimes 379b50d902SRodney W. Grimes #ifndef lint 389b50d902SRodney W. Grimes static char copyright[] = 399b50d902SRodney W. Grimes "@(#) Copyright (c) 1983, 1989, 1993\n\ 409b50d902SRodney W. Grimes The Regents of the University of California. All rights reserved.\n"; 419b50d902SRodney W. Grimes #endif /* not lint */ 429b50d902SRodney W. Grimes 439b50d902SRodney W. Grimes #ifndef lint 44eae79dd1SBruce Evans #if 0 45eae79dd1SBruce Evans static char sccsid[] = "@(#)nfsstat.c 8.2 (Berkeley) 3/31/95"; 46eae79dd1SBruce Evans #endif 4707e532e7SGarrett Wollman static const char rcsid[] = 48c3aac50fSPeter Wemm "$FreeBSD$"; 499b50d902SRodney W. Grimes #endif /* not lint */ 509b50d902SRodney W. Grimes 519b50d902SRodney W. Grimes #include <sys/param.h> 529b50d902SRodney W. Grimes #include <sys/mount.h> 535a4838fcSPoul-Henning Kamp #include <sys/time.h> 5407e532e7SGarrett Wollman #include <sys/sysctl.h> 55a62dc406SDoug Rabson #include <nfs/rpcv2.h> 56a62dc406SDoug Rabson #include <nfs/nfsproto.h> 579b50d902SRodney W. Grimes #include <nfs/nfs.h> 589b50d902SRodney W. Grimes #include <signal.h> 599b50d902SRodney W. Grimes #include <fcntl.h> 609b50d902SRodney W. Grimes #include <ctype.h> 619b50d902SRodney W. Grimes #include <errno.h> 629b50d902SRodney W. Grimes #include <kvm.h> 639c9f2eefSThomas Moestl #include <limits.h> 649b50d902SRodney W. Grimes #include <nlist.h> 659b50d902SRodney W. Grimes #include <unistd.h> 669b50d902SRodney W. Grimes #include <stdio.h> 679b50d902SRodney W. Grimes #include <stdlib.h> 689b50d902SRodney W. Grimes #include <string.h> 699b50d902SRodney W. Grimes #include <paths.h> 7007e532e7SGarrett Wollman #include <err.h> 719b50d902SRodney W. Grimes 729b50d902SRodney W. Grimes struct nlist nl[] = { 739b50d902SRodney W. Grimes #define N_NFSSTAT 0 749b50d902SRodney W. Grimes { "_nfsstats" }, 759b50d902SRodney W. Grimes "", 769b50d902SRodney W. Grimes }; 779b50d902SRodney W. Grimes kvm_t *kd; 789b50d902SRodney W. Grimes 7907e532e7SGarrett Wollman static int deadkernel = 0; 804893ef0bSMatthew Dillon static int widemode = 0; 8107e532e7SGarrett Wollman 824893ef0bSMatthew Dillon void intpr __P((int, int)); 834893ef0bSMatthew Dillon void printhdr __P((int, int)); 844893ef0bSMatthew Dillon void sidewaysintpr __P((u_int, int, int)); 85a62dc406SDoug Rabson void usage __P((void)); 864893ef0bSMatthew Dillon char *sperc1 __P((int, int)); 874893ef0bSMatthew Dillon char *sperc2 __P((int, int)); 884893ef0bSMatthew Dillon 894893ef0bSMatthew Dillon #define DELTA(field) (nfsstats.field - lastst.field) 909b50d902SRodney W. Grimes 919b50d902SRodney W. Grimes main(argc, argv) 929b50d902SRodney W. Grimes int argc; 939b50d902SRodney W. Grimes char **argv; 949b50d902SRodney W. Grimes { 959b50d902SRodney W. Grimes u_int interval; 964893ef0bSMatthew Dillon int clientOnly = -1; 974893ef0bSMatthew Dillon int serverOnly = -1; 989b50d902SRodney W. Grimes int ch; 999b50d902SRodney W. Grimes char *memf, *nlistf; 1009c9f2eefSThomas Moestl char errbuf[_POSIX2_LINE_MAX]; 1019b50d902SRodney W. Grimes 1029b50d902SRodney W. Grimes interval = 0; 1039b50d902SRodney W. Grimes memf = nlistf = NULL; 1044893ef0bSMatthew Dillon while ((ch = getopt(argc, argv, "csWM:N:w:")) != -1) 1059b50d902SRodney W. Grimes switch(ch) { 1069b50d902SRodney W. Grimes case 'M': 1079b50d902SRodney W. Grimes memf = optarg; 1089b50d902SRodney W. Grimes break; 1099b50d902SRodney W. Grimes case 'N': 1109b50d902SRodney W. Grimes nlistf = optarg; 1119b50d902SRodney W. Grimes break; 1124893ef0bSMatthew Dillon case 'W': 1134893ef0bSMatthew Dillon widemode = 1; 1144893ef0bSMatthew Dillon break; 1159b50d902SRodney W. Grimes case 'w': 1169b50d902SRodney W. Grimes interval = atoi(optarg); 1179b50d902SRodney W. Grimes break; 1184893ef0bSMatthew Dillon case 'c': 1194893ef0bSMatthew Dillon clientOnly = 1; 1204893ef0bSMatthew Dillon if (serverOnly < 0) 1214893ef0bSMatthew Dillon serverOnly = 0; 1224893ef0bSMatthew Dillon break; 1234893ef0bSMatthew Dillon case 's': 1244893ef0bSMatthew Dillon serverOnly = 1; 1254893ef0bSMatthew Dillon if (clientOnly < 0) 1264893ef0bSMatthew Dillon clientOnly = 0; 1274893ef0bSMatthew Dillon break; 1289b50d902SRodney W. Grimes case '?': 1299b50d902SRodney W. Grimes default: 1309b50d902SRodney W. Grimes usage(); 1319b50d902SRodney W. Grimes } 1329b50d902SRodney W. Grimes argc -= optind; 1339b50d902SRodney W. Grimes argv += optind; 1349b50d902SRodney W. Grimes 1359b50d902SRodney W. Grimes #define BACKWARD_COMPATIBILITY 1369b50d902SRodney W. Grimes #ifdef BACKWARD_COMPATIBILITY 1379b50d902SRodney W. Grimes if (*argv) { 1389b50d902SRodney W. Grimes interval = atoi(*argv); 1399b50d902SRodney W. Grimes if (*++argv) { 1409b50d902SRodney W. Grimes nlistf = *argv; 1419b50d902SRodney W. Grimes if (*++argv) 1429b50d902SRodney W. Grimes memf = *argv; 1439b50d902SRodney W. Grimes } 1449b50d902SRodney W. Grimes } 1459b50d902SRodney W. Grimes #endif 14607e532e7SGarrett Wollman if (nlistf != NULL || memf != NULL) { 14707e532e7SGarrett Wollman deadkernel = 1; 1489b50d902SRodney W. Grimes 14907e532e7SGarrett Wollman if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, 15007e532e7SGarrett Wollman errbuf)) == 0) { 15107e532e7SGarrett Wollman errx(1, "kvm_openfiles: %s", errbuf); 1529b50d902SRodney W. Grimes } 1539b50d902SRodney W. Grimes if (kvm_nlist(kd, nl) != 0) { 15407e532e7SGarrett Wollman errx(1, "kvm_nlist: can't get names"); 15507e532e7SGarrett Wollman } 1569b50d902SRodney W. Grimes } 1579b50d902SRodney W. Grimes 1589b50d902SRodney W. Grimes if (interval) 1594893ef0bSMatthew Dillon sidewaysintpr(interval, clientOnly, serverOnly); 1609b50d902SRodney W. Grimes else 1614893ef0bSMatthew Dillon intpr(clientOnly, serverOnly); 1629b50d902SRodney W. Grimes exit(0); 1639b50d902SRodney W. Grimes } 1649b50d902SRodney W. Grimes 1659b50d902SRodney W. Grimes /* 16607e532e7SGarrett Wollman * Read the nfs stats using sysctl(3) for live kernels, or kvm_read 16707e532e7SGarrett Wollman * for dead ones. 16807e532e7SGarrett Wollman */ 16907e532e7SGarrett Wollman void 170a62dc406SDoug Rabson readstats(stp) 171a62dc406SDoug Rabson struct nfsstats *stp; 17207e532e7SGarrett Wollman { 17307e532e7SGarrett Wollman if(deadkernel) { 17407e532e7SGarrett Wollman if(kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value, stp, 17507e532e7SGarrett Wollman sizeof *stp) < 0) { 17607e532e7SGarrett Wollman err(1, "kvm_read"); 17707e532e7SGarrett Wollman } 17807e532e7SGarrett Wollman } else { 17983d8891dSBruce Evans int name[3]; 18007e532e7SGarrett Wollman size_t buflen = sizeof *stp; 18183d8891dSBruce Evans struct vfsconf vfc; 18207e532e7SGarrett Wollman 18383d8891dSBruce Evans if (getvfsbyname("nfs", &vfc) < 0) 18483d8891dSBruce Evans err(1, "getvfsbyname: NFS not compiled into kernel"); 18583d8891dSBruce Evans name[0] = CTL_VFS; 18683d8891dSBruce Evans name[1] = vfc.vfc_typenum; 18783d8891dSBruce Evans name[2] = NFS_NFSSTATS; 18883d8891dSBruce Evans if (sysctl(name, 3, stp, &buflen, (void *)0, (size_t)0) < 0) { 18907e532e7SGarrett Wollman err(1, "sysctl"); 19007e532e7SGarrett Wollman } 19107e532e7SGarrett Wollman } 19207e532e7SGarrett Wollman } 19307e532e7SGarrett Wollman 19407e532e7SGarrett Wollman /* 1959b50d902SRodney W. Grimes * Print a description of the nfs stats. 1969b50d902SRodney W. Grimes */ 1979b50d902SRodney W. Grimes void 1984893ef0bSMatthew Dillon intpr(int clientOnly, int serverOnly) 1999b50d902SRodney W. Grimes { 2009b50d902SRodney W. Grimes struct nfsstats nfsstats; 2019b50d902SRodney W. Grimes 20207e532e7SGarrett Wollman readstats(&nfsstats); 20307e532e7SGarrett Wollman 2044893ef0bSMatthew Dillon if (clientOnly) { 2059b50d902SRodney W. Grimes printf("Client Info:\n"); 2069b50d902SRodney W. Grimes printf("Rpc Counts:\n"); 2079b50d902SRodney W. Grimes printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", 2089b50d902SRodney W. Grimes "Getattr", "Setattr", "Lookup", "Readlink", "Read", 2099b50d902SRodney W. Grimes "Write", "Create", "Remove"); 2109b50d902SRodney W. Grimes printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", 2119b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_GETATTR], 2129b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_SETATTR], 2139b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_LOOKUP], 2149b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_READLINK], 2159b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_READ], 2169b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_WRITE], 2179b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_CREATE], 2189b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_REMOVE]); 2199b50d902SRodney W. Grimes printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", 2209b50d902SRodney W. Grimes "Rename", "Link", "Symlink", "Mkdir", "Rmdir", 221a62dc406SDoug Rabson "Readdir", "RdirPlus", "Access"); 2229b50d902SRodney W. Grimes printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", 2239b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_RENAME], 2249b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_LINK], 2259b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_SYMLINK], 2269b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_MKDIR], 2279b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_RMDIR], 2289b50d902SRodney W. Grimes nfsstats.rpccnt[NFSPROC_READDIR], 229a62dc406SDoug Rabson nfsstats.rpccnt[NFSPROC_READDIRPLUS], 230a62dc406SDoug Rabson nfsstats.rpccnt[NFSPROC_ACCESS]); 231a62dc406SDoug Rabson printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", 232a62dc406SDoug Rabson "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit", 2339b50d902SRodney W. Grimes "GLease", "Vacate", "Evict"); 234a62dc406SDoug Rabson printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", 235a62dc406SDoug Rabson nfsstats.rpccnt[NFSPROC_MKNOD], 236a62dc406SDoug Rabson nfsstats.rpccnt[NFSPROC_FSSTAT], 237a62dc406SDoug Rabson nfsstats.rpccnt[NFSPROC_FSINFO], 238a62dc406SDoug Rabson nfsstats.rpccnt[NFSPROC_PATHCONF], 239a62dc406SDoug Rabson nfsstats.rpccnt[NFSPROC_COMMIT], 2409b50d902SRodney W. Grimes nfsstats.rpccnt[NQNFSPROC_GETLEASE], 2419b50d902SRodney W. Grimes nfsstats.rpccnt[NQNFSPROC_VACATED], 2429b50d902SRodney W. Grimes nfsstats.rpccnt[NQNFSPROC_EVICTED]); 2439b50d902SRodney W. Grimes printf("Rpc Info:\n"); 2449b50d902SRodney W. Grimes printf("%9.9s %9.9s %9.9s %9.9s %9.9s\n", 2454893ef0bSMatthew Dillon "TimedOut", "Invalid", "X Replies", "Retries", 2464893ef0bSMatthew Dillon "Requests"); 2479b50d902SRodney W. Grimes printf("%9d %9d %9d %9d %9d\n", 2489b50d902SRodney W. Grimes nfsstats.rpctimeouts, 2499b50d902SRodney W. Grimes nfsstats.rpcinvalid, 2509b50d902SRodney W. Grimes nfsstats.rpcunexpected, 2519b50d902SRodney W. Grimes nfsstats.rpcretries, 2529b50d902SRodney W. Grimes nfsstats.rpcrequests); 2539b50d902SRodney W. Grimes printf("Cache Info:\n"); 2549b50d902SRodney W. Grimes printf("%9.9s %9.9s %9.9s %9.9s", 2559b50d902SRodney W. Grimes "Attr Hits", "Misses", "Lkup Hits", "Misses"); 2569b50d902SRodney W. Grimes printf(" %9.9s %9.9s %9.9s %9.9s\n", 2579b50d902SRodney W. Grimes "BioR Hits", "Misses", "BioW Hits", "Misses"); 2589b50d902SRodney W. Grimes printf("%9d %9d %9d %9d", 2599b50d902SRodney W. Grimes nfsstats.attrcache_hits, nfsstats.attrcache_misses, 2609b50d902SRodney W. Grimes nfsstats.lookupcache_hits, nfsstats.lookupcache_misses); 2619b50d902SRodney W. Grimes printf(" %9d %9d %9d %9d\n", 2629b50d902SRodney W. Grimes nfsstats.biocache_reads-nfsstats.read_bios, 2639b50d902SRodney W. Grimes nfsstats.read_bios, 2649b50d902SRodney W. Grimes nfsstats.biocache_writes-nfsstats.write_bios, 2659b50d902SRodney W. Grimes nfsstats.write_bios); 2669b50d902SRodney W. Grimes printf("%9.9s %9.9s %9.9s %9.9s", 2679b50d902SRodney W. Grimes "BioRLHits", "Misses", "BioD Hits", "Misses"); 2689b50d902SRodney W. Grimes printf(" %9.9s %9.9s\n", "DirE Hits", "Misses"); 2699b50d902SRodney W. Grimes printf("%9d %9d %9d %9d", 2709b50d902SRodney W. Grimes nfsstats.biocache_readlinks-nfsstats.readlink_bios, 2719b50d902SRodney W. Grimes nfsstats.readlink_bios, 2729b50d902SRodney W. Grimes nfsstats.biocache_readdirs-nfsstats.readdir_bios, 2739b50d902SRodney W. Grimes nfsstats.readdir_bios); 2749b50d902SRodney W. Grimes printf(" %9d %9d\n", 2759b50d902SRodney W. Grimes nfsstats.direofcache_hits, nfsstats.direofcache_misses); 2764893ef0bSMatthew Dillon } 2774893ef0bSMatthew Dillon if (serverOnly) { 2789b50d902SRodney W. Grimes printf("\nServer Info:\n"); 2799b50d902SRodney W. Grimes printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", 2809b50d902SRodney W. Grimes "Getattr", "Setattr", "Lookup", "Readlink", "Read", 2819b50d902SRodney W. Grimes "Write", "Create", "Remove"); 2829b50d902SRodney W. Grimes printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", 2839b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_GETATTR], 2849b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_SETATTR], 2859b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_LOOKUP], 2869b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_READLINK], 2879b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_READ], 2889b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_WRITE], 2899b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_CREATE], 2909b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_REMOVE]); 2919b50d902SRodney W. Grimes printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", 2929b50d902SRodney W. Grimes "Rename", "Link", "Symlink", "Mkdir", "Rmdir", 293a62dc406SDoug Rabson "Readdir", "RdirPlus", "Access"); 2949b50d902SRodney W. Grimes printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", 2959b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_RENAME], 2969b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_LINK], 2979b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_SYMLINK], 2989b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_MKDIR], 2999b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_RMDIR], 3009b50d902SRodney W. Grimes nfsstats.srvrpccnt[NFSPROC_READDIR], 301a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_READDIRPLUS], 302a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_ACCESS]); 303a62dc406SDoug Rabson printf("%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", 304a62dc406SDoug Rabson "Mknod", "Fsstat", "Fsinfo", "PathConf", "Commit", 3059b50d902SRodney W. Grimes "GLease", "Vacate", "Evict"); 306a62dc406SDoug Rabson printf("%9d %9d %9d %9d %9d %9d %9d %9d\n", 307a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_MKNOD], 308a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_FSSTAT], 309a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_FSINFO], 310a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_PATHCONF], 311a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_COMMIT], 3129b50d902SRodney W. Grimes nfsstats.srvrpccnt[NQNFSPROC_GETLEASE], 3139b50d902SRodney W. Grimes nfsstats.srvrpccnt[NQNFSPROC_VACATED], 3149b50d902SRodney W. Grimes nfsstats.srvrpccnt[NQNFSPROC_EVICTED]); 3159b50d902SRodney W. Grimes printf("Server Ret-Failed\n"); 3169b50d902SRodney W. Grimes printf("%17d\n", nfsstats.srvrpc_errs); 3179b50d902SRodney W. Grimes printf("Server Faults\n"); 3189b50d902SRodney W. Grimes printf("%13d\n", nfsstats.srv_errs); 3199b50d902SRodney W. Grimes printf("Server Cache Stats:\n"); 3209b50d902SRodney W. Grimes printf("%9.9s %9.9s %9.9s %9.9s\n", 3219b50d902SRodney W. Grimes "Inprog", "Idem", "Non-idem", "Misses"); 3229b50d902SRodney W. Grimes printf("%9d %9d %9d %9d\n", 3239b50d902SRodney W. Grimes nfsstats.srvcache_inproghits, 3249b50d902SRodney W. Grimes nfsstats.srvcache_idemdonehits, 3259b50d902SRodney W. Grimes nfsstats.srvcache_nonidemdonehits, 3269b50d902SRodney W. Grimes nfsstats.srvcache_misses); 3279b50d902SRodney W. Grimes printf("Server Lease Stats:\n"); 3289b50d902SRodney W. Grimes printf("%9.9s %9.9s %9.9s\n", 3299b50d902SRodney W. Grimes "Leases", "PeakL", "GLeases"); 3309b50d902SRodney W. Grimes printf("%9d %9d %9d\n", 3319b50d902SRodney W. Grimes nfsstats.srvnqnfs_leases, 3329b50d902SRodney W. Grimes nfsstats.srvnqnfs_maxleases, 3339b50d902SRodney W. Grimes nfsstats.srvnqnfs_getleases); 334a62dc406SDoug Rabson printf("Server Write Gathering:\n"); 335a62dc406SDoug Rabson printf("%9.9s %9.9s %9.9s\n", 336a62dc406SDoug Rabson "WriteOps", "WriteRPC", "Opsaved"); 337a62dc406SDoug Rabson printf("%9d %9d %9d\n", 338a62dc406SDoug Rabson nfsstats.srvvop_writes, 339a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_WRITE], 3404893ef0bSMatthew Dillon nfsstats.srvrpccnt[NFSPROC_WRITE] - 3414893ef0bSMatthew Dillon nfsstats.srvvop_writes); 3424893ef0bSMatthew Dillon } 3439b50d902SRodney W. Grimes } 3449b50d902SRodney W. Grimes 3459b50d902SRodney W. Grimes u_char signalled; /* set if alarm goes off "early" */ 3469b50d902SRodney W. Grimes 3479b50d902SRodney W. Grimes /* 3489b50d902SRodney W. Grimes * Print a running summary of nfs statistics. 3499b50d902SRodney W. Grimes * Repeat display every interval seconds, showing statistics 3509b50d902SRodney W. Grimes * collected over that interval. Assumes that interval is non-zero. 3519b50d902SRodney W. Grimes * First line printed at top of screen is always cumulative. 3529b50d902SRodney W. Grimes */ 3539b50d902SRodney W. Grimes void 3544893ef0bSMatthew Dillon sidewaysintpr(u_int interval, int clientOnly, int serverOnly) 3559b50d902SRodney W. Grimes { 3569b50d902SRodney W. Grimes struct nfsstats nfsstats, lastst; 3574893ef0bSMatthew Dillon int hdrcnt = 1; 3589b50d902SRodney W. Grimes 3594893ef0bSMatthew Dillon readstats(&lastst); 3604893ef0bSMatthew Dillon sleep(interval); 3619b50d902SRodney W. Grimes 3624893ef0bSMatthew Dillon for (;;) { 3634893ef0bSMatthew Dillon readstats(&nfsstats); 3644893ef0bSMatthew Dillon 3654893ef0bSMatthew Dillon if (--hdrcnt == 0) { 3664893ef0bSMatthew Dillon printhdr(clientOnly, serverOnly); 3674893ef0bSMatthew Dillon if (clientOnly && serverOnly) 3684893ef0bSMatthew Dillon hdrcnt = 10; 3694893ef0bSMatthew Dillon else 3709b50d902SRodney W. Grimes hdrcnt = 20; 3719b50d902SRodney W. Grimes } 3724893ef0bSMatthew Dillon if (clientOnly) { 3734893ef0bSMatthew Dillon printf("%s %6d %6d %6d %6d %6d %6d %6d %6d", 3744893ef0bSMatthew Dillon ((clientOnly && serverOnly) ? "Client:" : ""), 3754893ef0bSMatthew Dillon DELTA(attrcache_hits) + DELTA(attrcache_misses), 3764893ef0bSMatthew Dillon DELTA(lookupcache_hits) + DELTA(lookupcache_misses), 3774893ef0bSMatthew Dillon DELTA(biocache_readlinks), 3784893ef0bSMatthew Dillon DELTA(biocache_reads), 3794893ef0bSMatthew Dillon DELTA(biocache_writes), 380a62dc406SDoug Rabson nfsstats.rpccnt[NFSPROC_RENAME]-lastst.rpccnt[NFSPROC_RENAME], 3814893ef0bSMatthew Dillon DELTA(accesscache_hits) + DELTA(accesscache_misses), 3824893ef0bSMatthew Dillon DELTA(biocache_readdirs) 3834893ef0bSMatthew Dillon ); 3844893ef0bSMatthew Dillon if (widemode) { 3854893ef0bSMatthew Dillon printf(" %s %s %s %s %s %s", 3864893ef0bSMatthew Dillon sperc1(DELTA(attrcache_hits), 3874893ef0bSMatthew Dillon DELTA(attrcache_misses)), 3884893ef0bSMatthew Dillon sperc1(DELTA(lookupcache_hits), 3894893ef0bSMatthew Dillon DELTA(lookupcache_misses)), 3904893ef0bSMatthew Dillon sperc2(DELTA(biocache_reads), 3914893ef0bSMatthew Dillon DELTA(read_bios)), 3924893ef0bSMatthew Dillon sperc2(DELTA(biocache_writes), 3934893ef0bSMatthew Dillon DELTA(write_bios)), 3944893ef0bSMatthew Dillon sperc1(DELTA(accesscache_hits), 3954893ef0bSMatthew Dillon DELTA(accesscache_misses)), 3964893ef0bSMatthew Dillon sperc2(DELTA(biocache_readdirs), 3974893ef0bSMatthew Dillon DELTA(readdir_bios)) 3984893ef0bSMatthew Dillon ); 3994893ef0bSMatthew Dillon } 4004893ef0bSMatthew Dillon printf("\n"); 4014893ef0bSMatthew Dillon } 4024893ef0bSMatthew Dillon if (serverOnly) { 4034893ef0bSMatthew Dillon printf("%s %6d %6d %6d %6d %6d %6d %6d %6d", 4044893ef0bSMatthew Dillon ((clientOnly && serverOnly) ? "Server:" : ""), 405a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_GETATTR]-lastst.srvrpccnt[NFSPROC_GETATTR], 406a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_LOOKUP]-lastst.srvrpccnt[NFSPROC_LOOKUP], 407a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_READLINK]-lastst.srvrpccnt[NFSPROC_READLINK], 408a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_READ]-lastst.srvrpccnt[NFSPROC_READ], 409a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_WRITE]-lastst.srvrpccnt[NFSPROC_WRITE], 410a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_RENAME]-lastst.srvrpccnt[NFSPROC_RENAME], 411a62dc406SDoug Rabson nfsstats.srvrpccnt[NFSPROC_ACCESS]-lastst.srvrpccnt[NFSPROC_ACCESS], 412a62dc406SDoug Rabson (nfsstats.srvrpccnt[NFSPROC_READDIR]-lastst.srvrpccnt[NFSPROC_READDIR]) 413a62dc406SDoug Rabson +(nfsstats.srvrpccnt[NFSPROC_READDIRPLUS]-lastst.srvrpccnt[NFSPROC_READDIRPLUS])); 4144893ef0bSMatthew Dillon printf("\n"); 4154893ef0bSMatthew Dillon } 4169b50d902SRodney W. Grimes lastst = nfsstats; 4179b50d902SRodney W. Grimes fflush(stdout); 4184893ef0bSMatthew Dillon sleep(interval); 4199b50d902SRodney W. Grimes } 4209b50d902SRodney W. Grimes /*NOTREACHED*/ 4219b50d902SRodney W. Grimes } 4229b50d902SRodney W. Grimes 4239b50d902SRodney W. Grimes void 4244893ef0bSMatthew Dillon printhdr(int clientOnly, int serverOnly) 4259b50d902SRodney W. Grimes { 4264893ef0bSMatthew Dillon printf("%s%6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s %6.6s", 4274893ef0bSMatthew Dillon ((serverOnly && clientOnly) ? " " : " "), 4284893ef0bSMatthew Dillon "GtAttr", "Lookup", "Rdlink", "Read", "Write", "Rename", 4294893ef0bSMatthew Dillon "Access", "Rddir"); 4304893ef0bSMatthew Dillon if (widemode && clientOnly) { 4314893ef0bSMatthew Dillon printf(" Attr Lkup BioR BioW Accs BioD"); 4329b50d902SRodney W. Grimes } 4334893ef0bSMatthew Dillon printf("\n"); 4344893ef0bSMatthew Dillon fflush(stdout); 4359b50d902SRodney W. Grimes } 4369b50d902SRodney W. Grimes 4379b50d902SRodney W. Grimes void 4389b50d902SRodney W. Grimes usage() 4399b50d902SRodney W. Grimes { 4409b50d902SRodney W. Grimes (void)fprintf(stderr, 4416e0442deSDavid E. O'Brien "usage: nfsstat [-csW] [-M core] [-N system] [-w interval]\n"); 4429b50d902SRodney W. Grimes exit(1); 4439b50d902SRodney W. Grimes } 4444893ef0bSMatthew Dillon 4454893ef0bSMatthew Dillon static char SPBuf[64][8]; 4464893ef0bSMatthew Dillon static int SPIndex; 4474893ef0bSMatthew Dillon 4484893ef0bSMatthew Dillon char * 4494893ef0bSMatthew Dillon sperc1(int hits, int misses) 4504893ef0bSMatthew Dillon { 4514893ef0bSMatthew Dillon char *p = SPBuf[SPIndex]; 4524893ef0bSMatthew Dillon 4534893ef0bSMatthew Dillon if (hits + misses) { 4544893ef0bSMatthew Dillon sprintf(p, "%3d%%", 4554893ef0bSMatthew Dillon (int)(char)((quad_t)hits * 100 / (hits + misses))); 4564893ef0bSMatthew Dillon } else { 4574893ef0bSMatthew Dillon sprintf(p, " -"); 4584893ef0bSMatthew Dillon } 4594893ef0bSMatthew Dillon SPIndex = (SPIndex + 1) & 63; 4604893ef0bSMatthew Dillon return(p); 4614893ef0bSMatthew Dillon } 4624893ef0bSMatthew Dillon 4634893ef0bSMatthew Dillon char * 4644893ef0bSMatthew Dillon sperc2(int ttl, int misses) 4654893ef0bSMatthew Dillon { 4664893ef0bSMatthew Dillon char *p = SPBuf[SPIndex]; 4674893ef0bSMatthew Dillon 4684893ef0bSMatthew Dillon if (ttl) { 4694893ef0bSMatthew Dillon sprintf(p, "%3d%%", 4704893ef0bSMatthew Dillon (int)(char)((quad_t)(ttl - misses) * 100 / ttl)); 4714893ef0bSMatthew Dillon } else { 4724893ef0bSMatthew Dillon sprintf(p, " -"); 4734893ef0bSMatthew Dillon } 4744893ef0bSMatthew Dillon SPIndex = (SPIndex + 1) & 63; 4754893ef0bSMatthew Dillon return(p); 4764893ef0bSMatthew Dillon } 4774893ef0bSMatthew Dillon 478