fsprobe: add fsprobe_Wait function
[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 #include <roken.h>
20
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     afs_int32 code;     /*Return code */
149     struct sockaddr_in FSSktArray[3];   /*socket array */
150     struct hostent *he;         /*Host entry */
151     int sleep_secs;             /*Number of seconds to sleep */
152
153     printf("\n\nTest of the fsprobe facility.\n\n");
154
155     /*
156      * Fill in the socket array for bigbird, vice1, and vice2.
157      */
158     FSSktArray[0].sin_family = AF_INET;
159     FSSktArray[0].sin_port = htons(7000);       /* FileServer port */
160     he = hostutil_GetHostByName("servername1");
161     if (he == NULL) {
162         fprintf(stderr, "[%s] Can't get host info for servername1\n", rn);
163         exit(-1);
164     }
165     memcpy(&(FSSktArray[0].sin_addr.s_addr), he->h_addr, 4);
166
167     FSSktArray[1].sin_family = AF_INET;
168     FSSktArray[1].sin_port = htons(7000);       /* FileServer port */
169     he = hostutil_GetHostByName("servername2");
170     if (he == NULL) {
171         fprintf(stderr, "[%s] Can't get host info for servername2\n", rn);
172         exit(-1);
173     }
174     memcpy(&(FSSktArray[1].sin_addr.s_addr), he->h_addr, 4);
175
176     FSSktArray[2].sin_family = AF_INET;
177     FSSktArray[2].sin_port = htons(7000);       /* FileServer port */
178     he = hostutil_GetHostByName("servername3");
179     if (he == NULL) {
180         fprintf(stderr, "[%s] Can't get host info for servername3\n", rn);
181         exit(-1);
182     }
183     memcpy(&(FSSktArray[2].sin_addr.s_addr), he->h_addr, 4);
184
185     printf("Sockets for the 3 AFS FileServers to be probed:\n");
186     printf("\t Host servername1: IP addr 0x%x, port %d\n",
187            FSSktArray[0].sin_addr.s_addr, FSSktArray[0].sin_port);
188     printf("\t Host servername2: IP addr 0x%x, port %d\n",
189            FSSktArray[1].sin_addr.s_addr, FSSktArray[1].sin_port);
190     printf("\t Host servername3: IP addr 0x%x, port %d\n",
191            FSSktArray[2].sin_addr.s_addr, FSSktArray[2].sin_port);
192
193     /*
194      * Crank up the FileServer prober, then sit back and have fun.
195      */
196     printf("Starting up the fsprobe service\n");
197     code = fsprobe_Init(3,      /*Num servers */
198                         FSSktArray,     /*FileServer socket array */
199                         30,     /*Probe every 30 seconds */
200                         FS_Handler,     /*Handler routine */
201                         1);     /*Turn debugging output on */
202     if (code) {
203         fprintf(stderr, "[%s] Error returned by fsprobe_Init: %d\n", rn,
204                 code);
205         fsprobe_Cleanup(1);     /*Get rid of malloc'ed structures */
206         exit(-1);
207     }
208     sleep_secs = 60 * 10;       /*Allow 10 minutes of data collection */
209     printf
210         ("Fsprobe service started, main thread sleeping for %d seconds...\n",
211          sleep_secs);
212
213     fsprobe_Wait(sleep_secs);
214
215     /*
216      * We're all done.  Clean up, put the last nail in Rx, then
217      * exit happily.
218      */
219     printf("Yawn, main thread just woke up.  Cleaning things out...\n");
220     code = fsprobe_Cleanup(1);  /*Get rid of malloc'ed data */
221     rx_Finalize();
222     exit(0);
223
224 }                               /*Main routine */