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