b2db51f6c98688e293b760e30e250eb2ffa29ab2
[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     FSSktArray[0].sin_family = htons(AF_INET);  /*Internet family */
175     FSSktArray[0].sin_port = htons(7000);       /*FileServer port */
176     he = hostutil_GetHostByName("servername1");
177     if (he == NULL) {
178         fprintf(stderr, "[%s] Can't get host info for servername1\n", rn);
179         exit(-1);
180     }
181     memcpy(&(FSSktArray[0].sin_addr.s_addr), he->h_addr, 4);
182
183     FSSktArray[1].sin_family = htons(AF_INET);  /*Internet address family */
184     FSSktArray[1].sin_port = htons(7000);       /*FileServer port */
185     he = hostutil_GetHostByName("servername2");
186     if (he == NULL) {
187         fprintf(stderr, "[%s] Can't get host info for servername2\n", rn);
188         exit(-1);
189     }
190     memcpy(&(FSSktArray[1].sin_addr.s_addr), he->h_addr, 4);
191
192     FSSktArray[2].sin_family = htons(AF_INET);  /*Internet address family */
193     FSSktArray[2].sin_port = htons(7000);       /*FileServer port */
194     he = hostutil_GetHostByName("servername3");
195     if (he == NULL) {
196         fprintf(stderr, "[%s] Can't get host info for servername3\n", rn);
197         exit(-1);
198     }
199     memcpy(&(FSSktArray[2].sin_addr.s_addr), he->h_addr, 4);
200
201     printf("Sockets for the 3 AFS FileServers to be probed:\n");
202     printf("\t Host servername1: IP addr 0x%lx, port %d\n",
203            FSSktArray[0].sin_addr.s_addr, FSSktArray[0].sin_port);
204     printf("\t Host servername2: IP addr 0x%lx, port %d\n",
205            FSSktArray[1].sin_addr.s_addr, FSSktArray[1].sin_port);
206     printf("\t Host servername3: IP addr 0x%lx, port %d\n",
207            FSSktArray[2].sin_addr.s_addr, FSSktArray[2].sin_port);
208
209     /*
210      * Crank up the FileServer prober, then sit back and have fun.
211      */
212     printf("Starting up the fsprobe service\n");
213     code = fsprobe_Init(3,      /*Num servers */
214                         FSSktArray,     /*FileServer socket array */
215                         30,     /*Probe every 30 seconds */
216                         FS_Handler,     /*Handler routine */
217                         1);     /*Turn debugging output on */
218     if (code) {
219         fprintf(stderr, "[%s] Error returned by fsprobe_Init: %d\n", rn,
220                 code);
221         fsprobe_Cleanup(1);     /*Get rid of malloc'ed structures */
222         exit(-1);
223     }
224     sleep_secs = 60 * 10;       /*Allow 10 minutes of data collection */
225     printf
226         ("Fsprobe service started, main thread sleeping for %d seconds...\n",
227          sleep_secs);
228
229     /*
230      * Let's just fall asleep for a while, then we'll clean up.
231      */
232     tv.tv_sec = sleep_secs;
233     tv.tv_usec = 0;
234     code = IOMGR_Select(0,      /*Num fds */
235                         0,      /*Descriptors ready for reading */
236                         0,      /*Descriptors ready for writing */
237                         0,      /*Descriptors with exceptional conditions */
238                         &tv);   /*Timeout structure */
239     if (code) {
240         fprintf(stderr, "[%s] IOMGR_Select() returned non-zero value: %d\n",
241                 rn, code);
242     }
243
244     /*
245      * We're all done.  Clean up, put the last nail in Rx, then
246      * exit happily.
247      */
248     printf("Yawn, main thread just woke up.  Cleaning things out...\n");
249     code = fsprobe_Cleanup(1);  /*Get rid of malloc'ed data */
250     rx_Finalize();
251     exit(0);
252
253 }                               /*Main routine */