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