2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2003 Apple Computer, Inc.
13 * This file contains sample code for the rxstats interface
16 #include <afsconfig.h>
17 #include <afs/param.h>
29 #include <afs/afs_Admin.h>
30 #include <afs/afs_AdminErrors.h>
31 #include <afs/afs_clientAdmin.h>
32 #include <afs/afs_utilAdmin.h>
35 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
36 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
37 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
38 #endif /* AFS_DARWIN_ENV */
40 #include <rx/rxstat.h>
41 #include <afs/afsint.h>
42 #define FSINT_COMMON_XG
43 #include <afs/afscbint.h>
44 #include <afs/kauth.h>
45 #include <afs/kautils.h>
46 #include <afs/ptint.h>
47 #include <afs/ptserver.h>
48 #include <afs/vldbint.h>
49 #include <afs/bosint.h>
50 #include <afs/volint.h>
51 #include <afs/volser.h>
52 #include <afs/bosint.h>
56 #include <arpa/inet.h> /* for inet_ntoa() */
59 extern int RXSTATS_RetrievePeerRPCStats();
64 fprintf(stderr, "Usage: rxstat_get_peer <cell> <host> <port>\n");
69 ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort)
75 *srvrName = *(argp++);
78 *srvrPort = strtol(*(argp++), NULL, 0);
79 if (*srvrPort <= 0 || *srvrPort >= 65536)
86 GetPrintStrings(afs_RPCStats_p statp, char *ifName, char *ifRole,
87 char *hostName, const char ***funcList, int *funcListLen)
91 ina.s_addr = htonl(statp->s.stats_v1.remote_peer);
92 strcpy(hostName, inet_ntoa(ina));
94 if (statp->s.stats_v1.remote_is_server) {
95 strcpy(ifRole, "client");
97 strcpy(ifRole, "server");
100 switch (statp->s.stats_v1.interfaceId) {
101 case RXSTATS_STATINDEX:
102 strcpy(ifName, "rxstats interface");
103 *funcList = RXSTATS_function_names;
104 *funcListLen = RXSTATS_NO_OF_STAT_FUNCS;
106 case RXAFS_STATINDEX:
107 strcpy(ifName, "fileserver interface");
108 *funcList = RXAFS_function_names;
109 *funcListLen = RXAFS_NO_OF_STAT_FUNCS;
111 case RXAFSCB_STATINDEX:
112 strcpy(ifName, "callback interface");
113 *funcList = RXAFSCB_function_names;
114 *funcListLen = RXAFSCB_NO_OF_STAT_FUNCS;
117 strcpy(ifName, "ptserver interface");
118 *funcList = PR_function_names;
119 *funcListLen = PR_NO_OF_STAT_FUNCS;
122 strcpy(ifName, "ubik disk interface");
123 *funcList = DISK_function_names;
124 *funcListLen = DISK_NO_OF_STAT_FUNCS;
127 strcpy(ifName, "ubik vote interface");
128 *funcList = VOTE_function_names;
129 *funcListLen = VOTE_NO_OF_STAT_FUNCS;
132 strcpy(ifName, "volserver interface");
133 *funcList = VL_function_names;
134 *funcListLen = VL_NO_OF_STAT_FUNCS;
136 case AFSVolSTATINDEX:
137 strcpy(ifName, "volserver interface");
138 *funcList = AFSVolfunction_names;
139 *funcListLen = AFSVolNO_OF_STAT_FUNCS;
142 strcpy(ifName, "bosserver interface");
143 *funcList = BOZO_function_names;
144 *funcListLen = BOZO_NO_OF_STAT_FUNCS;
147 strcpy(ifName, "KAA interface");
148 *funcList = KAA_function_names;
149 *funcListLen = KAA_NO_OF_STAT_FUNCS;
152 strcpy(ifName, "KAM interface");
153 *funcList = KAM_function_names;
154 *funcListLen = KAM_NO_OF_STAT_FUNCS;
157 strcpy(ifName, "KAT interface");
158 *funcList = KAT_function_names;
159 *funcListLen = KAT_NO_OF_STAT_FUNCS;
162 sprintf(ifName, "interface 0x%x", statp->s.stats_v1.interfaceId);
170 main(int argc, char *argv[])
174 struct rx_connection *conn;
179 afs_RPCStats_t stats;
183 const char **funcList;
187 ParseArgs(argc, argv, &srvrName, &srvrPort);
189 rc = afsclient_Init(&st);
191 fprintf(stderr, "afsclient_Init, status %d\n", st);
195 rc = afsclient_NullCellOpen(&cellHandle, &st);
197 fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st);
201 rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn,
204 fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st);
208 rc = util_RPCStatsGetBegin(conn, RXSTATS_RetrievePeerRPCStats, &iterator,
211 fprintf(stderr, "util_RPCStatsGetBegin, status %d\n", st);
215 while (util_RPCStatsGetNext(iterator, &stats, &st)) {
216 index = stats.s.stats_v1.func_index;
219 GetPrintStrings(&stats, ifName, role, hostName, &funcList,
221 printf("\nPeer stats for %s accessed as a %s\n"
222 " host %s, port %d\n\n", ifName, role, hostName,
223 stats.s.stats_v1.remote_port);
226 if (index >= funcListLen) {
227 printf(" Function index %d\n", index);
229 printf(" %s\n", funcList[index]);
232 if (!hiszero(stats.s.stats_v1.invocations)) {
233 printf("\tinvoc (%u.%u) bytes_sent (%u.%u) bytes_rcvd (%u.%u)\n",
234 hgethi(stats.s.stats_v1.invocations),
235 hgetlo(stats.s.stats_v1.invocations),
236 hgethi(stats.s.stats_v1.bytes_sent),
237 hgetlo(stats.s.stats_v1.bytes_sent),
238 hgethi(stats.s.stats_v1.bytes_rcvd),
239 hgetlo(stats.s.stats_v1.bytes_rcvd));
240 printf("\tqsum %d.%06d qsqr %d.%06d"
241 " qmin %d.%06d qmax %d.%06d\n",
242 stats.s.stats_v1.queue_time_sum.sec,
243 stats.s.stats_v1.queue_time_sum.usec,
244 stats.s.stats_v1.queue_time_sum_sqr.sec,
245 stats.s.stats_v1.queue_time_sum_sqr.usec,
246 stats.s.stats_v1.queue_time_min.sec,
247 stats.s.stats_v1.queue_time_min.usec,
248 stats.s.stats_v1.queue_time_max.sec,
249 stats.s.stats_v1.queue_time_max.usec);
250 printf("\txsum %d.%06d xsqr %d.%06d"
251 " xmin %d.%06d xmax %d.%06d\n",
252 stats.s.stats_v1.execution_time_sum.sec,
253 stats.s.stats_v1.execution_time_sum.usec,
254 stats.s.stats_v1.execution_time_sum_sqr.sec,
255 stats.s.stats_v1.execution_time_sum_sqr.usec,
256 stats.s.stats_v1.execution_time_min.sec,
257 stats.s.stats_v1.execution_time_min.usec,
258 stats.s.stats_v1.execution_time_max.sec,
259 stats.s.stats_v1.execution_time_max.usec);
261 printf("\tNever invoked\n");
264 if (st != ADMITERATORDONE) {
265 fprintf(stderr, "util_RPCStatsGetNext, status %d\n", st);
270 rc = util_RPCStatsGetDone(iterator, &st);
272 fprintf(stderr, "util_RPCStatsGetDone, status %d\n", st);
276 rc = afsclient_RPCStatClose(conn, &st);
278 fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st);
282 rc = afsclient_CellClose(cellHandle, &st);
284 fprintf(stderr, "afsclient_CellClose, status %d\n", st);