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
11 * This file contains sample code for the rxstats interface
14 #include <afs/param.h>
15 #include <afsconfig.h>
23 #include <afs/afs_Admin.h>
24 #include <afs/afs_AdminErrors.h>
25 #include <afs/afs_clientAdmin.h>
26 #include <afs/afs_utilAdmin.h>
27 #include <rx/rxstat.h>
28 #include <afs/afsint.h>
29 #define FSINT_COMMON_XG
30 #include <afs/afscbint.h>
31 #include <afs/kauth.h>
32 #include <afs/kautils.h>
33 #include <afs/ptint.h>
34 #include <afs/ptserver.h>
35 #include <afs/vldbint.h>
36 #include <afs/bosint.h>
37 #include <afs/volint.h>
38 #include <afs/volser.h>
39 #include <afs/bosint.h>
43 #include <arpa/inet.h> /* for inet_ntoa() */
46 extern int RXSTATS_RetrievePeerRPCStats();
51 "Usage: rxstat_get_peer <cell> <host> <port>\n");
65 *srvrName = *(argp++);
68 *srvrPort = strtol(*(argp++), NULL, 0);
69 if (*srvrPort <= 0 || *srvrPort >= 65536)
80 const char ***funcList,
85 ina.s_addr = htonl(statp->s.stats_v1.remote_peer);
86 strcpy(hostName, inet_ntoa(ina));
88 if (statp->s.stats_v1.remote_is_server) {
89 strcpy(ifRole, "client");
91 strcpy(ifRole, "server");
94 switch(statp->s.stats_v1.interfaceId) {
95 case RXSTATS_STATINDEX:
96 strcpy(ifName, "rxstats interface");
97 *funcList = RXSTATS_function_names;
98 *funcListLen = RXSTATS_NO_OF_STAT_FUNCS;
100 case RXAFS_STATINDEX:
101 strcpy(ifName, "fileserver interface");
102 *funcList = RXAFS_function_names;
103 *funcListLen = RXAFS_NO_OF_STAT_FUNCS;
105 case RXAFSCB_STATINDEX:
106 strcpy(ifName, "callback interface");
107 *funcList = RXAFSCB_function_names;
108 *funcListLen = RXAFSCB_NO_OF_STAT_FUNCS;
111 strcpy(ifName, "ptserver interface");
112 *funcList = PR_function_names;
113 *funcListLen = PR_NO_OF_STAT_FUNCS;
116 strcpy(ifName, "ubik disk interface");
117 *funcList = DISK_function_names;
118 *funcListLen = DISK_NO_OF_STAT_FUNCS;
121 strcpy(ifName, "ubik vote interface");
122 *funcList = VOTE_function_names;
123 *funcListLen = VOTE_NO_OF_STAT_FUNCS;
126 strcpy(ifName, "volserver interface");
127 *funcList = VL_function_names;
128 *funcListLen = VL_NO_OF_STAT_FUNCS;
130 case AFSVolSTATINDEX:
131 strcpy(ifName, "volserver interface");
132 *funcList = AFSVolfunction_names;
133 *funcListLen = AFSVolNO_OF_STAT_FUNCS;
136 strcpy(ifName, "bosserver interface");
137 *funcList = BOZO_function_names;
138 *funcListLen = BOZO_NO_OF_STAT_FUNCS;
141 strcpy(ifName, "KAA interface");
142 *funcList = KAA_function_names;
143 *funcListLen = KAA_NO_OF_STAT_FUNCS;
146 strcpy(ifName, "KAM interface");
147 *funcList = KAM_function_names;
148 *funcListLen = KAM_NO_OF_STAT_FUNCS;
151 strcpy(ifName, "KAT interface");
152 *funcList = KAT_function_names;
153 *funcListLen = KAT_NO_OF_STAT_FUNCS;
156 sprintf(ifName, "interface 0x%x", statp->s.stats_v1.interfaceId);
163 int main(int argc, char *argv[])
167 struct rx_connection *conn;
172 afs_RPCStats_t stats;
176 const char **funcList;
180 ParseArgs(argc, argv, &srvrName, &srvrPort);
182 rc = afsclient_Init(&st);
184 fprintf(stderr, "afsclient_Init, status %d\n", st);
188 rc = afsclient_NullCellOpen(&cellHandle, &st);
190 fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st);
194 rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn, &st);
196 fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st);
200 rc = util_RPCStatsGetBegin(conn, RXSTATS_RetrievePeerRPCStats,
203 fprintf(stderr, "util_RPCStatsGetBegin, status %d\n", st);
207 while (util_RPCStatsGetNext(iterator, &stats, &st)) {
208 index = stats.s.stats_v1.func_index;
211 GetPrintStrings(&stats, ifName, role, hostName,
212 &funcList, &funcListLen);
213 printf("\nPeer stats for %s accessed as a %s\n"
214 " host %s, port %d\n\n",
215 ifName, role, hostName, stats.s.stats_v1.remote_port);
218 if (index >= funcListLen) {
219 printf(" Function index %d\n", index);
221 printf(" %s\n", funcList[index]);
224 if (!hiszero(stats.s.stats_v1.invocations)) {
225 printf("\tinvoc (%u.%u) bytes_sent (%u.%u) bytes_rcvd (%u.%u)\n",
226 hgethi(stats.s.stats_v1.invocations),
227 hgetlo(stats.s.stats_v1.invocations),
228 hgethi(stats.s.stats_v1.bytes_sent),
229 hgetlo(stats.s.stats_v1.bytes_sent),
230 hgethi(stats.s.stats_v1.bytes_rcvd),
231 hgetlo(stats.s.stats_v1.bytes_rcvd));
232 printf("\tqsum %d.%06d qsqr %d.%06d"
233 " qmin %d.%06d qmax %d.%06d\n",
234 stats.s.stats_v1.queue_time_sum.sec,
235 stats.s.stats_v1.queue_time_sum.usec,
236 stats.s.stats_v1.queue_time_sum_sqr.sec,
237 stats.s.stats_v1.queue_time_sum_sqr.usec,
238 stats.s.stats_v1.queue_time_min.sec,
239 stats.s.stats_v1.queue_time_min.usec,
240 stats.s.stats_v1.queue_time_max.sec,
241 stats.s.stats_v1.queue_time_max.usec);
242 printf("\txsum %d.%06d xsqr %d.%06d"
243 " xmin %d.%06d xmax %d.%06d\n",
244 stats.s.stats_v1.execution_time_sum.sec,
245 stats.s.stats_v1.execution_time_sum.usec,
246 stats.s.stats_v1.execution_time_sum_sqr.sec,
247 stats.s.stats_v1.execution_time_sum_sqr.usec,
248 stats.s.stats_v1.execution_time_min.sec,
249 stats.s.stats_v1.execution_time_min.usec,
250 stats.s.stats_v1.execution_time_max.sec,
251 stats.s.stats_v1.execution_time_max.usec);
253 printf("\tNever invoked\n");
256 if (st != ADMITERATORDONE) {
257 fprintf(stderr, "util_RPCStatsGetNext, status %d\n", st);
262 rc = util_RPCStatsGetDone(iterator, &st);
264 fprintf(stderr, "util_RPCStatsGetDone, status %d\n", st);
268 rc = afsclient_RPCStatClose(conn, &st);
270 fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st);
274 rc = afsclient_CellClose(cellHandle, &st);
276 fprintf(stderr, "afsclient_CellClose, status %d\n", st);