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