Remove the RCSID macro
[openafs.git] / src / fsprobe / fsprobe_test.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  * Description:
12  *      Test of the fsprobe module.
13  *
14  *------------------------------------------------------------------------*/
15
16 #include <afsconfig.h>
17 #include <afs/param.h>
18
19
20 #include <string.h>
21 #include <fsprobe.h>            /*Interface for fsprobe module */
22 #include <afs/afsutil.h>
23     
24 /*------------------------------------------------------------------------
25  * FS_Handler
26  *
27  * Description:
28  *      Handler routine passed to the fsprobe module.  This handler is
29  *      called immediately after a poll of all the FileServers has taken
30  *      place.  All it needs to know is exported by the fsprobe module,
31  *      namely the data structure where the probe results are stored.
32  *
33  * Arguments:
34  *      None.
35  *
36  * Returns:
37  *      0 on success,
38  *      -1 otherwise.
39  *
40  * Environment:
41  *      See above.  All we do now is print out what we got.
42  *
43  * Side Effects:
44  *      As advertised.
45  *------------------------------------------------------------------------*/
46
47 int
48 FS_Handler(void)
49 {                               /*FS_Handler */
50
51     static char rn[] = "FS_Handler";    /*Routine name */
52     struct ProbeViceStatistics *curr_stats;     /*Ptr to current stats */
53     int curr_srvidx, i;         /*Current server index */
54     int *curr_probeOK;          /*Ptr to current probeOK value */
55
56     printf("[%s] Called; results of poll %d are:\n", rn,
57            fsprobe_Results.probeNum);
58     curr_stats = fsprobe_Results.stats;
59     curr_probeOK = fsprobe_Results.probeOK;
60
61     for (curr_srvidx = 0; curr_srvidx < 3; curr_srvidx++) {
62         printf("\nServer %s:\n", (fsprobe_ConnInfo + curr_srvidx)->hostName);
63         printf("\tValue of probeOK for this server: %d\n", *curr_probeOK);
64         printf("\tCurrentMsgNumber:\t%d\n", curr_stats->CurrentMsgNumber);
65         printf("\tOldestMsgNumber:\t%d\n", curr_stats->OldestMsgNumber);
66         printf("\tCurrentTime:\t%d\n", curr_stats->CurrentTime);
67         printf("\tBootTime:\t%d\n", curr_stats->BootTime);
68         printf("\tStartTime:\t%d\n", curr_stats->StartTime);
69         printf("\tCurrentConnections:\t%d\n", curr_stats->CurrentConnections);
70         printf("\tTotalViceCalls:\t%d\n", curr_stats->TotalViceCalls);
71         printf("\tTotalFetchs:\t%d\n", curr_stats->TotalFetchs);
72         printf("\tFetchDatas:\t%d\n", curr_stats->FetchDatas);
73         printf("\tFetchedBytes:\t%d\n", curr_stats->FetchedBytes);
74         printf("\tFetchDataRate:\t%d\n", curr_stats->FetchDataRate);
75         printf("\tTotalStores:\t%d\n", curr_stats->TotalStores);
76         printf("\tStoreDatas:\t%d\n", curr_stats->StoreDatas);
77         printf("\tStoredBytes:\t%d\n", curr_stats->StoredBytes);
78         printf("\tStoreDataRate:\t%d\n", curr_stats->StoreDataRate);
79         printf("\tTotalRPCBytesSent:\t%d\n", curr_stats->TotalRPCBytesSent);
80         printf("\tTotalRPCBytesReceived:\t%d\n",
81                curr_stats->TotalRPCBytesReceived);
82         printf("\tTotalRPCPacketsSent:\t%d\n",
83                curr_stats->TotalRPCPacketsSent);
84         printf("\tTotalRPCPacketsReceived:\t%d\n",
85                curr_stats->TotalRPCPacketsReceived);
86         printf("\tTotalRPCPacketsLost:\t%d\n",
87                curr_stats->TotalRPCPacketsLost);
88         printf("\tTotalRPCBogusPackets:\t%d\n",
89                curr_stats->TotalRPCBogusPackets);
90         printf("\tSystemCPU:\t%d\n", curr_stats->SystemCPU);
91         printf("\tUserCPU:\t%d\n", curr_stats->UserCPU);
92         printf("\tNiceCPU:\t%d\n", curr_stats->NiceCPU);
93         printf("\tIdleCPU:\t%d\n", curr_stats->IdleCPU);
94         printf("\tTotalIO:\t%d\n", curr_stats->TotalIO);
95         printf("\tActiveVM:\t%d\n", curr_stats->ActiveVM);
96         printf("\tTotalVM:\t%d\n", curr_stats->TotalVM);
97         printf("\tEtherNetTotalErrors:\t%d\n",
98                curr_stats->EtherNetTotalErrors);
99         printf("\tEtherNetTotalWrites:\t%d\n",
100                curr_stats->EtherNetTotalWrites);
101         printf("\tEtherNetTotalInterupts:\t%d\n",
102                curr_stats->EtherNetTotalInterupts);
103         printf("\tEtherNetGoodReads:\t%d\n", curr_stats->EtherNetGoodReads);
104         printf("\tEtherNetTotalBytesWritten:\t%d\n",
105                curr_stats->EtherNetTotalBytesWritten);
106         printf("\tEtherNetTotalBytesRead:\t%d\n",
107                curr_stats->EtherNetTotalBytesRead);
108         printf("\tProcessSize:\t%d\n", curr_stats->ProcessSize);
109         printf("\tWorkStations:\t%d\n", curr_stats->WorkStations);
110         printf("\tActiveWorkStations:\t%d\n", curr_stats->ActiveWorkStations);
111         printf("\tSpare1:\t%d\n", curr_stats->Spare1);
112         printf("\tSpare2:\t%d\n", curr_stats->Spare2);
113         printf("\tSpare3:\t%d\n", curr_stats->Spare3);
114         printf("\tSpare4:\t%d\n", curr_stats->Spare4);
115         printf("\tSpare5:\t%d\n", curr_stats->Spare5);
116         printf("\tSpare6:\t%d\n", curr_stats->Spare6);
117         printf("\tSpare7:\t%d\n", curr_stats->Spare7);
118         printf("\tSpare8:\t%d\n", curr_stats->Spare8);
119
120         for (i = 0; i < 26; i++) {
121             printf("\tDisk %d: blocks avail=%d, ttl blocks=%d, name=%s\n", i,
122                    curr_stats->Disk[i].BlocksAvailable,
123                    curr_stats->Disk[i].TotalBlocks, curr_stats->Disk[i].Name);
124         }
125         /*
126          * Bump out statistics pointer to the next server's region.  Ditto
127          * for probeOK;
128          */
129         curr_stats++;
130         curr_probeOK++;
131
132     }                           /*For each server */
133
134     /*
135      * Return the happy news.
136      */
137     return (0);
138
139 }                               /*FS_Handler */
140
141 #include "AFS_component_version_number.c"
142
143 int
144 main(int argc, char **argv)
145 {                               /*Main routine */
146
147     static char rn[] = "fsprobe_test";  /*Routine name */
148     register afs_int32 code;    /*Return code */
149     struct sockaddr_in FSSktArray[3];   /*socket array */
150     struct hostent *he;         /*Host entry */
151     struct timeval tv;          /*Time structure */
152     int sleep_secs;             /*Number of seconds to sleep */
153
154     printf("\n\nTest of the fsprobe facility.\n\n");
155
156     /*
157      * Fill in the socket array for bigbird, vice1, and vice2.
158      */
159 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
160     FSSktArray[0].sin_family = AF_INET;         /*Internet family */
161 #else
162     FSSktArray[0].sin_family = htons(AF_INET);  /*Internet family */
163 #endif
164     FSSktArray[0].sin_port = htons(7000);       /*FileServer port */
165     he = hostutil_GetHostByName("servername1");
166     if (he == NULL) {
167         fprintf(stderr, "[%s] Can't get host info for servername1\n", rn);
168         exit(-1);
169     }
170     memcpy(&(FSSktArray[0].sin_addr.s_addr), he->h_addr, 4);
171
172 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
173     FSSktArray[1].sin_family = AF_INET;         /*Internet address family */
174 #else
175     FSSktArray[1].sin_family = htons(AF_INET);  /*Internet address family */
176 #endif
177     FSSktArray[1].sin_port = htons(7000);       /*FileServer port */
178     he = hostutil_GetHostByName("servername2");
179     if (he == NULL) {
180         fprintf(stderr, "[%s] Can't get host info for servername2\n", rn);
181         exit(-1);
182     }
183     memcpy(&(FSSktArray[1].sin_addr.s_addr), he->h_addr, 4);
184
185 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
186     FSSktArray[2].sin_family = AF_INET;         /*Internet address family */
187 #else
188     FSSktArray[2].sin_family = htons(AF_INET);  /*Internet address family */
189 #endif
190     FSSktArray[2].sin_port = htons(7000);       /*FileServer port */
191     he = hostutil_GetHostByName("servername3");
192     if (he == NULL) {
193         fprintf(stderr, "[%s] Can't get host info for servername3\n", rn);
194         exit(-1);
195     }
196     memcpy(&(FSSktArray[2].sin_addr.s_addr), he->h_addr, 4);
197
198     printf("Sockets for the 3 AFS FileServers to be probed:\n");
199     printf("\t Host servername1: IP addr 0x%x, port %d\n",
200            FSSktArray[0].sin_addr.s_addr, FSSktArray[0].sin_port);
201     printf("\t Host servername2: IP addr 0x%x, port %d\n",
202            FSSktArray[1].sin_addr.s_addr, FSSktArray[1].sin_port);
203     printf("\t Host servername3: IP addr 0x%x, port %d\n",
204            FSSktArray[2].sin_addr.s_addr, FSSktArray[2].sin_port);
205
206     /*
207      * Crank up the FileServer prober, then sit back and have fun.
208      */
209     printf("Starting up the fsprobe service\n");
210     code = fsprobe_Init(3,      /*Num servers */
211                         FSSktArray,     /*FileServer socket array */
212                         30,     /*Probe every 30 seconds */
213                         FS_Handler,     /*Handler routine */
214                         1);     /*Turn debugging output on */
215     if (code) {
216         fprintf(stderr, "[%s] Error returned by fsprobe_Init: %d\n", rn,
217                 code);
218         fsprobe_Cleanup(1);     /*Get rid of malloc'ed structures */
219         exit(-1);
220     }
221     sleep_secs = 60 * 10;       /*Allow 10 minutes of data collection */
222     printf
223         ("Fsprobe service started, main thread sleeping for %d seconds...\n",
224          sleep_secs);
225
226     /*
227      * Let's just fall asleep for a while, then we'll clean up.
228      */
229     tv.tv_sec = sleep_secs;
230     tv.tv_usec = 0;
231     code = IOMGR_Select(0,      /*Num fds */
232                         0,      /*Descriptors ready for reading */
233                         0,      /*Descriptors ready for writing */
234                         0,      /*Descriptors with exceptional conditions */
235                         &tv);   /*Timeout structure */
236     if (code) {
237         fprintf(stderr, "[%s] IOMGR_Select() returned non-zero value: %d\n",
238                 rn, code);
239     }
240
241     /*
242      * We're all done.  Clean up, put the last nail in Rx, then
243      * exit happily.
244      */
245     printf("Yawn, main thread just woke up.  Cleaning things out...\n");
246     code = fsprobe_Cleanup(1);  /*Get rid of malloc'ed data */
247     rx_Finalize();
248     exit(0);
249
250 }                               /*Main routine */