afsmon-warning-cleanup-20010605
[openafs.git] / src / afsmonitor / afsmon-output.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  * Module:      afsmon-output.c
12  *              Outputs the xstat probe results to a file
13  *              Most of this code is taken from xstat_fs_test.c and
14  *              xstat_cm_test.c
15  *
16  *-------------------------------------------------------------------------*/
17
18 #include <stdio.h>
19 #include <time.h>
20 #include <afs/param.h>
21 #include <afs/xstat_fs.h>  
22 #include <afs/xstat_cm.h>
23
24
25
26 /* Extern Variables */
27 extern int afsmon_debug;        /* debugging on ? */
28 extern FILE *debugFD;           /* debug file FD */
29 extern char errMsg[256];        /* error message buffer */
30
31 extern int afsmon_Exit();       /* exit routine */
32
33 static FILE *fs_outFD;                  /* fs output file descriptor */
34 static FILE *cm_outFD;                  /* cm output file descriptor */
35
36 /* structures used by FS & CM stats print routines */
37
38 static char *fsOpNames[] = {
39     "FetchData",
40     "FetchACL",
41     "FetchStatus",
42     "StoreData",
43     "StoreACL",
44     "StoreStatus",
45     "RemoveFile",
46     "CreateFile",
47     "Rename",
48     "Symlink",
49     "Link",
50     "MakeDir",
51     "RemoveDir",
52     "SetLock",
53     "ExtendLock",
54     "ReleaseLock",
55     "GetStatistics",
56     "GiveUpCallbacks",
57     "GetVolumeInfo",
58     "GetVolumeStatus",
59     "SetVolumeStatus",
60     "GetRootVolume",
61     "CheckToken",
62     "GetTime",
63     "NGetVolumeInfo",
64     "BulkStatus",
65     "XStatsVersion",
66     "GetXStats"
67 };
68
69 static char *cmOpNames[] = {
70     "CallBack",
71     "InitCallBackState",
72     "Probe",
73     "GetLock",
74     "GetCE",
75     "XStatsVersion",
76     "GetXStats"
77 };
78
79 static char *xferOpNames[] = {
80     "FetchData",
81     "StoreData"
82 };
83
84 /*________________________________________________________________________
85                                 FS STATS ROUTINES 
86  *_______________________________________________________________________*/
87
88 /*------------------------------------------------------------------------
89  * Print_fs_OverallPerfInfo
90  *
91  * Description:
92  *      Print out overall performance numbers.
93  *
94  * Arguments:
95  *      a_ovP : Ptr to the overall performance numbers.
96  *
97  * Returns:
98  *      Nothing.
99  *
100  * Environment:
101  *      Nothing interesting.
102  *
103  * Side Effects:
104  *      As advertised.
105  *------------------------------------------------------------------------*/
106
107 void Print_fs_OverallPerfInfo(a_ovP)
108     struct afs_PerfStats *a_ovP;
109
110 { /*Print_fs_OverallPerfInfo*/
111
112     fprintf(fs_outFD,"\t%10d numPerfCalls\n\n", a_ovP->numPerfCalls);
113
114
115     /*
116      * Vnode cache section.
117      */
118     fprintf(fs_outFD,"\t%10d vcache_L_Entries\n", a_ovP->vcache_L_Entries);
119     fprintf(fs_outFD,"\t%10d vcache_L_Allocs\n",  a_ovP->vcache_L_Allocs);
120     fprintf(fs_outFD,"\t%10d vcache_L_Gets\n",    a_ovP->vcache_L_Gets);
121     fprintf(fs_outFD,"\t%10d vcache_L_Reads\n",   a_ovP->vcache_L_Reads);
122     fprintf(fs_outFD,"\t%10d vcache_L_Writes\n\n",a_ovP->vcache_L_Writes);
123
124     fprintf(fs_outFD,"\t%10d vcache_S_Entries\n", a_ovP->vcache_S_Entries);
125     fprintf(fs_outFD,"\t%10d vcache_S_Allocs\n",  a_ovP->vcache_S_Allocs);
126     fprintf(fs_outFD,"\t%10d vcache_S_Gets\n",    a_ovP->vcache_S_Gets);
127     fprintf(fs_outFD,"\t%10d vcache_S_Reads\n",   a_ovP->vcache_S_Reads);
128     fprintf(fs_outFD,"\t%10d vcache_S_Writes\n\n",a_ovP->vcache_S_Writes);
129
130     fprintf(fs_outFD,"\t%10d vcache_H_Entries\n", a_ovP->vcache_H_Entries);
131     fprintf(fs_outFD,"\t%10d vcache_H_Gets\n",    a_ovP->vcache_H_Gets);
132     fprintf(fs_outFD,"\t%10d vcache_H_Replacements\n\n",a_ovP->vcache_H_Replacements);
133
134     /*
135      * Directory package section.
136      */
137     fprintf(fs_outFD,"\t%10d dir_Buffers\n", a_ovP->dir_Buffers);
138     fprintf(fs_outFD,"\t%10d dir_Calls\n", a_ovP->dir_Calls);
139     fprintf(fs_outFD,"\t%10d dir_IOs\n\n", a_ovP->dir_IOs);
140
141     /*
142      * Rx section.
143      */
144     fprintf(fs_outFD,"\t%10d rx_packetRequests\n", a_ovP->rx_packetRequests);
145     fprintf(fs_outFD,"\t%10d rx_noPackets_RcvClass\n", a_ovP->rx_noPackets_RcvClass);
146     fprintf(fs_outFD,"\t%10d rx_noPackets_SendClass\n", a_ovP->rx_noPackets_SendClass);
147     fprintf(fs_outFD,"\t%10d rx_noPackets_SpecialClass\n", a_ovP->rx_noPackets_SpecialClass);
148     fprintf(fs_outFD,"\t%10d rx_socketGreedy\n", a_ovP->rx_socketGreedy);
149     fprintf(fs_outFD,"\t%10d rx_bogusPacketOnRead\n", a_ovP->rx_bogusPacketOnRead);
150     fprintf(fs_outFD,"\t%10d rx_bogusHost\n",   a_ovP->rx_bogusHost);
151     fprintf(fs_outFD,"\t%10d rx_noPacketOnRead\n", a_ovP->rx_noPacketOnRead);
152     fprintf(fs_outFD,"\t%10d rx_noPacketBuffersOnRead\n", a_ovP->rx_noPacketBuffersOnRead);
153     fprintf(fs_outFD,"\t%10d rx_selects\n", a_ovP->rx_selects);
154     fprintf(fs_outFD,"\t%10d rx_sendSelects\n", a_ovP->rx_sendSelects);
155     fprintf(fs_outFD,"\t%10d rx_packetsRead_RcvClass\n", a_ovP->rx_packetsRead_RcvClass);
156     fprintf(fs_outFD,"\t%10d rx_packetsRead_SendClass\n", a_ovP->rx_packetsRead_SendClass);
157     fprintf(fs_outFD,"\t%10d rx_packetsRead_SpecialClass\n", a_ovP->rx_packetsRead_SpecialClass);
158     fprintf(fs_outFD,"\t%10d rx_dataPacketsRead\n", a_ovP->rx_dataPacketsRead);
159     fprintf(fs_outFD,"\t%10d rx_ackPacketsRead\n", a_ovP->rx_ackPacketsRead);
160     fprintf(fs_outFD,"\t%10d rx_dupPacketsRead\n", a_ovP->rx_dupPacketsRead);
161     fprintf(fs_outFD,"\t%10d rx_spuriousPacketsRead\n", a_ovP->rx_spuriousPacketsRead);
162     fprintf(fs_outFD,"\t%10d rx_packetsSent_RcvClass\n", a_ovP->rx_packetsSent_RcvClass);
163     fprintf(fs_outFD,"\t%10d rx_packetsSent_SendClass\n", a_ovP->rx_packetsSent_SendClass);
164     fprintf(fs_outFD,"\t%10d rx_packetsSent_SpecialClass\n", a_ovP->rx_packetsSent_SpecialClass);
165     fprintf(fs_outFD,"\t%10d rx_ackPacketsSent\n", a_ovP->rx_ackPacketsSent);
166     fprintf(fs_outFD,"\t%10d rx_pingPacketsSent\n", a_ovP->rx_pingPacketsSent);
167     fprintf(fs_outFD,"\t%10d rx_abortPacketsSent\n",a_ovP->rx_abortPacketsSent);
168     fprintf(fs_outFD,"\t%10d rx_busyPacketsSent\n", a_ovP->rx_busyPacketsSent);
169     fprintf(fs_outFD,"\t%10d rx_dataPacketsSent\n", a_ovP->rx_dataPacketsSent);
170     fprintf(fs_outFD,"\t%10d rx_dataPacketsReSent\n", a_ovP->rx_dataPacketsReSent);
171     fprintf(fs_outFD,"\t%10d rx_dataPacketsPushed\n",   a_ovP->rx_dataPacketsPushed);
172     fprintf(fs_outFD,"\t%10d rx_ignoreAckedPacket\n",   a_ovP->rx_ignoreAckedPacket);
173     fprintf(fs_outFD,"\t%10d rx_totalRtt_Sec\n", a_ovP->rx_totalRtt_Sec);
174     fprintf(fs_outFD,"\t%10d rx_totalRtt_Usec\n", a_ovP->rx_totalRtt_Usec);
175     fprintf(fs_outFD,"\t%10d rx_minRtt_Sec\n",  a_ovP->rx_minRtt_Sec);
176     fprintf(fs_outFD,"\t%10d rx_minRtt_Usec\n",         a_ovP->rx_minRtt_Usec);
177     fprintf(fs_outFD,"\t%10d rx_maxRtt_Sec\n",          a_ovP->rx_maxRtt_Sec);
178     fprintf(fs_outFD,"\t%10d rx_maxRtt_Usec\n",         a_ovP->rx_maxRtt_Usec);
179     fprintf(fs_outFD,"\t%10d rx_nRttSamples\n",         a_ovP->rx_nRttSamples);
180     fprintf(fs_outFD,"\t%10d rx_nServerConns\n",        a_ovP->rx_nServerConns);
181     fprintf(fs_outFD,"\t%10d rx_nClientConns\n",        a_ovP->rx_nClientConns);
182     fprintf(fs_outFD,"\t%10d rx_nPeerStructs\n",        a_ovP->rx_nPeerStructs);
183     fprintf(fs_outFD,"\t%10d rx_nCallStructs\n",        a_ovP->rx_nCallStructs);
184     fprintf(fs_outFD,"\t%10d rx_nFreeCallStructs\n\n",  a_ovP->rx_nFreeCallStructs);
185
186     /*
187      * Host module fields.
188      */
189     fprintf(fs_outFD,"\t%10d host_NumHostEntries\n",    a_ovP->host_NumHostEntries);
190     fprintf(fs_outFD,"\t%10d host_HostBlocks\n",        a_ovP->host_HostBlocks);
191     fprintf(fs_outFD,"\t%10d host_NonDeletedHosts\n",   a_ovP->host_NonDeletedHosts);
192     fprintf(fs_outFD,"\t%10d host_HostsInSameNetOrSubnet\n", a_ovP->host_HostsInSameNetOrSubnet);
193     fprintf(fs_outFD,"\t%10d host_HostsInDiffSubnet\n", a_ovP->host_HostsInDiffSubnet);
194     fprintf(fs_outFD,"\t%10d host_HostsInDiffNetwork\n",a_ovP->host_HostsInDiffNetwork);
195     fprintf(fs_outFD,"\t%10d host_NumClients\n",        a_ovP->host_NumClients);
196     fprintf(fs_outFD,"\t%10d host_ClientBlocks\n\n",    a_ovP->host_ClientBlocks);
197
198 } /*Print_fs_OverallPerfInfo*/
199
200
201 /*------------------------------------------------------------------------
202  * Print_fs_OpTiming
203  *
204  * Description:
205  *      Print out the contents of an RPC op timing structure.
206  *
207  * Arguments:
208  *      a_opIdx   : Index of the AFS operation we're printing number on.
209  *      a_opTimeP : Ptr to the op timing structure to print.
210  *
211  * Returns:
212  *      Nothing.
213  *
214  * Environment:
215  *      Nothing interesting.
216  *
217  * Side Effects:
218  *      As advertised.
219  *------------------------------------------------------------------------*/
220
221 void Print_fs_OpTiming(a_opIdx, a_opTimeP)
222     int a_opIdx;
223     struct fs_stats_opTimingData *a_opTimeP;
224
225 { /*Print_fs_OpTiming*/
226
227     fprintf(fs_outFD,"%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
228            fsOpNames[a_opIdx],
229            a_opTimeP->numOps, a_opTimeP->numSuccesses,
230            a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
231            a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
232            a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);
233
234 } /*Print_fs_OpTiming*/
235
236
237 /*------------------------------------------------------------------------
238  * Print_fs_XferTiming
239  *
240  * Description:
241  *      Print out the contents of a data transfer structure.
242  *
243  * Arguments:
244  *      a_opIdx : Index of the AFS operation we're printing number on.
245  *      a_xferP : Ptr to the data transfer structure to print.
246  *
247  * Returns:
248  *      Nothing.
249  *
250  * Environment:
251  *      Nothing interesting.
252  *
253  * Side Effects:
254  *      As advertised.
255  *------------------------------------------------------------------------*/
256
257 void Print_fs_XferTiming(a_opIdx, a_xferP)
258     int a_opIdx;
259     struct fs_stats_xferData *a_xferP;
260
261 { /*Print_fs_XferTiming*/
262
263     fprintf(fs_outFD,"%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
264            xferOpNames[a_opIdx],
265            a_xferP->numXfers, a_xferP->numSuccesses,
266            a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
267            a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
268            a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
269     fprintf(fs_outFD,"\t[bytes: sum=%d, min=%d, max=%d]\n",
270            a_xferP->sumBytes, a_xferP->minBytes, a_xferP->maxBytes);
271     fprintf(fs_outFD,"\t[buckets: 0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d 6: %d, 7: %d, 8: %d]\n",
272            a_xferP->count[0],
273            a_xferP->count[1],
274            a_xferP->count[2],
275            a_xferP->count[3],
276            a_xferP->count[4],
277            a_xferP->count[5],
278            a_xferP->count[6],
279            a_xferP->count[7],
280            a_xferP->count[8]);
281
282 } /*Print_fs_XferTiming*/
283
284
285 /*------------------------------------------------------------------------
286  * Print_fs_DetailedPerfInfo
287  *
288  * Description:
289  *      Print out a set of detailed performance numbers.
290  *
291  * Arguments:
292  *      a_detP : Ptr to detailed perf numbers to print.
293  *
294  * Returns:
295  *      Nothing.
296  *
297  * Environment:
298  *      Nothing interesting.
299  *
300  * Side Effects:
301  *      As advertised.
302  *------------------------------------------------------------------------*/
303
304 void Print_fs_DetailedPerfInfo(a_detP)
305     struct fs_stats_DetailedStats *a_detP;
306
307 { /*Print_fs_DetailedPerfInfo*/
308
309     int currIdx;        /*Loop variable*/
310
311     fprintf(fs_outFD,"\t%10d epoch\n", a_detP->epoch);
312
313     for (currIdx = 0; currIdx < FS_STATS_NUM_RPC_OPS; currIdx++)
314         Print_fs_OpTiming(currIdx, &(a_detP->rpcOpTimes[currIdx]));
315
316     for (currIdx = 0; currIdx < FS_STATS_NUM_XFER_OPS; currIdx++)
317         Print_fs_XferTiming(currIdx, &(a_detP->xferOpTimes[currIdx]));
318
319 } /*Print_fs_DetailedPerfInfo*/
320
321
322 /*------------------------------------------------------------------------
323  * Print_fs_FullPerfInfo
324  *
325  * Description:
326  *      Print out the AFS_XSTATSCOLL_FULL_PERF_INFO collection we just
327  *      received.
328  *
329  * Arguments:
330  *      None.
331  *
332  * Returns:
333  *      Nothing.
334  *
335  * Environment:
336  *      All the info we need is nestled into xstat_fs_Results.
337  *
338  * Side Effects:
339  *      As advertised.
340  *------------------------------------------------------------------------*/
341
342 void Print_fs_FullPerfInfo(a_fs_Results)
343 struct xstat_fs_ProbeResults *a_fs_Results;             /* ptr to fs results */
344 { /*Print_fs_FullPerfInfo*/
345
346     static char rn[] = "Print_fs_FullPerfInfo";       /*Routine name*/
347     static afs_int32 fullPerfLongs =
348         (sizeof(struct fs_stats_FullPerfStats) >> 2); /*Correct # longs to rcv*/
349     afs_int32 numLongs;                               /*# longwords received*/
350     struct fs_stats_FullPerfStats *fullPerfP;         /*Ptr to full perf stats*/
351     char *printableTime;                        /*Ptr to printable time string*/
352
353
354     numLongs = a_fs_Results->data.AFS_CollData_len;
355     if (numLongs != fullPerfLongs) {
356         fprintf(fs_outFD," ** Data size mismatch in full performance collection!\n");
357         fprintf(fs_outFD," ** Expecting %d, got %d\n", fullPerfLongs, numLongs);
358         return;
359     }
360
361     printableTime = ctime((time_t *)&(a_fs_Results->probeTime));
362     printableTime[strlen(printableTime)-1] = '\0';
363     fullPerfP = (struct fs_stats_FullPerfStats *)
364         (a_fs_Results->data.AFS_CollData_val);
365
366     fprintf(fs_outFD,"AFS_XSTATSCOLL_FULL_PERF_INFO (coll %d) for FS %s\n[Probe %d, %s]\n\n",
367            a_fs_Results->collectionNumber,
368            a_fs_Results->connP->hostName,
369            a_fs_Results->probeNum,
370            printableTime);
371
372     Print_fs_OverallPerfInfo(&(fullPerfP->overall));
373     Print_fs_DetailedPerfInfo(&(fullPerfP->det));
374
375 } /*Print_fs_FullPerfInfo*/
376
377
378 /*------------------------------------------------------------------------
379  * afsmon_fsOutput()
380  *
381  * Description:
382  *      Prints the contents of xstat_fs_Results to an output file. The 
383  *      output is either in a compact (longs only) format or a detailed
384  *      format giving the names of each of the datums. Output is appended.
385  *
386  * Arguments:
387  *      Name of output file.
388  *      Flag to indicate if detailed output is required.
389  *
390  * Returns:
391  *      Nothing.
392  *
393  * Environment:
394  *      All the info we need is nestled into xstat_fs_Results.
395  *
396  * Side Effects:
397  *      As advertised.
398  *------------------------------------------------------------------------*/
399 int
400 afsmon_fsOutput(a_outfile, a_detOutput) 
401 char *a_outfile;                /* ptr to output file name */
402 int a_detOutput;                /* detailed output ? */
403 {
404
405    static char rn[] = "afsmon_fsOutput";        /* routine name */
406    char *printTime;                             /* ptr to time string */
407    char *hostname;                              /* fileserner name */
408    afs_int32 numLongs;                          /* longwords in result */
409    afs_int32 *currLong;                         /* ptr to longwords in result */
410    int i;
411    
412    if (afsmon_debug) {
413         fprintf(debugFD,"[ %s ] Called, a_outfile= %s, a_detOutput= %d\n",
414                 rn, a_outfile, a_detOutput);
415         fflush(debugFD);
416    }
417
418    fs_outFD = fopen(a_outfile,"a");
419    if (fs_outFD == (FILE *)0) {
420         sprintf(errMsg,"[ %s ] failed to open output file %s",rn,a_outfile);
421         afsmon_Exit(1);
422    }
423
424    /* get the probe time and strip the \n at the end */
425    printTime = ctime((time_t *)&(xstat_fs_Results.probeTime));
426    printTime[strlen(printTime) - 1] = '\0';
427    hostname = xstat_fs_Results.connP->hostName;
428    
429    /* print "time hostname FS" */
430    fprintf(fs_outFD,"\n%s %s FS ",printTime,hostname);
431
432    /* if probe failed print -1 and return */
433    if (xstat_fs_Results.probeOK) {
434         fprintf(fs_outFD,"-1\n");
435         fclose(fs_outFD);
436         return(0);
437    }
438
439    /* print out the probe information as  long words */
440    numLongs = xstat_fs_Results.data.AFS_CollData_len; 
441    currLong = (afs_int32 *)(xstat_fs_Results.data.AFS_CollData_val);
442
443    for(i=0; i<numLongs; i++) {
444         fprintf(fs_outFD,"%d ",*currLong++);
445    }
446    fprintf(fs_outFD,"\n\n");
447
448    /* print detailed information */
449    if (a_detOutput) {
450         Print_fs_FullPerfInfo(&xstat_fs_Results);
451         fflush(fs_outFD);
452    }
453
454    if ( fclose(fs_outFD)) 
455         if (afsmon_debug) {
456         fprintf(debugFD,"[ %s ] failed to close %s\n",rn,a_outfile);
457         fflush(debugFD);
458         }
459
460    return(0);
461 }
462    
463 /*___________________________________________________________________________
464                         CM STATS
465  *__________________________________________________________________________*/
466
467
468
469 /*------------------------------------------------------------------------
470  * Print_cm_UpDownStats
471  *
472  * Description:
473  *      Print the up/downtime stats for the given class of server records
474  *      provided.
475  *
476  * Arguments:
477  *      a_upDownP : Ptr to the server up/down info.
478  *
479  * Returns:
480  *      Nothing.
481  *
482  * Environment:
483  *      Nothing interesting.
484  *
485  * Side Effects:
486  *      As advertised.
487  *------------------------------------------------------------------------*/
488
489 void Print_cm_UpDownStats(a_upDownP)
490     struct afs_stats_SrvUpDownInfo *a_upDownP;  /*Ptr to server up/down info*/
491
492 { /*Print_cm_UpDownStats*/
493
494     /*
495      * First, print the simple values.
496      */
497     fprintf(cm_outFD,"\t\t%10d numTtlRecords\n",                a_upDownP->numTtlRecords);
498     fprintf(cm_outFD,"\t\t%10d numUpRecords\n",         a_upDownP->numUpRecords);
499     fprintf(cm_outFD,"\t\t%10d numDownRecords\n",               a_upDownP->numDownRecords);
500     fprintf(cm_outFD,"\t\t%10d sumOfRecordAges\n",      a_upDownP->sumOfRecordAges);
501     fprintf(cm_outFD,"\t\t%10d ageOfYoungestRecord\n",  a_upDownP->ageOfYoungestRecord);
502     fprintf(cm_outFD,"\t\t%10d ageOfOldestRecord\n",    a_upDownP->ageOfOldestRecord);
503     fprintf(cm_outFD,"\t\t%10d numDowntimeIncidents\n", a_upDownP->numDowntimeIncidents);
504     fprintf(cm_outFD,"\t\t%10d numRecordsNeverDown\n",  a_upDownP->numRecordsNeverDown);
505     fprintf(cm_outFD,"\t\t%10d maxDowntimesInARecord\n",        a_upDownP->maxDowntimesInARecord);
506     fprintf(cm_outFD,"\t\t%10d sumOfDowntimes\n",               a_upDownP->sumOfDowntimes);
507     fprintf(cm_outFD,"\t\t%10d shortestDowntime\n",     a_upDownP->shortestDowntime);
508     fprintf(cm_outFD,"\t\t%10d longestDowntime\n",      a_upDownP->longestDowntime);
509
510     /*
511      * Now, print the array values.
512      */
513     fprintf(cm_outFD,"\t\tDowntime duration distribution:\n");
514     fprintf(cm_outFD,"\t\t\t%8d: 0 min .. 10 min\n",  a_upDownP->downDurations[0]);
515     fprintf(cm_outFD,"\t\t\t%8d: 10 min .. 30 min\n", a_upDownP->downDurations[1]);
516     fprintf(cm_outFD,"\t\t\t%8d: 30 min .. 1 hr\n",   a_upDownP->downDurations[2]);
517     fprintf(cm_outFD,"\t\t\t%8d: 1 hr .. 2 hr\n",     a_upDownP->downDurations[3]);
518     fprintf(cm_outFD,"\t\t\t%8d: 2 hr .. 4 hr\n",     a_upDownP->downDurations[4]);
519     fprintf(cm_outFD,"\t\t\t%8d: 4 hr .. 8 hr\n",     a_upDownP->downDurations[5]);
520     fprintf(cm_outFD,"\t\t\t%8d: > 8 hr\n",           a_upDownP->downDurations[6]);
521
522     fprintf(cm_outFD,"\t\tDowntime incident distribution:\n");
523     fprintf(cm_outFD,"\t\t\t%8d: 0 times\n",        a_upDownP->downIncidents[0]);
524     fprintf(cm_outFD,"\t\t\t%8d: 1 time\n",         a_upDownP->downIncidents[1]);
525     fprintf(cm_outFD,"\t\t\t%8d: 2 .. 5 times\n",   a_upDownP->downIncidents[2]);
526     fprintf(cm_outFD,"\t\t\t%8d: 6 .. 10 times\n",  a_upDownP->downIncidents[3]);
527     fprintf(cm_outFD,"\t\t\t%8d: 10 .. 50 times\n", a_upDownP->downIncidents[4]);
528     fprintf(cm_outFD,"\t\t\t%8d: > 50 times\n",     a_upDownP->downIncidents[5]);
529
530 } /*Print_cm_UpDownStats*/
531
532
533 /*------------------------------------------------------------------------
534  * Print_cm_OverallPerfInfo
535  *
536  * Description:
537  *      Print out overall performance numbers.
538  *
539  * Arguments:
540  *      a_ovP : Ptr to the overall performance numbers.
541  *
542  * Returns:
543  *      Nothing.
544  *
545  * Environment:
546  *      All the info we need is nestled into xstat_cm_Results.
547  *
548  * Side Effects:
549  *      As advertised.
550  *------------------------------------------------------------------------*/
551
552 void Print_cm_OverallPerfInfo(a_ovP)
553     struct afs_stats_CMPerf *a_ovP;
554
555 { /*Print_cm_OverallPerfInfo*/
556
557     fprintf(cm_outFD,"\t%10d numPerfCalls\n",           a_ovP->numPerfCalls);
558
559     fprintf(cm_outFD,"\t%10d epoch\n",                  a_ovP->epoch);
560     fprintf(cm_outFD,"\t%10d numCellsVisible\n",        a_ovP->numCellsVisible);
561     fprintf(cm_outFD,"\t%10d numCellsContacted\n",      a_ovP->numCellsContacted);
562     fprintf(cm_outFD,"\t%10d dlocalAccesses\n",         a_ovP->dlocalAccesses);
563     fprintf(cm_outFD,"\t%10d vlocalAccesses\n",         a_ovP->vlocalAccesses);
564     fprintf(cm_outFD,"\t%10d dremoteAccesses\n",        a_ovP->dremoteAccesses);
565     fprintf(cm_outFD,"\t%10d vremoteAccesses\n",        a_ovP->vremoteAccesses);
566     fprintf(cm_outFD,"\t%10d cacheNumEntries\n",        a_ovP->cacheNumEntries);
567     fprintf(cm_outFD,"\t%10d cacheBlocksTotal\n",       a_ovP->cacheBlocksTotal);
568     fprintf(cm_outFD,"\t%10d cacheBlocksInUse\n",       a_ovP->cacheBlocksInUse);
569     fprintf(cm_outFD,"\t%10d cacheBlocksOrig\n",        a_ovP->cacheBlocksOrig);
570     fprintf(cm_outFD,"\t%10d cacheMaxDirtyChunks\n",a_ovP->cacheMaxDirtyChunks);
571     fprintf(cm_outFD,"\t%10d cacheCurrDirtyChunks\n",   a_ovP->cacheCurrDirtyChunks);
572     fprintf(cm_outFD,"\t%10d dcacheHits\n",             a_ovP->dcacheHits);
573     fprintf(cm_outFD,"\t%10d vcacheHits\n",             a_ovP->vcacheHits);
574     fprintf(cm_outFD,"\t%10d dcacheMisses\n",           a_ovP->dcacheMisses);
575     fprintf(cm_outFD,"\t%10d vcacheMisses\n",           a_ovP->vcacheMisses);
576     fprintf(cm_outFD,"\t%10d cacheFilesReused\n",       a_ovP->cacheFilesReused);
577     fprintf(cm_outFD,"\t%10d vcacheXAllocs\n",          a_ovP->vcacheXAllocs);
578
579     fprintf(cm_outFD,"\t%10d bufAlloced\n",             a_ovP->bufAlloced);
580     fprintf(cm_outFD,"\t%10d bufHits\n",                        a_ovP->bufHits);
581     fprintf(cm_outFD,"\t%10d bufMisses\n",              a_ovP->bufMisses);
582     fprintf(cm_outFD,"\t%10d bufFlushDirty\n",          a_ovP->bufFlushDirty);
583
584     fprintf(cm_outFD,"\t%10d LargeBlocksActive\n",      a_ovP->LargeBlocksActive);
585     fprintf(cm_outFD,"\t%10d LargeBlocksAlloced\n",     a_ovP->LargeBlocksAlloced);
586     fprintf(cm_outFD,"\t%10d SmallBlocksActive\n",      a_ovP->SmallBlocksActive);
587     fprintf(cm_outFD,"\t%10d SmallBlocksAlloced\n",     a_ovP->SmallBlocksAlloced);
588     fprintf(cm_outFD,"\t%10d OutStandingMemUsage\n",    a_ovP->OutStandingMemUsage);
589     fprintf(cm_outFD,"\t%10d OutStandingAllocs\n",      a_ovP->OutStandingAllocs);
590     fprintf(cm_outFD,"\t%10d CallBackAlloced\n",        a_ovP->CallBackAlloced);
591     fprintf(cm_outFD,"\t%10d CallBackFlushes\n",        a_ovP->CallBackFlushes);
592
593     fprintf(cm_outFD,"\t%10d srvRecords\n",             a_ovP->srvRecords);
594     fprintf(cm_outFD,"\t%10d srvNumBuckets\n",          a_ovP->srvNumBuckets);
595     fprintf(cm_outFD,"\t%10d srvMaxChainLength\n",      a_ovP->srvMaxChainLength);
596     fprintf(cm_outFD,"\t%10d srvMaxChainLengthHWM\n",   a_ovP->srvMaxChainLengthHWM);
597     fprintf(cm_outFD,"\t%10d srvRecordsHWM\n",          a_ovP->srvRecordsHWM);
598
599     fprintf(cm_outFD,"\t%10d sysName_ID\n",             a_ovP->sysName_ID);
600
601     fprintf(cm_outFD,"\tFile Server up/downtimes, same cell:\n");
602     Print_cm_UpDownStats(&(a_ovP->fs_UpDown[0]));
603
604     fprintf(cm_outFD,"\tFile Server up/downtimes, diff cell:\n");
605     Print_cm_UpDownStats(&(a_ovP->fs_UpDown[1]));
606
607     fprintf(cm_outFD,"\tVL Server up/downtimes, same cell:\n");
608     Print_cm_UpDownStats(&(a_ovP->vl_UpDown[0]));
609
610     fprintf(cm_outFD,"\tVL Server up/downtimes, diff cell:\n");
611     Print_cm_UpDownStats(&(a_ovP->vl_UpDown[1]));
612
613 } /*Print_cm_OverallPerfInfo*/
614
615
616 /*------------------------------------------------------------------------
617  * Print_cm_PerfInfo
618  *
619  * Description:
620  *      Print out the AFSCB_XSTATSCOLL_PERF_INFO collection we just
621  *      received.
622  *
623  * Arguments:
624  *      None.
625  *
626  * Returns:
627  *      Nothing.
628  *
629  * Environment:
630  *      All the info we need is nestled into xstat_cm_Results.
631  *
632  * Side Effects:
633  *      As advertised.
634  *------------------------------------------------------------------------*/
635
636 void Print_cm_PerfInfo()
637
638 { /*Print_cm_PerfInfo*/
639
640     static char rn[] = "Print_cm_PerfInfo";     /*Routine name*/
641     static afs_int32 perfLongs =
642         (sizeof(struct afs_stats_CMPerf) >> 2); /*Correct # longs to rcv*/
643     afs_int32 numLongs;                 /*# longwords received*/
644     struct afs_stats_CMPerf *perfP;     /*Ptr to performance stats*/
645     char *printableTime;                /*Ptr to printable time string*/
646
647     numLongs = xstat_cm_Results.data.AFSCB_CollData_len;
648     if (numLongs != perfLongs) {
649         fprintf(cm_outFD," ** Data size mismatch in performance collection!\n");
650         fprintf(cm_outFD,"** Expecting %d, got %d\n", perfLongs, numLongs);
651         return;
652     }
653
654     printableTime = ctime((time_t *)&(xstat_cm_Results.probeTime));
655     printableTime[strlen(printableTime)-1] = '\0';
656     perfP = (struct afs_stats_CMPerf *)
657         (xstat_cm_Results.data.AFSCB_CollData_val);
658
659     fprintf(cm_outFD,"AFSCB_XSTATSCOLL_PERF_INFO (coll %d) for CM %s\n[Probe %d, %s]\n\n",
660            xstat_cm_Results.collectionNumber,
661            xstat_cm_Results.connP->hostName,
662            xstat_cm_Results.probeNum,
663            printableTime);
664
665     Print_cm_OverallPerfInfo(perfP);
666
667 } /*Print_cm_PerfInfo*/
668
669
670 /*------------------------------------------------------------------------
671  * Print_cm_OpTiming
672  *
673  * Description:
674  *      Print out the contents of an FS RPC op timing structure.
675  *
676  * Arguments:
677  *      a_opIdx   : Index of the AFS operation we're printing number on.
678  *      a_opNames : Ptr to table of operaton names.
679  *      a_opTimeP : Ptr to the op timing structure to print.
680  *
681  * Returns:
682  *      Nothing.
683  *
684  * Environment:
685  *      Nothing interesting.
686  *
687  * Side Effects:
688  *      As advertised.
689  *------------------------------------------------------------------------*/
690
691 void Print_cm_OpTiming(a_opIdx, a_opNames, a_opTimeP)
692     int a_opIdx;
693     char *a_opNames[];
694     struct afs_stats_opTimingData *a_opTimeP;
695
696 { /*Print_cm_OpTiming*/
697
698     fprintf(cm_outFD,"%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
699            a_opNames[a_opIdx],
700            a_opTimeP->numOps, a_opTimeP->numSuccesses,
701            a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
702            a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
703            a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);
704
705 } /*Print_cm_OpTiming*/
706
707
708 /*------------------------------------------------------------------------
709  * Print_cm_XferTiming
710  *
711  * Description:
712  *      Print out the contents of a data transfer structure.
713  *
714  * Arguments:
715  *      a_opIdx : Index of the AFS operation we're printing number on.
716  *      a_xferP : Ptr to the data transfer structure to print.
717  *
718  * Returns:
719  *      Nothing.
720  *
721  * Environment:
722  *      Nothing interesting.
723  *
724  * Side Effects:
725  *      As advertised.
726  *------------------------------------------------------------------------*/
727
728 void Print_cm_XferTiming(a_opIdx, a_opNames, a_xferP)
729     int a_opIdx;
730     char *a_opNames[];
731     struct afs_stats_xferData *a_xferP;
732
733 { /*Print_cm_XferTiming*/
734
735     fprintf(cm_outFD,"%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
736            a_opNames[a_opIdx],
737            a_xferP->numXfers, a_xferP->numSuccesses,
738            a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
739            a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
740            a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
741     fprintf(cm_outFD,"\t[bytes: sum=%d, min=%d, max=%d]\n",
742            a_xferP->sumBytes, a_xferP->minBytes, a_xferP->maxBytes);
743     fprintf(cm_outFD,"\t[buckets: 0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d 6: %d, 7: %d, 8: %d]\n",
744            a_xferP->count[0],
745            a_xferP->count[1],
746            a_xferP->count[2],
747            a_xferP->count[3],
748            a_xferP->count[4],
749            a_xferP->count[5],
750            a_xferP->count[6],
751            a_xferP->count[7],
752            a_xferP->count[8]);
753
754 } /*Print_cm_XferTiming*/
755
756
757 /*------------------------------------------------------------------------
758  * Print_cm_ErrInfo
759  *
760  * Description:
761  *      Print out the contents of an FS RPC error info structure.
762  *
763  * Arguments:
764  *      a_opIdx   : Index of the AFS operation we're printing.
765  *      a_opNames : Ptr to table of operation names.
766  *      a_opErrP  : Ptr to the op timing structure to print.
767  *
768  * Returns:
769  *      Nothing.
770  *
771  * Environment:
772  *      Nothing interesting.
773  *
774  * Side Effects:
775  *      As advertised.
776  *------------------------------------------------------------------------*/
777
778 void Print_cm_ErrInfo(a_opIdx, a_opNames, a_opErrP)
779     int a_opIdx;
780     char *a_opNames[];
781     struct afs_stats_RPCErrors *a_opErrP;
782
783 { /*Print_cm_ErrInfo*/
784
785     fprintf(cm_outFD,"%15s: %d server, %d network, %d prot, %d vol, %d busies, %d other\n",
786            a_opNames[a_opIdx],
787            a_opErrP->err_Server,
788            a_opErrP->err_Network,
789            a_opErrP->err_Protection,
790            a_opErrP->err_Volume,
791            a_opErrP->err_VolumeBusies,
792            a_opErrP->err_Other);
793
794 } /*Print_cm_ErrInfo*/
795
796
797 /*------------------------------------------------------------------------
798  * Print_cm_RPCPerfInfo
799  *
800  * Description:
801  *      Print out a set of RPC performance numbers.
802  *
803  * Arguments:
804  *      a_rpcP : Ptr to RPC perf numbers to print.
805  *
806  * Returns:
807  *      Nothing.
808  *
809  * Environment:
810  *      Nothing interesting.
811  *
812  * Side Effects:
813  *      As advertised.
814  *------------------------------------------------------------------------*/
815
816 void Print_cm_RPCPerfInfo(a_rpcP)
817     struct afs_stats_RPCOpInfo *a_rpcP;
818
819 { /*Print_cm_RPCPerfInfo*/
820
821     int currIdx;                /*Loop variable*/
822
823     /*
824      * Print the contents of each of the opcode-related arrays.
825      */
826     fprintf(cm_outFD,"FS Operation Timings:\n---------------------\n");
827     for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; currIdx++)
828         Print_cm_OpTiming(currIdx, fsOpNames, &(a_rpcP->fsRPCTimes[currIdx]));
829
830     fprintf(cm_outFD,"\nError Info:\n-----------\n");
831     for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; currIdx++)
832         Print_cm_ErrInfo(currIdx, fsOpNames, &(a_rpcP->fsRPCErrors[currIdx]));
833
834     fprintf(cm_outFD,"\nTransfer timings:\n-----------------\n");
835     for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_XFER_OPS; currIdx++)
836         Print_cm_XferTiming(currIdx, xferOpNames, &(a_rpcP->fsXferTimes[currIdx]));
837
838     fprintf(cm_outFD,"\nCM Operation Timings:\n---------------------\n");
839     for (currIdx = 0; currIdx < AFS_STATS_NUM_CM_RPC_OPS; currIdx++)
840         Print_cm_OpTiming(currIdx, cmOpNames, &(a_rpcP->cmRPCTimes[currIdx]));
841
842 } /*Print_cm_RPCPerfInfo*/
843
844
845 /*------------------------------------------------------------------------
846  * Print_cm_FullPerfInfo
847  *
848  * Description:
849  *      Print out a set of full performance numbers.
850  *
851  * Arguments:
852  *      None.
853  *
854  * Returns:
855  *      Nothing.
856  *
857  * Environment:
858  *      Nothing interesting.
859  *
860  * Side Effects:
861  *      As advertised.
862  *------------------------------------------------------------------------*/
863
864 void Print_cm_FullPerfInfo()
865
866 { /*Print_cm_FullPerfInfo*/
867
868     static char rn[] = "Print_cm_FullPerfInfo"; /* routine name */
869     struct afs_stats_AuthentInfo *authentP;     /*Ptr to authentication stats*/
870     struct afs_stats_AccessInfo *accessinfP;    /*Ptr to access stats*/
871    static afs_int32 fullPerfLongs =
872         (sizeof (struct afs_stats_CMFullPerf) >> 2); /*Correct #longs*/
873     afs_int32 numLongs;                         /*# longs actually received*/
874     struct afs_stats_CMFullPerf *fullP;         /*Ptr to full perf info*/
875
876     char *printableTime;                        /*Ptr to printable time string*/
877
878     numLongs = xstat_cm_Results.data.AFSCB_CollData_len;
879     if (numLongs != fullPerfLongs) {
880         fprintf(cm_outFD," ** Data size mismatch in performance collection!\n");
881         fprintf(cm_outFD," ** Expecting %d, got %d\n",fullPerfLongs, numLongs);
882         return;
883     }
884
885     printableTime = ctime((time_t *)&(xstat_cm_Results.probeTime));
886     printableTime[strlen(printableTime)-1] = '\0';
887     fullP = (struct afs_stats_CMFullPerf *)
888         (xstat_cm_Results.data.AFSCB_CollData_val);
889
890     fprintf(cm_outFD,"AFSCB_XSTATSCOLL_FULL_PERF_INFO (coll %d) for CM %s\n[Probe %d, %s]\n\n",
891            xstat_cm_Results.collectionNumber,
892            xstat_cm_Results.connP->hostName,
893            xstat_cm_Results.probeNum,
894            printableTime);
895
896     /*
897      * Print the overall numbers first, followed by all of the RPC numbers,
898      * then each of the other groupings.
899      */
900     fprintf(cm_outFD,"Overall Performance Info:\n-------------------------\n");
901     Print_cm_OverallPerfInfo(&(fullP->perf));
902     fprintf(cm_outFD,"\n");
903     Print_cm_RPCPerfInfo(&(fullP->rpc));
904
905     authentP = &(fullP->authent);
906     fprintf(cm_outFD,"\nAuthentication info:\n--------------------\n");
907     fprintf(cm_outFD,"\t%d PAGS, %d records (%d auth, %d unauth), %d max in PAG, chain max: %d\n",
908            authentP->curr_PAGs,
909            authentP->curr_Records,
910            authentP->curr_AuthRecords,
911            authentP->curr_UnauthRecords,
912            authentP->curr_MaxRecordsInPAG,
913            authentP->curr_LongestChain);
914     fprintf(cm_outFD,"\t%d PAG creations, %d tkt updates\n",
915            authentP->PAGCreations,
916            authentP->TicketUpdates);
917     fprintf(cm_outFD,"\t[HWMs: %d PAGS, %d records, %d max in PAG, chain max: %d]\n",
918            authentP->HWM_PAGs,
919            authentP->HWM_Records,
920            authentP->HWM_MaxRecordsInPAG,
921            authentP->HWM_LongestChain);
922
923     accessinfP = &(fullP->accessinf);
924     fprintf(cm_outFD,"\n[Un]replicated accesses:\n------------------------\n");
925     fprintf(cm_outFD,"\t%d unrep, %d rep, %d reps accessed, %d max reps/ref, %d first OK\n\n",
926            accessinfP->unreplicatedRefs,
927            accessinfP->replicatedRefs,
928            accessinfP->numReplicasAccessed,
929            accessinfP->maxReplicasPerRef,
930            accessinfP->refFirstReplicaOK);
931
932     /* There really isn't any authorship info
933     authorP = &(fullP->author); */
934
935 } /*Print_cm_FullPerfInfo*/
936
937 /*------------------------------------------------------------------------
938  * afsmon_cmOutput()
939  *
940  * Description:
941  *      Prints the contents of xstat_cm_Results to an output file. The 
942  *      output is either in a compact (longs only) format or a detailed
943  *      format giving the names of each of the datums. Output is appended.
944  *
945  * Arguments:
946  *      Name of output file.
947  *      Flag to indicate if detailed output is required.
948  *
949  * Returns:
950  *      Nothing.
951  *
952  * Environment:
953  *      All the info we need is nestled into xstat_cm_Results.
954  *
955  * Side Effects:
956  *      As advertised.
957  *------------------------------------------------------------------------*/
958 int
959 afsmon_cmOutput(a_outfile, a_detOutput) 
960 char *a_outfile;                /* ptr to output file name */
961 int a_detOutput;                /* detailed output ? */
962 {
963
964    static char rn[] = "afsmon_cmOutput";        /* routine name */
965    char *printTime;                             /* ptr to time string */
966    char *hostname;                              /* fileserner name */
967    afs_int32 numLongs;                          /* longwords in result */
968    afs_int32 *currLong;                         /* ptr to longwords in result */
969    int i;
970    
971    if (afsmon_debug) {
972         fprintf(debugFD,"[ %s ] Called, a_outfile= %s, a_detOutput= %d\n",
973                 rn, a_outfile, a_detOutput);
974         fflush(debugFD);
975    }
976
977    /* need to lock this file before writing */
978    cm_outFD = fopen(a_outfile,"a");
979    if (cm_outFD == (FILE *)0) {
980         sprintf(errMsg,"[ %s ] failed to open output file %s",rn,a_outfile);
981         afsmon_Exit(1);
982    }
983
984    /* get the probe time and strip the \n at the end */
985    printTime = ctime((time_t *)&(xstat_cm_Results.probeTime));
986    printTime[strlen(printTime) - 1] = '\0';
987    hostname = xstat_cm_Results.connP->hostName;
988    
989    /* print "time hostname CM" prefix  */
990    fprintf(cm_outFD,"\n%s %s CM ",printTime,hostname);
991
992    /* if probe failed print -1 and vanish */
993    if (xstat_cm_Results.probeOK) {
994         fprintf(cm_outFD,"-1\n");
995         fclose(cm_outFD);
996         return(0);
997    }
998
999    /* print out the probe information as  long words */
1000    numLongs = xstat_cm_Results.data.AFSCB_CollData_len; 
1001    currLong = (afs_int32 *)(xstat_cm_Results.data.AFSCB_CollData_val);
1002
1003    for(i=0; i<numLongs; i++) {
1004         fprintf(cm_outFD,"%d ",*currLong++);
1005    }
1006    fprintf(cm_outFD,"\n\n");
1007
1008    /* print out detailed statistics */
1009    if (a_detOutput) {
1010         Print_cm_FullPerfInfo();
1011         fflush(cm_outFD);
1012    }
1013  
1014    if ( fclose(cm_outFD)) 
1015         if (afsmon_debug) {
1016         fprintf(debugFD,"[ %s ] failed to close %s\n",rn,a_outfile);
1017         fflush(debugFD);
1018         }
1019
1020    return(0);
1021 }