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