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