105ab6a150495742e2a6d1b6813c96b3ab69ff5e
[openafs.git] / src / libadmin / samples / rxstat_query_process.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * This file contains sample code for the rxstats interface 
12  */
13
14 #include <afsconfig.h>
15 #include <afs/param.h>
16
17 RCSID
18     ("$Header$");
19
20 #ifdef AFS_NT40_ENV
21 #include <winsock2.h>
22 #include <pthread.h>
23 #endif
24 #include <afs/afs_Admin.h>
25 #include <afs/afs_clientAdmin.h>
26 #include <afs/afs_utilAdmin.h>
27
28 extern int RXSTATS_QueryProcessRPCStats();
29
30 void
31 Usage()
32 {
33     fprintf(stderr, "Usage: rxstat_query_process <host> <port>\n");
34     exit(1);
35 }
36
37 void
38 ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort)
39 {
40     char **argp = argv;
41
42     if (!*(++argp))
43         Usage();
44     *srvrName = *(argp++);
45     if (!*(argp))
46         Usage();
47     *srvrPort = strtol(*(argp++), NULL, 0);
48     if (*srvrPort <= 0 || *srvrPort >= 65536)
49         Usage();
50     if (*(argp))
51         Usage();
52 }
53
54 int
55 main(int argc, char *argv[])
56 {
57     int rc;
58     afs_status_t st = 0;
59     struct rx_connection *conn;
60     char *srvrName;
61     long srvrPort;
62     void *cellHandle;
63     afs_RPCStatsState_t state;
64
65     ParseArgs(argc, argv, &srvrName, &srvrPort);
66
67     rc = afsclient_Init(&st);
68     if (!rc) {
69         fprintf(stderr, "afsclient_Init, status %d\n", st);
70         exit(1);
71     }
72
73     rc = afsclient_NullCellOpen(&cellHandle, &st);
74     if (!rc) {
75         fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st);
76         exit(1);
77     }
78
79     rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn,
80                                    &st);
81     if (!rc) {
82         fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st);
83         exit(1);
84     }
85
86     rc = util_RPCStatsStateGet(conn, RXSTATS_QueryProcessRPCStats, &state,
87                                &st);
88     if (!rc) {
89         fprintf(stderr, "util_RPCStatsStateGet, status %d\n", st);
90         exit(1);
91     }
92
93     rc = afsclient_RPCStatClose(conn, &st);
94     if (!rc) {
95         fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st);
96         exit(1);
97     }
98
99     rc = afsclient_CellClose(cellHandle, &st);
100     if (!rc) {
101         fprintf(stderr, "afsclient_CellClose, status %d\n", st);
102         exit(1);
103     }
104
105     printf("\n");
106     printf("Process RPC stats are ");
107     switch (state) {
108     case AFS_RPC_STATS_DISABLED:
109         printf("disabled\n");
110         break;
111     case AFS_RPC_STATS_ENABLED:
112         printf("enabled\n");
113         break;
114     default:
115         printf("INVALID\n");
116         break;
117     }
118     printf("\n");
119
120     exit(0);
121 }