AFS-Monitor

 view release on metacpan or  search on metacpan

src/Monitor.xs  view on Meta::CPAN

      char *packet_type = rx_packetTypes[i];
      TYPE = newHV();
      hv_store(TYPE, "packetsRead", 11, newSViv(rxstats->packetsRead[i]), 0);
      hv_store(TYPE, "packetsSent", 11, newSViv(rxstats->packetsSent[i]), 0);
      if (packet_type == "unused") {
         /* rename "unused" types */
         /* can't have several entries in a hash with same name */
         char packet_type_unused[7];
         sprintf(packet_type_unused, "unused%d", num_unused);
         packet_type = packet_type_unused;
         num_unused++;
      }
      hv_store(PACKETS, packet_type, strlen(packet_type),
               newRV_inc((SV *) (TYPE)), 0);
   }
   hv_store(RXSTATS, "packets", 7, newRV_inc((SV *) (PACKETS)), 0);

   hv_store(RXSTATS, "dataPacketsRead", 15, newSViv(rxstats->dataPacketsRead),
            0);
   hv_store(RXSTATS, "ackPacketsRead", 14, newSViv(rxstats->ackPacketsRead),
            0);
   hv_store(RXSTATS, "dupPacketsRead", 14, newSViv(rxstats->dupPacketsRead),
            0);
   hv_store(RXSTATS, "spuriousPacketsRead", 19,
            newSViv(rxstats->spuriousPacketsRead), 0);
   hv_store(RXSTATS, "ignorePacketDally", 17,
            newSViv(rxstats->ignorePacketDally), 0);

   hv_store(RXSTATS, "pingPacketsSent", 15, newSViv(rxstats->pingPacketsSent),
            0);
   hv_store(RXSTATS, "abortPacketsSent", 16,
            newSViv(rxstats->abortPacketsSent), 0);
   hv_store(RXSTATS, "busyPacketsSent", 15, newSViv(rxstats->busyPacketsSent),
            0);

   hv_store(RXSTATS, "ackPacketsSent", 14, newSViv(rxstats->ackPacketsSent),
            0);
   hv_store(RXSTATS, "dataPacketsSent", 15, newSViv(rxstats->dataPacketsSent),
            0);
   hv_store(RXSTATS, "dataPacketsReSent", 17,
            newSViv(rxstats->dataPacketsReSent), 0);
   hv_store(RXSTATS, "dataPacketsPushed", 17,
            newSViv(rxstats->dataPacketsPushed), 0);
   hv_store(RXSTATS, "ignoreAckedPacket", 17,
            newSViv(rxstats->ignoreAckedPacket), 0);

   hv_store(RXSTATS, "netSendFailures", 15, newSViv(rxstats->netSendFailures),
            0);
   hv_store(RXSTATS, "fatalErrors", 11, newSViv(rxstats->fatalErrors), 0);

   hv_store(RXSTATS, "nServerConns", 12, newSViv(rxstats->nServerConns), 0);
   hv_store(RXSTATS, "nClientConns", 12, newSViv(rxstats->nClientConns), 0);
   hv_store(RXSTATS, "nPeerStructs", 12, newSViv(rxstats->nPeerStructs), 0);
   hv_store(RXSTATS, "nCallStructs", 12, newSViv(rxstats->nCallStructs), 0);
   hv_store(RXSTATS, "nFreeCallStructs", 16,
            newSViv(rxstats->nFreeCallStructs), 0);

   hv_store(RXSTATS, "nRttSamples", 11, newSViv(rxstats->nRttSamples), 0);

   TOTALRTT = newHV();
   hv_store(TOTALRTT, "sec", 3, newSViv(rxstats->totalRtt.sec), 0);
   hv_store(TOTALRTT, "usec", 4, newSViv(rxstats->totalRtt.usec), 0);
   hv_store(RXSTATS, "totalRtt", 8, newRV_inc((SV *) (TOTALRTT)), 0);
   MINRTT = newHV();
   hv_store(MINRTT, "sec", 3, newSViv(rxstats->minRtt.sec), 0);
   hv_store(MINRTT, "usec", 4, newSViv(rxstats->minRtt.usec), 0);
   hv_store(RXSTATS, "minRtt", 6, newRV_inc((SV *) (MINRTT)), 0);
   MAXRTT = newHV();
   hv_store(MAXRTT, "sec", 3, newSViv(rxstats->maxRtt.sec), 0);
   hv_store(MAXRTT, "usec", 4, newSViv(rxstats->maxRtt.usec), 0);
   hv_store(RXSTATS, "maxRtt", 6, newRV_inc((SV *) (MAXRTT)), 0);

#if !defined(AFS_PTHREAD_ENV) && !defined(AFS_USE_GETTIMEOFDAY)
   hv_store(RXSTATS, "clock_nUpdates", 14, newSViv(clock_nUpdates), 0);
#endif
}

/* end of rxdebug helper functions */





/* start of afsmonitor helper functions */

/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

#define FS 1    /* for misc. use */
#define CM 2    /* for misc. use */
#define CFG_STR_LEN 80  /* max length of config file fields */
#define NUM_XSTAT_FS_AFS_PERFSTATS_LONGS 66 /* number of fields (longs)
                                             * in struct afs_PerfStats */
#define NUM_AFS_STATS_CMPERF_LONGS 40   /* number of longs in struct afs_stats_CMPerf
                                         * excluding up/down stats and fields we dont display */


/*
 * from src/afsmonitor/afsmonitor.h
 *
 */

#define HOST_NAME_LEN 80    /* length of server/cm names */
#define THRESH_VAR_NAME_LEN 80  /* THRESHOLD STRUCTURE DEFINITIONS */
#define THRESH_VAR_LEN 16
#define NUM_FS_STAT_ENTRIES 271 /* number of file server statistics
                                 * entries to display */
#define FS_STAT_STRING_LEN 14   /* max length of each string above */
#define NUM_CM_STAT_ENTRIES 571 /* number of cache manager statistics
                                 * entries to display */
#define CM_STAT_STRING_LEN 14   /* max length of each string above */

#define FS_NUM_DATA_CATEGORIES 9    /* # of fs categories */
#define CM_NUM_DATA_CATEGORIES 16   /* # of cm categories */


/*
 * from src/xstat/xstat_fs.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 *

/*
 * We have to pass a port to Rx to start up our callback listener
 * service, but 7001 is already taken up by the Cache Manager.  So,
 * we make up our own.
 */
#define XSTAT_FS_CBPORT 7101

src/Monitor.xs  view on Meta::CPAN

 *
 */

/* structures to store info of hosts to be monitored */
struct afsmon_hostEntry {
   char hostName[HOST_NAME_LEN];    /* fs or cm host name */
   int numThresh;               /* number of thresholds for this host */
   struct Threshold *thresh;    /* ptr to threshold entries */
   struct afsmon_hostEntry *next;
};


/*
 * from src/afsmonitor/afsmonitor.h
 *
 */

/* structures to store statistics in a format convenient to dump to the
screen */
/* for file servers */
struct fs_Display_Data {
   char hostName[HOST_NAME_LEN];
   int probeOK;                 /* 0 => probe failed */
   char data[NUM_FS_STAT_ENTRIES][FS_STAT_STRING_LEN];
   short threshOvf[NUM_FS_STAT_ENTRIES];    /* overflow flags */
   int ovfCount;                /* overflow count */
};
/* for cache managers */
struct cm_Display_Data {
   char hostName[HOST_NAME_LEN];
   int probeOK;                 /* 0 => probe failed */
   char data[NUM_CM_STAT_ENTRIES][CM_STAT_STRING_LEN];
   short threshOvf[NUM_CM_STAT_ENTRIES];    /* overflow flags */
   int ovfCount;                /* overflow count */
};



/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

/* wouldn't compile without this, but it wasn't in original afsmonitor.c */
#if !defined(__USE_GNU) && !defined(__APPLE_CC__)
char *
strcasestr(char *s1, char *s2)
{
   char *ptr;
   int len1, len2;

   len1 = strlen(s1);
   len2 = strlen(s2);

   if (len1 < len2)
      return ((char *)NULL);

   ptr = s1;

   while (len1 >= len2 && len1 > 0) {
      if ((strncasecmp(ptr, s2, len2)) == 0)
         return (ptr);
      ptr++;
      len1--;
   }
   return ((char *)NULL);
}
#endif           /* __USE_GNU */


/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

struct hostent *
GetHostByName(char *name)
{
   struct hostent *he;
#ifdef AFS_SUN5_ENV
   char ip_addr[32];
#endif

   he = gethostbyname(name);
#ifdef AFS_SUN5_ENV
   /* On solaris the above does not resolve hostnames to full names */
   if (he != NULL) {
      memcpy(ip_addr, he->h_addr, he->h_length);
      he = gethostbyaddr(ip_addr, he->h_length, he->h_addrtype);
   }
#endif
   return (he);
}


/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

/*
 * Constructs a string to pass back to Perl for easy execution of the threshold handler.
 * DOES NOT execute the threshold handler.
 *
 * from src/afsmonitor/afsmonitor.c
 *
 * int
 * execute_thresh_handler(a_handler, a_hostName, a_hostType,
 *                         a_threshName,a_threshValue, a_actValue)
 * char *a_handler;
 * char *a_hostName;
 * int a_hostType;
 * char *a_threshName;
 * char *a_threshValue;
 * char *a_actValue;
 */

int
my_execute_thresh_handler(a_handler, a_hostName, a_hostType, a_threshName,
                          a_threshValue, a_actValue,
                          ENTRY, buffer)

src/Monitor.xs  view on Meta::CPAN

   }
   else {
      prev_item->next = curr_item;
   }

   prev_item = curr_item;
   /*  record the address of this entry so that its threshold */
   /* count can be incremented during  the first pass of the config file */
   (*last_hostEntry) = curr_item;

   return (0);
}   /* my_insert_CM() */



/*
 * parses a threshold entry line in the config file.
 *
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_parse_threshEntry(a_line, global_fsThreshCount, global_cmThreshCount,
                     last_hostEntry, lastHostType, buffer)
   char *a_line;                /* line that is being parsed */
   int *global_fsThreshCount;   /* count of global file server thresholds */
   int *global_cmThreshCount;   /* count of global cache manager thresholds */
   struct afsmon_hostEntry *last_hostEntry; /* a pointer to the last host entry */
   int lastHostType;            /* points to an integer specifying whether the last host was fs or cm */
   char *buffer;                /* to return error messages in */
{
   char opcode[CFG_STR_LEN];    /* junk characters */
   char arg1[CFG_STR_LEN];      /* hostname or qualifier (fs/cm?)  */
   char arg2[CFG_STR_LEN];      /* threshold variable */
   char arg3[CFG_STR_LEN];      /* threshold value */
   char arg4[CFG_STR_LEN];      /* user's handler  */
   char arg5[CFG_STR_LEN];      /* junk characters */


   /* break it up */
   opcode[0] = 0;
   arg1[0] = 0;
   arg2[0] = 0;
   arg3[0] = 0;
   arg4[0] = 0;
   arg5[0] = 0;
   sscanf(a_line, "%s %s %s %s %s %s", opcode, arg1, arg2, arg3, arg4, arg5);

   /* syntax is "thresh fs/cm variable_name threshold_value [handler] " */
   if (((strlen(arg1)) == 0) || ((strlen(arg2)) == 0)
       || ((strlen(arg3)) == 0)) {
      sprintf(buffer, "Incomplete line");
      return (-1);
   }
   if (strlen(arg3) > THRESH_VAR_LEN - 2) {
      sprintf(buffer, "threshold value too long");
      return (-1);
   }

   if ((strcasecmp(arg1, "fs")) == 0) {
      switch (lastHostType) {
        case 0:    /* its a global threshold */
           (*global_fsThreshCount)++;
           break;
        case 1:    /* inc thresh count of last file server */
           last_hostEntry->numThresh++;
           break;
        case 2:
           sprintf(buffer,
                   "A threshold for a File Server cannot be placed after a Cache Manager host entry in the config file");
           return (-1);
        default:
           sprintf(buffer, "Programming error 1");
           return (-1);
      }
   }
   else if ((strcasecmp(arg1, "cm")) == 0) {
      switch (lastHostType) {
        case 0:    /* its a global threshold */
           (*global_cmThreshCount)++;
           break;
        case 2:    /* inc thresh count of last cache manager */
           last_hostEntry->numThresh++;
           break;
        case 1:
           sprintf(buffer,
                   "A threshold for a Cache Manager cannot be placed after a File Server host entry in the config file");
           return (-1);
        default:
           sprintf(buffer, "Programming error 2");
           return (-1);
      }
   }
   else {
      sprintf(buffer,
              "Syntax error. Second argument should be \"fs\" or \"cm\"");
      return (-1);
   }

   return (0);
}   /* my_parse_threshEntry() */



/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_parse_showEntry(a_line, fs_showDefault, cm_showDefault, fs_showFlags,
                   cm_showFlags, buffer)
   char *a_line;
   int *fs_showDefault;
   int *cm_showDefault;
   short *fs_showFlags;
   short *cm_showFlags;
   char *buffer;
{

   char opcode[CFG_STR_LEN];    /* specifies type of config entry */
   char arg1[CFG_STR_LEN];      /* show fs or cm entry ? */
   char arg2[CFG_STR_LEN];      /* what we gotta show  */
   char arg3[CFG_STR_LEN];      /* junk */
   char catName[CFG_STR_LEN];   /* for category names */
   int numGroups = 0;           /* number of groups in a section */
   int fromIdx = 0;
   int toIdx = 0;
   int found = 0;
   int idx = 0;                 /* index to fs_categories[] */
   int i = 0;
   int j = 0;

   extern char *fs_varNames[];
   extern char *cm_varNames[];
   extern char *fs_categories[];    /* file server data category names */
   extern char *cm_categories[];    /* cache manager data category names */

   opcode[0] = 0;
   arg1[0] = 0;
   arg2[0] = 0;
   arg3[0] = 0;
   sscanf(a_line, "%s %s %s %s", opcode, arg1, arg2, arg3);

   if (arg3[0] != '\0') {
      sprintf(buffer, "Extraneous characters at end of line");
      return (-1);
   }

   if ((strcasecmp(arg1, "fs") != 0) && (strcasecmp(arg1, "cm") != 0)) {
      sprintf(buffer,
              "Second argument of \"show\" directive should be \"fs\" or \"cm\"");
      return (-1);
   }

   /* Each entry can either be a variable name or a section/group name. Variable
    * names are listed in xx_varNames[] and section/group names in xx_categories[].
    * The section/group names in xx_categiries[] also give the starting/ending
    * indices of the variables belonging to that section/group. These indices
    * are stored in order in xx_Display_map[] and displayed to the screen in that
    * order. */

   /* To handle duplicate "show" entries we keep track of what what we have
    * already marked to show in the xx_showFlags[] */

   if (strcasecmp(arg1, "fs") == 0) {   /* its a File Server entry */
      /* mark that we have to show only what the user wants */
      *fs_showDefault = 0;

      /* if it is a section/group name, find it in the fs_categories[] array */

      found = 0;
      if (strcasestr(arg2, "_section") != (char *)NULL
          || strcasestr(arg2, "_group") != (char *)NULL) {
         idx = 0;
         while (idx < FS_NUM_DATA_CATEGORIES) {
            sscanf(fs_categories[idx], "%s %d %d", catName, &fromIdx, &toIdx);
            idx++;
            if (strcasecmp(arg2, catName) == 0) {
               found = 1;
               break;
            }
         }

         if (!found) {  /* typo in section/group name */
            sprintf(buffer, "Could not find section/group name %s", arg2);
            return (-1);
         }
      }

        /* if it is a group name, read its start/end indices and fill in the
         * fs_Display_map[]. */

      if (strcasestr(arg2, "_group") != (char *)NULL) {

         if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_FS_STAT_ENTRIES ||
             toIdx > NUM_FS_STAT_ENTRIES)
            return (-2);
         for (j = fromIdx; j <= toIdx; j++) {
            fs_showFlags[j] = 1;
         }
      }

      /* if it is a section name */
      else if (strcasestr(arg2, "_section") != (char *)NULL) {
         /* fromIdx is actually the number of groups in this section */
         numGroups = fromIdx;
         /* for each group in section */
         while (idx < FS_NUM_DATA_CATEGORIES && numGroups) {
            sscanf(fs_categories[idx], "%s %d %d", catName, &fromIdx, &toIdx);

            if (strcasestr(catName, "_group") != (char *) NULL) {
               if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_FS_STAT_ENTRIES
                   || toIdx > NUM_FS_STAT_ENTRIES)
                  return (-4);
               for (j = fromIdx; j <= toIdx; j++) {
                  fs_showFlags[j] = 1;
               }
            }
            else {
               sprintf(buffer, "Error parsing groups for %s", arg2);
               return (-6);
            }
            idx++;
            numGroups--;
         }  /* for each group in section */

      }
      else {    /* it is a variable name */

         for (i = 0; i < NUM_FS_STAT_ENTRIES; i++) {
            if (strcasecmp(arg2, fs_varNames[i]) == 0) {
               fs_showFlags[i] = 1;
               found = 1;
               break;
            }
         }
         if (!found) {  /* typo in variable name */
            sprintf(buffer, "Could not find variable name %s", arg2);
            return (-1);
         }
      } /* its a variable name */

   }

    /* it is an fs entry */
   if (strcasecmp(arg1, "cm") == 0) {   /* its a Cache Manager entry */

      /* mark that we have to show only what the user wants */
      *cm_showDefault = 0;

      /* if it is a section/group name, find it in the cm_categories[] array */

      found = 0;
      if (strcasestr(arg2, "_section") != (char *)NULL
          || strcasestr(arg2, "_group") != (char *)NULL) {
         idx = 0;
         while (idx < CM_NUM_DATA_CATEGORIES) {
            sscanf(cm_categories[idx], "%s %d %d", catName, &fromIdx, &toIdx);
            idx++;
            if (strcasecmp(arg2, catName) == 0) {
               found = 1;
               break;
            }
         }

         if (!found) {  /* typo in section/group name */
            sprintf(buffer, "Could not find section/group name %s", arg2);
            return (-1);
         }
      }

      /* if it is a group name */

      if (strcasestr(arg2, "_group") != (char *)NULL) {

         if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_CM_STAT_ENTRIES
             || toIdx > NUM_CM_STAT_ENTRIES)
            return (-10);
         for (j = fromIdx; j <= toIdx; j++) {
            cm_showFlags[j] = 1;
         }
      }

      /* if it is a section name, get the count of number of groups in it and
       * for each group fill in the start/end indices in the cm_Display_map[] */

      else if (strcasestr(arg2, "_section") != (char *)NULL) {
         /* fromIdx is actually the number of groups in thi section */
         numGroups = fromIdx;
         /* for each group in section */
         while (idx < CM_NUM_DATA_CATEGORIES && numGroups) {
            sscanf(cm_categories[idx], "%s %d %d", catName, &fromIdx, &toIdx);

            if (strcasestr(catName, "_group") != (char *) NULL) {
               if (fromIdx < 0 || toIdx < 0 || fromIdx > NUM_CM_STAT_ENTRIES
                   || toIdx > NUM_CM_STAT_ENTRIES)
                  return (-12);
               for (j = fromIdx; j <= toIdx; j++) {
                  cm_showFlags[j] = 1;
               }
            }
            else {
               sprintf(buffer, "Error parsing groups for %s", arg2);
               return (-15);
            }
            idx++;
            numGroups--;
         }  /* for each group in section */
      }
      else {    /* it is a variable name */

         for (i = 0; i < NUM_CM_STAT_ENTRIES; i++) {
            if (strcasecmp(arg2, cm_varNames[i]) == 0) {
               cm_showFlags[i] = 1;
               found = 1;
               break;
            }
         }
         if (!found) {  /* typo in section/group name */
            sprintf(buffer, "Could not find variable name %s", arg2);
            return (-1);
         }
      } /* its a variable name */

   }    /* it is a cm entry */

   return (0);

}   /* my_parse_showEntry() */



/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_parse_hostEntry(a_line, numFS, numCM, lastHostType, last_hostEntry,
                   FSnameList, CMnameList, buffer)
   char *a_line;
   int *numFS;
   int *numCM;
   int *lastHostType;
   struct afsmon_hostEntry **last_hostEntry;
   struct afsmon_hostEntry **FSnameList;
   struct afsmon_hostEntry **CMnameList;
   char *buffer;
{
   char opcode[CFG_STR_LEN];
   char arg1[CFG_STR_LEN];
   char arg2[CFG_STR_LEN];
   struct hostent *he = 0;
   int code = 0;

   opcode[0] = 0;
   arg1[0] = 0;
   arg2[0] = 0;

   sscanf(a_line, "%s %s %s", opcode, arg1, arg2);
   if ((strlen(arg2)) != 0) {
      sprintf(buffer, "Extraneous characters at end of line");
      return (-1);
   }

   he = GetHostByName(arg1);
   if (he == NULL) {
      sprintf(buffer, "Unable to resolve hostname %s", arg1);
      return (-1);
   }

   if ((strcasecmp(opcode, "fs")) == 0) {
      /* use the complete host name to insert in the file server names list */
      code = my_insert_FS(he->h_name, FSnameList, last_hostEntry);
      if (code) {
         return (-1);
      }
      /* note that last host entry in the config file was fs */
      (*lastHostType) = 1;
      (*numFS)++;
   }
   else if ((strcasecmp(opcode, "cm")) == 0) {
      /* use the complete host name to insert in the CM names list */
      code = my_insert_CM(he->h_name, CMnameList, last_hostEntry);
      if (code)
         return (-1);
      /* last host entry in the config file was cm */
      (*lastHostType) = 2;
      (*numCM)++;
   }
   else {
      return (-1);
   }

   return (0);
}   /* my_parse_hostEntry() */



/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_store_threshold(a_type, a_varName, a_value, a_handler, global_TC,
                   Header, hostname, srvCount, buffer)
   int a_type;                  /* 1 = fs , 2 = cm */
   char *a_varName;             /* threshold name */
   char *a_value;               /* threshold value */
   char *a_handler;             /* threshold overflow handler */
   int *global_TC;              /* ptr to global_xxThreshCount */
   struct afsmon_hostEntry *Header; /* tmp ptr to hostEntry list header */
   char *hostname;
   int srvCount;                /* tmp count of host names */
   char *buffer;
{

   struct afsmon_hostEntry *tmp_host = 0;   /* tmp ptr to hostEntry */
   struct Threshold *threshP = 0;   /* tmp ptr to threshold list */
   int index = 0;               /* index to fs_varNames or cm_varNames */
   int found = 0;
   int done = 0;
   int i = 0, j = 0;

   /* resolve the threshold variable name */
   found = 0;
   if (a_type == FS) {  /* fs threshold */
      for (index = 0; index < NUM_FS_STAT_ENTRIES; index++) {
         if (strcasecmp(a_varName, fs_varNames[index]) == 0) {
            found = 1;
            break;
         }
      }
      if (!found) {
         sprintf(buffer, "Unknown FS threshold variable name %s", a_varName);
         return (-1);
      }
   }
   else if (a_type == CM) { /* cm threshold */
      for (index = 0; index < NUM_CM_STAT_ENTRIES; index++) {
         if (strcasecmp(a_varName, cm_varNames[index]) == 0) {
            found = 1;
            break;
         }
      }
      if (!found) {
         sprintf(buffer, "Unknown CM threshold variable name %s", a_varName);
         return (-1);
      }
   }
   else
      return (-1);

   /* if the global thresh count is not zero, place this threshold on
    * all the host entries  */

   if (*global_TC) {
      tmp_host = Header;
      for (i = 0; i < srvCount; i++) {
         threshP = tmp_host->thresh;
         done = 0;
         for (j = 0; j < tmp_host->numThresh; j++) {
            if ((threshP->itemName[0] == '\0') ||
                (strcasecmp(threshP->itemName, a_varName) == 0)) {
               strncpy(threshP->itemName, a_varName, THRESH_VAR_NAME_LEN);
               strncpy(threshP->threshVal, a_value, THRESH_VAR_LEN);
               strcpy(threshP->handler, a_handler);
               threshP->index = index;
               done = 1;
               break;
            }
            threshP++;
         }
         if (!done) {
            sprintf(buffer,
                    "Could not insert threshold entry for %s in thresh list of host %s",
                    a_varName, tmp_host->hostName);
            return (-1);
         }
         tmp_host = tmp_host->next;
      }
      (*global_TC)--;
      return (0);
   }

   /* it is not a global threshold, insert it in the thresh list of this
    * host only. We overwrite the global threshold if it was already set */

   if (*hostname == '\0') {
      sprintf(buffer, "Programming error 3");
      return (-1);
   }

   /* get the hostEntry that this threshold belongs to */
   tmp_host = Header;
   found = 0;
   for (i = 0; i < srvCount; i++) {
      if (strcasecmp(tmp_host->hostName, hostname) == 0) {
         found = 1;
         break;
      }
      tmp_host = tmp_host->next;
   }
   if (!found) {
      sprintf(buffer, "Unable to find host %s in %s hostEntry list", hostname,
              (a_type - 1) ? "CM" : "FS");
      return (-1);
   }

   /* put this entry on the thresh list of this host, overwrite global value
    * if needed */

   threshP = tmp_host->thresh;
   done = 0;
   for (i = 0; i < tmp_host->numThresh; i++) {
      if ((threshP->itemName[0] == '\0') ||
          (strcasecmp(threshP->itemName, a_varName) == 0)) {
         strncpy(threshP->itemName, a_varName, THRESH_VAR_NAME_LEN);
         strncpy(threshP->threshVal, a_value, THRESH_VAR_LEN);
         strcpy(threshP->handler, a_handler);
         threshP->index = index;
         done = 1;
         break;
      }
      threshP++;
   }

   if (!done) {
      sprintf(buffer, "Unable to insert threshold %s for %s host %s",
              a_varName, (a_type - 1) ? "CM" : "FS", tmp_host->hostName);
      return (-1);
   }

   return (0);

}   /* my_store_threshold() */



/*
 * from /src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 *
 * int
 * check_fs_thresholds(a_hostEntry, a_Data)
 * struct afsmon_hostEntry *a_hostEntry;
 * struct fs_Display_Data *a_Data;
 *
 * and
 *
 * int
 * check_cm_thresholds(a_hostEntry, a_Data)
 * struct afsmon_hostEntry *a_hostEntry;
 * struct cm_Display_Data *a_Data;
 */

int
my_check_thresholds(a_hostEntry, HOSTINFO, type, buffer)
   struct afsmon_hostEntry *a_hostEntry;    /* ptr to hostEntry */
   HV *HOSTINFO;                /* ptr to data to be displayed */
   int type;
   char *buffer;
{

   struct Threshold *threshP;
   double tValue = 0;           /* threshold value */
   double pValue = 0;           /* probe value */
   int i;
   int idx;
   int count;                   /* number of thresholds exceeded */
   HV *SECTION;
   HV *GROUP;
   HV *VALUE;
   int found;
   char *key;
   I32 keylen;
   char strval[256];

src/Monitor.xs  view on Meta::CPAN

   short *cm_showFlags;
   struct afsmon_hostEntry **FSnameList;
   struct afsmon_hostEntry **CMnameList;
{
   char buff1[256] = "";        /* for error messages */
   char buff2[256] = "";        /* for error messages returned from subroutines */
   FILE *configFD = 0;          /* config file descriptor */
   char line[4 * CFG_STR_LEN];  /* a line of config file */
   char opcode[CFG_STR_LEN];    /* specifies type of config entry */
   char arg1[CFG_STR_LEN];      /* hostname or qualifier (fs/cm?)  */
   char arg2[CFG_STR_LEN];      /* threshold variable */
   char arg3[CFG_STR_LEN];      /* threshold value */
   char arg4[CFG_STR_LEN];      /* user's handler  */
   struct afsmon_hostEntry *curr_host = 0;
   struct hostent *he = 0;      /* hostentry to resolve host name */
   char *handlerPtr = 0;        /* ptr to pass theresh handler string */
   int code = 0;                /* error code */
   int linenum = 0;             /* config file line number */
   int threshCount = 0;         /* count of thresholds for each server */
   int error_in_config = 0;     /* syntax errors in config file  ?? */
   int i = 0;
   int numBytes = 0;
   /* int global_ThreshFlag = 1; */
   int global_fsThreshCount = 0;
   int global_cmThreshCount = 0;
   static char last_fsHost[HOST_NAME_LEN];
   static char last_cmHost[HOST_NAME_LEN];

   /* open config file */
   configFD = fopen(a_config_filename, "r");
   if (configFD == (FILE *) NULL) {
      sprintf(buff1, "Failed to open config file %s", a_config_filename);
      BSETCODE(5, buff1);
      return (-1);
   }

   /* parse config file */

   /* First Pass - check syntax and count number of servers and thresholds to monitor */

   *numFS = 0;
   *numCM = 0;
   threshCount = 0;
   error_in_config = 0; /* flag to note if config file has syntax errors */

   while ((fgets(line, CFG_STR_LEN, configFD)) != NULL) {
      opcode[0] = 0;
      arg1[0] = 0;
      arg2[0] = 0;
      arg3[0] = 0;
      arg4[0] = 0;
      sscanf(line, "%s %s %s %s %s", opcode, arg1, arg2, arg3, arg4);
      linenum++;
      /* fprintf(STDERR, "Got line %d: \"%s %s %s %s %s\"\n",
       * linenum, opcode, arg1, arg2, arg3, arg4); */
      /* skip blank lines and comment lines */
      if ((strlen(opcode) == 0) || line[0] == '#') {
         /* fprintf(STDERR, " - skipping line %d\n", linenum); */
         continue;
      }
      if ((strcasecmp(opcode, "fs") == 0) || (strcasecmp(opcode, "cm")) == 0) {
         /* fprintf(STDERR, " - parsing host entry\n"); */
         code =
            my_parse_hostEntry(line, numFS, numCM, lastHostType,
                               last_hostEntry, FSnameList, CMnameList, buff2);
         /* thresholds are not global anymore */
         /* if (global_ThreshFlag) global_ThreshFlag = 0; */
      }
      else if ((strcasecmp(opcode, "thresh")) == 0) {
         /* fprintf(STDERR, " - parsing thresh entry\n"); */
         code =
            my_parse_threshEntry(line, &global_fsThreshCount,
                                 &global_cmThreshCount, *last_hostEntry,
                                 *lastHostType, buff2);
      }
      else if ((strcasecmp(opcode, "show")) == 0) {
         /* fprintf(STDERR, " - parsing show entry\n"); */
         code =
            my_parse_showEntry(line, fs_showDefault, cm_showDefault,
                               fs_showFlags, cm_showFlags, buff2);
      }
      else {
         /* fprintf(STDERR, " - unknown entry\n"); */
         sprintf(buff2, "Unknown opcode %s", opcode);
         code = 1;
      }

      if (code) {
         sprintf(buff1,
                 "Error processing config file line %d (\"%s %s %s %s %s\"). %s",
                 linenum, opcode, arg1, arg2, arg3, arg4, buff2);
         error_in_config = 1;
         BSETCODE(10, buff1);
         return (-1);
      }
   }
   /* fprintf(STDERR, "got to end of file.\n"); */

   if (error_in_config) {
      sprintf(buff1, "Error in config file. %s", buff2);
      BSETCODE(10, buff1);
      return (-1);
   }

   /* the threshold count of all hosts in increased by 1 for each global
    * threshold. If one of the hosts has a local threshold for the same
    * variable it would end up being counted twice. whats a few bytes of memory
    * wasted anyway ? */

   if (global_fsThreshCount) {
      curr_host = *FSnameList;
      for (i = 0; i < *numFS; i++) {
         curr_host->numThresh += global_fsThreshCount;
         curr_host = curr_host->next;
      }
   }
   if (global_cmThreshCount) {
      curr_host = *CMnameList;
      for (i = 0; i < *numCM; i++) {
         curr_host->numThresh += global_cmThreshCount;
         curr_host = curr_host->next;
      }
   }

   /* make sure we have something to monitor */
   if (*numFS == 0 && *numCM == 0) {
      sprintf(buff1,
              "Config file must specify atleast one File Server or Cache Manager host to monitor.");
      fclose(configFD);
      BSETCODE(15, buff1);
      return (-1);
   }

   /* Second Pass */

   fseek(configFD, 0, 0);   /* seek to the beginning */

src/Monitor.xs  view on Meta::CPAN

   /* allocate memory for threshold lists */

   curr_host = *FSnameList;
   for (i = 0; i < *numFS; i++) {
      if (curr_host->hostName[0] == '\0') {
         sprintf(buff1, "Programming error 4");
         BSETCODE(20, buff1);
         return (-1);
      }
      if (curr_host->numThresh) {
         numBytes = curr_host->numThresh * sizeof(struct Threshold);
         curr_host->thresh = (struct Threshold *)malloc(numBytes);
         if (curr_host->thresh == (struct Threshold *) NULL) {
            sprintf(buff1, "Memory Allocation error 1");
            BSETCODE(25, buff1);
            return (-1);
         }
         memset(curr_host->thresh, 0, numBytes);
      }
      curr_host = curr_host->next;
   }

   curr_host = *CMnameList;
   for (i = 0; i < *numCM; i++) {
      if (curr_host->hostName[0] == '\0') {
         sprintf(buff1, "Programming error 5");
         BSETCODE(30, buff1);
         return (-1);
      }
      if (curr_host->numThresh) {
         numBytes = curr_host->numThresh * sizeof(struct Threshold);
         curr_host->thresh = (struct Threshold *)malloc(numBytes);
         if (curr_host->thresh == (struct Threshold *) NULL) {
            sprintf(buff1, "Memory Allocation error 2");
            BSETCODE(35, buff1);
            return (-1);
         }
         memset(curr_host->thresh, 0, numBytes);
      }
      curr_host = curr_host->next;
   }

   opcode[0] = 0;
   arg1[0] = 0;
   arg2[0] = 0;
   arg3[0] = 0;
   arg4[0] = 0;
   last_fsHost[0] = '\0';
   last_cmHost[0] = '\0';
   linenum = 0;
   while ((fgets(line, CFG_STR_LEN, configFD)) != NULL) {
      opcode[0] = 0;
      arg1[0] = 0;
      arg2[0] = 0;
      arg3[0] = 0;
      arg4[0] = 0;
      sscanf(line, "%s %s %s %s %s", opcode, arg1, arg2, arg3, arg4);
      linenum++;

      /* if we have a host entry, remember the host name */
      if (strcasecmp(opcode, "fs") == 0) {
         he = GetHostByName(arg1);
         strncpy(last_fsHost, he->h_name, HOST_NAME_LEN);
      }
      else if (strcasecmp(opcode, "cm") == 0) {
         he = GetHostByName(arg1);
         strncpy(last_cmHost, he->h_name, HOST_NAME_LEN);
      }
      else if (strcasecmp(opcode, "thresh") == 0) {
         /* if we have a threshold handler it may have arguments
          * and the sscanf() above would not get them, so do the
          * following */
         if (strlen(arg4)) {
            handlerPtr = line;
            /* now skip over 4 words - this is done by first
             * skipping leading blanks then skipping a word */
            for (i = 0; i < 4; i++) {
               while (isspace(*handlerPtr))
                  handlerPtr++;
               while (!isspace(*handlerPtr))
                  handlerPtr++;
            }
            while (isspace(*handlerPtr))
               handlerPtr++;
            /* we how have a pointer to the start of the handler
             * name & args */
         }
         else
            handlerPtr = arg4;  /* empty string */

         if (strcasecmp(arg1, "fs") == 0)
            code = my_store_threshold(1,    /* 1 = fs */
                                      arg2, arg3, handlerPtr,
                                      &global_fsThreshCount, *FSnameList,
                                      last_fsHost, *numFS, buff2);

         else if (strcasecmp(arg1, "cm") == 0)
            code = my_store_threshold(2,    /* 2 = cm */
                                      arg2, arg3, handlerPtr,
                                      &global_cmThreshCount, *CMnameList,
                                      last_cmHost, *numCM, buff2);

         else {
            sprintf(buff1, "Programming error 6");
            BSETCODE(40, buff1);
            return (-1);
         }
         if (code) {
            sprintf(buff1,
                    "Error processing config file line %d (\"%s %s %s %s %s\"): Failed to store threshold. %s",
                    linenum, opcode, arg1, arg2, arg3, arg4, buff2);
            BSETCODE(45, buff1);
            return (-1);
         }
      }
   }

   fclose(configFD);
   return (0);
}   /* my_process_config_file() */




/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_fs_OpTiming(a_opIdx, a_opTimeP, fs_outFD)
   int a_opIdx;
   struct fs_stats_opTimingData *a_opTimeP;
   FILE *fs_outFD;
{

   fprintf(fs_outFD,
           "%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           fsOpNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
           a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
           a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
           a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);
}   /* my_Print_fs_OpTiming() */


/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_fs_XferTiming(a_opIdx, a_xferP, fs_outFD)
   int a_opIdx;
   struct fs_stats_xferData *a_xferP;
   FILE *fs_outFD;
{

   fprintf(fs_outFD,
           "%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           xferOpNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
           a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
           a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
           a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
   fprintf(fs_outFD, "\t[bytes: sum=%d, min=%d, max=%d]\n",
           a_xferP->sumBytes, a_xferP->minBytes, a_xferP->maxBytes);
   fprintf(fs_outFD,
           "\t[buckets: 0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d 6: %d, 7: %d, 8: %d]\n",
           a_xferP->count[0], a_xferP->count[1], a_xferP->count[2],
           a_xferP->count[3], a_xferP->count[4], a_xferP->count[5],
           a_xferP->count[6], a_xferP->count[7], a_xferP->count[8]);
}   /* my_Print_fs_XferTiming() */



/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_fs_OverallPerfInfo(a_ovP, fs_outFD)
   struct afs_PerfStats *a_ovP;
   FILE *fs_outFD;
{

   fprintf(fs_outFD, "\t%10d numPerfCalls\n\n", a_ovP->numPerfCalls);

   /*
    * Vnode cache section.
    */
   fprintf(fs_outFD, "\t%10d vcache_L_Entries\n", a_ovP->vcache_L_Entries);
   fprintf(fs_outFD, "\t%10d vcache_L_Allocs\n", a_ovP->vcache_L_Allocs);
   fprintf(fs_outFD, "\t%10d vcache_L_Gets\n", a_ovP->vcache_L_Gets);
   fprintf(fs_outFD, "\t%10d vcache_L_Reads\n", a_ovP->vcache_L_Reads);
   fprintf(fs_outFD, "\t%10d vcache_L_Writes\n\n", a_ovP->vcache_L_Writes);

   fprintf(fs_outFD, "\t%10d vcache_S_Entries\n", a_ovP->vcache_S_Entries);
   fprintf(fs_outFD, "\t%10d vcache_S_Allocs\n", a_ovP->vcache_S_Allocs);
   fprintf(fs_outFD, "\t%10d vcache_S_Gets\n", a_ovP->vcache_S_Gets);
   fprintf(fs_outFD, "\t%10d vcache_S_Reads\n", a_ovP->vcache_S_Reads);
   fprintf(fs_outFD, "\t%10d vcache_S_Writes\n\n", a_ovP->vcache_S_Writes);

   fprintf(fs_outFD, "\t%10d vcache_H_Entries\n", a_ovP->vcache_H_Entries);
   fprintf(fs_outFD, "\t%10d vcache_H_Gets\n", a_ovP->vcache_H_Gets);
   fprintf(fs_outFD, "\t%10d vcache_H_Replacements\n\n",
           a_ovP->vcache_H_Replacements);

   /*
    * Directory package section.
    */
   fprintf(fs_outFD, "\t%10d dir_Buffers\n", a_ovP->dir_Buffers);
   fprintf(fs_outFD, "\t%10d dir_Calls\n", a_ovP->dir_Calls);
   fprintf(fs_outFD, "\t%10d dir_IOs\n\n", a_ovP->dir_IOs);

   /*
    * Rx section.
    */
   fprintf(fs_outFD, "\t%10d rx_packetRequests\n", a_ovP->rx_packetRequests);
   fprintf(fs_outFD, "\t%10d rx_noPackets_RcvClass\n",
           a_ovP->rx_noPackets_RcvClass);
   fprintf(fs_outFD, "\t%10d rx_noPackets_SendClass\n",
           a_ovP->rx_noPackets_SendClass);
   fprintf(fs_outFD, "\t%10d rx_noPackets_SpecialClass\n",
           a_ovP->rx_noPackets_SpecialClass);
   fprintf(fs_outFD, "\t%10d rx_socketGreedy\n", a_ovP->rx_socketGreedy);
   fprintf(fs_outFD, "\t%10d rx_bogusPacketOnRead\n",
           a_ovP->rx_bogusPacketOnRead);
   fprintf(fs_outFD, "\t%10d rx_bogusHost\n", a_ovP->rx_bogusHost);
   fprintf(fs_outFD, "\t%10d rx_noPacketOnRead\n", a_ovP->rx_noPacketOnRead);
   fprintf(fs_outFD, "\t%10d rx_noPacketBuffersOnRead\n",
           a_ovP->rx_noPacketBuffersOnRead);
   fprintf(fs_outFD, "\t%10d rx_selects\n", a_ovP->rx_selects);
   fprintf(fs_outFD, "\t%10d rx_sendSelects\n", a_ovP->rx_sendSelects);
   fprintf(fs_outFD, "\t%10d rx_packetsRead_RcvClass\n",
           a_ovP->rx_packetsRead_RcvClass);
   fprintf(fs_outFD, "\t%10d rx_packetsRead_SendClass\n",
           a_ovP->rx_packetsRead_SendClass);
   fprintf(fs_outFD, "\t%10d rx_packetsRead_SpecialClass\n",
           a_ovP->rx_packetsRead_SpecialClass);
   fprintf(fs_outFD, "\t%10d rx_dataPacketsRead\n",
           a_ovP->rx_dataPacketsRead);
   fprintf(fs_outFD, "\t%10d rx_ackPacketsRead\n", a_ovP->rx_ackPacketsRead);
   fprintf(fs_outFD, "\t%10d rx_dupPacketsRead\n", a_ovP->rx_dupPacketsRead);
   fprintf(fs_outFD, "\t%10d rx_spuriousPacketsRead\n",
           a_ovP->rx_spuriousPacketsRead);
   fprintf(fs_outFD, "\t%10d rx_packetsSent_RcvClass\n",
           a_ovP->rx_packetsSent_RcvClass);
   fprintf(fs_outFD, "\t%10d rx_packetsSent_SendClass\n",
           a_ovP->rx_packetsSent_SendClass);
   fprintf(fs_outFD, "\t%10d rx_packetsSent_SpecialClass\n",
           a_ovP->rx_packetsSent_SpecialClass);
   fprintf(fs_outFD, "\t%10d rx_ackPacketsSent\n", a_ovP->rx_ackPacketsSent);
   fprintf(fs_outFD, "\t%10d rx_pingPacketsSent\n",
           a_ovP->rx_pingPacketsSent);
   fprintf(fs_outFD, "\t%10d rx_abortPacketsSent\n",
           a_ovP->rx_abortPacketsSent);
   fprintf(fs_outFD, "\t%10d rx_busyPacketsSent\n",
           a_ovP->rx_busyPacketsSent);
   fprintf(fs_outFD, "\t%10d rx_dataPacketsSent\n",
           a_ovP->rx_dataPacketsSent);
   fprintf(fs_outFD, "\t%10d rx_dataPacketsReSent\n",
           a_ovP->rx_dataPacketsReSent);
   fprintf(fs_outFD, "\t%10d rx_dataPacketsPushed\n",
           a_ovP->rx_dataPacketsPushed);
   fprintf(fs_outFD, "\t%10d rx_ignoreAckedPacket\n",
           a_ovP->rx_ignoreAckedPacket);
   fprintf(fs_outFD, "\t%10d rx_totalRtt_Sec\n", a_ovP->rx_totalRtt_Sec);
   fprintf(fs_outFD, "\t%10d rx_totalRtt_Usec\n", a_ovP->rx_totalRtt_Usec);
   fprintf(fs_outFD, "\t%10d rx_minRtt_Sec\n", a_ovP->rx_minRtt_Sec);
   fprintf(fs_outFD, "\t%10d rx_minRtt_Usec\n", a_ovP->rx_minRtt_Usec);
   fprintf(fs_outFD, "\t%10d rx_maxRtt_Sec\n", a_ovP->rx_maxRtt_Sec);
   fprintf(fs_outFD, "\t%10d rx_maxRtt_Usec\n", a_ovP->rx_maxRtt_Usec);
   fprintf(fs_outFD, "\t%10d rx_nRttSamples\n", a_ovP->rx_nRttSamples);
   fprintf(fs_outFD, "\t%10d rx_nServerConns\n", a_ovP->rx_nServerConns);
   fprintf(fs_outFD, "\t%10d rx_nClientConns\n", a_ovP->rx_nClientConns);
   fprintf(fs_outFD, "\t%10d rx_nPeerStructs\n", a_ovP->rx_nPeerStructs);
   fprintf(fs_outFD, "\t%10d rx_nCallStructs\n", a_ovP->rx_nCallStructs);
   fprintf(fs_outFD, "\t%10d rx_nFreeCallStructs\n\n",
           a_ovP->rx_nFreeCallStructs);

   /*
    * Host module fields.
    */
   fprintf(fs_outFD, "\t%10d host_NumHostEntries\n",
           a_ovP->host_NumHostEntries);
   fprintf(fs_outFD, "\t%10d host_HostBlocks\n", a_ovP->host_HostBlocks);
   fprintf(fs_outFD, "\t%10d host_NonDeletedHosts\n",
           a_ovP->host_NonDeletedHosts);
   fprintf(fs_outFD, "\t%10d host_HostsInSameNetOrSubnet\n",
           a_ovP->host_HostsInSameNetOrSubnet);
   fprintf(fs_outFD, "\t%10d host_HostsInDiffSubnet\n",
           a_ovP->host_HostsInDiffSubnet);
   fprintf(fs_outFD, "\t%10d host_HostsInDiffNetwork\n",
           a_ovP->host_HostsInDiffNetwork);
   fprintf(fs_outFD, "\t%10d host_NumClients\n", a_ovP->host_NumClients);
   fprintf(fs_outFD, "\t%10d host_ClientBlocks\n\n",
           a_ovP->host_ClientBlocks);

}   /* my_Print_fs_OverallPerfInfo() */



/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_fs_DetailedPerfInfo(a_detP, fs_outFD)
   struct fs_stats_DetailedStats *a_detP;
   FILE *fs_outFD;
{

   int currIdx = 0;             /*Loop variable */
   fprintf(fs_outFD, "\t%10d epoch\n", a_detP->epoch);
   for (currIdx = 0; currIdx < FS_STATS_NUM_RPC_OPS; currIdx++)
      my_Print_fs_OpTiming(currIdx, &(a_detP->rpcOpTimes[currIdx]), fs_outFD);
   for (currIdx = 0; currIdx < FS_STATS_NUM_XFER_OPS; currIdx++)
      my_Print_fs_XferTiming(currIdx, &(a_detP->xferOpTimes[currIdx]),
                             fs_outFD);
}   /* my_Print_fs_DetailedPerfInfo() */


/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_fs_FullPerfInfo(a_fs_Results, fs_outFD)
   struct xstat_fs_ProbeResults *a_fs_Results;
   FILE *fs_outFD;

src/Monitor.xs  view on Meta::CPAN

      sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* max time */
      sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
   }

   /* copy fs transfer timings */

   srcbuf = (afs_int32 *) (fullPerfP->det.xferOpTimes);
   for (i = 0; i < FS_STATS_NUM_XFER_OPS; i++) {
      sprintf(a_fsData->data[idx], "%d", *srcbuf);  /* numOps */
      idx++;
      srcbuf++;
      sprintf(a_fsData->data[idx], "%d", *srcbuf);  /* numSuccesses */
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* sum time */
      sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* sqr time */
      sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* min time */
      sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* max time */
      sprintf(a_fsData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      sprintf(a_fsData->data[idx], "%d", *srcbuf);  /* sum bytes */
      idx++;
      srcbuf++;
      sprintf(a_fsData->data[idx], "%d", *srcbuf);  /* min bytes */
      idx++;
      srcbuf++;
      sprintf(a_fsData->data[idx], "%d", *srcbuf);  /* max bytes */
      idx++;
      srcbuf++;
      for (j = 0; j < FS_STATS_NUM_XFER_BUCKETS; j++) {
         sprintf(a_fsData->data[idx], "%d", *srcbuf);   /* bucket[j] */
         idx++;
         srcbuf++;
      }
   }

   return (0);
}   /* my_fs_Results_ltoa() */



void
fs_Results_to_Hash(struct fs_Display_Data *fsData, HV *HOSTINFO,
                   short *showFlags, int showDefault)
{
   int secidx;
   int grpidx;
   int numgrp;
   int fromidx;
   int toidx;
   char section[CFG_STR_LEN] = "";
   char group[CFG_STR_LEN] = "";
   HV *ENTRY;
   HV *GROUP;
   HV *SECTION;
   int i;

   secidx = 0;
   grpidx = secidx + 1;

   while (secidx < FS_NUM_DATA_CATEGORIES) {

      sscanf(fs_categories[secidx], "%s %d", section, &numgrp);
      SECTION = newHV();

      while (grpidx <= secidx + numgrp) {
         GROUP = newHV();
         sscanf(fs_categories[grpidx], "%s %d %d", group, &fromidx, &toidx);
         for (i = fromidx; i <= toidx; i++) {
            if (showFlags[i] || showDefault) {
               ENTRY = newHV();
               hv_store(ENTRY, "value", 5, newSVnv(atof(fsData->data[i])), 0);
               hv_store(GROUP, fs_varNames[i], strlen(fs_varNames[i]),
                        newRV_inc((SV *) ENTRY), 0);
            }
         }
         if (HvKEYS(GROUP))
            hv_store(SECTION, group, strlen(group), newRV_inc((SV *) GROUP),
                     0);
         grpidx++;
      }
      if (HvKEYS(SECTION))
         hv_store(HOSTINFO, section, strlen(section),
                  newRV_inc((SV *) SECTION), 0);
      secidx += numgrp + 1;
      grpidx = secidx + 1;
   }
}   /* fs_Results_to_Hash() */



/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_save_FS_data_forDisplay(a_fsResults, HOSTINFO, numFS, FSnameList,
                           fs_showFlags, fs_showDefault, buffer)
   struct xstat_fs_ProbeResults *a_fsResults;
   HV *HOSTINFO;
   int numFS;
   struct afsmon_hostEntry *FSnameList;
   short *fs_showFlags;
   int fs_showDefault;
   char *buffer;
{
   struct fs_Display_Data *curr_fsDataP;
   struct afsmon_hostEntry *curr_host = 0;
   int i = 0;
   int code = 0;
   int done = 0;
   char buff2[256] = "";

   curr_fsDataP =
      (struct fs_Display_Data *)malloc(sizeof(struct fs_Display_Data));
   if (curr_fsDataP == (struct fs_Display_Data *) NULL) {
      sprintf(buffer, "Memory allocation failure");
      return (-1);
   }
   memset(curr_fsDataP, 0, sizeof(struct fs_Display_Data));

   hv_store(HOSTINFO, "hostName", 8, newSVpv(a_fsResults->connP->hostName, 0),
            0);

   /*  Check the status of the probe. If it succeeded, we store its
    * results in the display data structure. If it failed we only mark
    * the failed status in the display data structure. */

   if (a_fsResults->probeOK) {  /* 1 => notOK the xstat results */
      hv_store(HOSTINFO, "probeOK", 7, newSViv(0), 0);
   }
   else {   /* probe succeeded, update display data structures */
      hv_store(HOSTINFO, "probeOK", 7, newSViv(1), 0);

      my_fs_Results_ltoa(curr_fsDataP, a_fsResults);

      fs_Results_to_Hash(curr_fsDataP, HOSTINFO, fs_showFlags,
                         fs_showDefault);

      /* compare with thresholds and set the overflow flags.
       * note that the threshold information is in the hostEntry structure and
       * each threshold item has a positional index associated with it */

      /* locate the hostEntry for this host */
      done = 0;
      curr_host = FSnameList;
      for (i = 0; i < numFS; i++) {
         if (strcasecmp(curr_host->hostName, a_fsResults->connP->hostName)
             == 0) {
            done = 1;
            break;
         }
         curr_host = curr_host->next;;
      }
      if (!done) {
         sprintf(buffer, "Error storing results for FS host %s (70)",
                 a_fsResults->connP->hostName);
         return (70);
      }

      code = my_check_thresholds(curr_host, HOSTINFO, FS, buff2);
      if (code) {
         sprintf(buffer, "Error in checking thresholds (75) %s", buff2);
         return (75);
      }

   }    /* the probe succeeded, so we store the data in the display structure */
   return (0);

}   /* my_save_FS_data_forDisplay() */



/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_afsmon_FS_Handler(xstat_fs_Results, numFS, conn_idx, buffer, argp)
   struct xstat_fs_ProbeResults xstat_fs_Results;
   int numFS;
   int conn_idx;
   char *buffer;
   va_list argp;
{
   char *outputfile = va_arg(argp, char *);
   int detailed = va_arg(argp, int);
   AV *FILESERV = va_arg(argp, AV *);
   struct afsmon_hostEntry *FSnameList =
      va_arg(argp, struct afsmon_hostEntry *);
   short *fs_showFlags = va_arg(argp, short *);
   int fs_showDefault = va_arg(argp, int);

   HV *HOSTINFO = newHV();

   int code = 0;

   if (outputfile)
      my_afsmon_fsOutput(outputfile, detailed, xstat_fs_Results);

   /* add everything to data structure */
   code =
      my_save_FS_data_forDisplay(&xstat_fs_Results, HOSTINFO, numFS,
                                 FSnameList, fs_showFlags, fs_showDefault,
                                 buffer);
   if (code) {
      return (code);

src/Monitor.xs  view on Meta::CPAN


         currCollIDP = xstat_fs_collIDP;
         for (numColls = 0;
              numColls < xstat_fs_numCollections; numColls++, currCollIDP++) {
            /*
             * Initialize the per-probe values.
             */
            xstat_fs_Results.collectionNumber = *currCollIDP;
            xstat_fs_Results.data.AFS_CollData_len = AFS_MAX_XSTAT_LONGS;
            memset(xstat_fs_Results.data.AFS_CollData_val, 0,
                   AFS_MAX_XSTAT_LONGS * 4);

            xstat_fs_Results.connP = curr_conn;

            xstat_fs_Results.probeOK =
               RXAFS_GetXStats(curr_conn->rxconn,
                               clientVersionNumber,
                               *currCollIDP,
                               &srvVersionNumber,
                               &(xstat_fs_Results.probeTime),
                               &(xstat_fs_Results.data));
            code =
               ProbeHandler(xstat_fs_Results, xstat_fs_numServers, index,
                            buff2, argp);
            index++;

            if (code) {
               sprintf(buffer, "Handler returned error code %d. %s",
                       code, buff2);
               return (code);
            }

         }  /* For each collection */
      } /*Valid Rx connection */

      /*
       * Advance the xstat_fs connection pointer.
       */
      curr_conn++;

   }    /* For each xstat_fs connection */
   return (0);
}   /* my_xstat_fs_LWP() */


/*
 * from src/xstat/xstat_fs.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_xstat_fs_Init(int (*ProbeHandler) (), int xstat_fs_numServers,
                 struct sockaddr_in *a_socketArray,
                 int xstat_fs_numCollections, afs_int32 * xstat_fs_collIDP,
                 char *buffer, ...)
{
   int curr_srv = 0;
   int conn_err = 0;
   char *hostNameFound = "";
   struct xstat_fs_ConnectionInfo *curr_conn = 0, *xstat_fs_ConnInfo = 0;
   struct rx_securityClass *secobj = 0; /*Client security object */
   char buff2[256] = "";
   int PortToUse = 0;
   int code = 0;
   va_list argp;

   xstat_fs_ConnInfo = (struct xstat_fs_ConnectionInfo *)
      malloc(xstat_fs_numServers * sizeof(struct xstat_fs_ConnectionInfo));
   if (xstat_fs_ConnInfo == (struct xstat_fs_ConnectionInfo *) NULL) {
      sprintf(buffer,
              "Can't allocate %d connection info structs (%d bytes)",
              xstat_fs_numServers,
              (xstat_fs_numServers * sizeof(struct xstat_fs_ConnectionInfo)));
      return (-1);  /*No cleanup needs to be done yet */
   }

   PortToUse = XSTAT_FS_CBPORT;

   do {
      code = rx_Init(htons(PortToUse));
      if (code) {
         if (code == RX_ADDRINUSE) {
            PortToUse++;
         }
         else {
            sprintf(buffer, "Fatal error in rx_Init()");
            return (-1);
         }
      }
   } while (code);

    /*
     * Create a null Rx client security object, to be used by the
     * probe LWP.
     */
   secobj = rxnull_NewClientSecurityObject();
   if (secobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_xstat_fs_Cleanup(1, xstat_fs_numServers, xstat_fs_ConnInfo, buff2);
      sprintf(buffer, "Can't create probe LWP client security object. %s",
              buff2);
      return (-1);
   }

   curr_conn = xstat_fs_ConnInfo;
   conn_err = 0;
   for (curr_srv = 0; curr_srv < xstat_fs_numServers; curr_srv++) {
      /*
       * Copy in the socket info for the current server, resolve its
       * printable name if possible.
       */

      memcpy(&(curr_conn->skt), a_socketArray + curr_srv,
             sizeof(struct sockaddr_in));

      hostNameFound = hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr);
      if (hostNameFound == NULL) {
         warn("Can't map Internet address %lu to a string name",
              curr_conn->skt.sin_addr.s_addr);
         curr_conn->hostName[0] = '\0';
      }
      else {
         strcpy(curr_conn->hostName, hostNameFound);
      }

      /*
       * Make an Rx connection to the current server.
       */

      curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,  /*Server addr */
                                           curr_conn->skt.sin_port, /*Server port */
                                           1,   /*AFS service # */
                                           secobj,  /*Security obj */
                                           0);  /*# of above */
      if (curr_conn->rxconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "Can't create Rx connection to server '%s' (%lu)",
                 curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         my_xstat_fs_Cleanup(1, xstat_fs_numServers, xstat_fs_ConnInfo,
                             buff2);
         return (-2);
      }
      /*
       * Bump the current xstat_fs connection to set up.
       */
      curr_conn++;

   }    /*for curr_srv */


   va_start(argp, buffer);
   code =
      my_xstat_fs_LWP(ProbeHandler, xstat_fs_ConnInfo, xstat_fs_numServers,
                      xstat_fs_collIDP, xstat_fs_numCollections, buffer,
                      argp);
   va_end(argp);

   if (code) {
      return (code);
   }
   my_xstat_fs_Cleanup(1, xstat_fs_numServers, xstat_fs_ConnInfo, buff2);
   return (0);
}   /* my_xstat_fs_Init() */


/*
 * from src/xstat/xstat_fs.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_xstat_fs_Cleanup(a_releaseMem, xstat_fs_numServers, xstat_fs_ConnInfo,
                    buffer)
   int a_releaseMem;
   int xstat_fs_numServers;
   struct xstat_fs_ConnectionInfo *xstat_fs_ConnInfo;
   char *buffer;
{
   int code = 0;                /*Return code */
   int conn_idx = 0;            /*Current connection index */
   struct xstat_fs_ConnectionInfo *curr_conn = 0;   /*Ptr to xstat_fs connection */

   /*
    * Take care of all Rx connections first.  Check to see that the
    * server count is a legal value.
    */
   if (xstat_fs_numServers <= 0) {
      sprintf(buffer,
              "Illegal number of servers (xstat_fs_numServers = %d)",
              xstat_fs_numServers);
      code = -1;
   }
   else {

src/Monitor.xs  view on Meta::CPAN

   fprintf(cm_outFD, "\t\t%10d numDowntimeIncidents\n",
           a_upDownP->numDowntimeIncidents);
   fprintf(cm_outFD, "\t\t%10d numRecordsNeverDown\n",
           a_upDownP->numRecordsNeverDown);
   fprintf(cm_outFD, "\t\t%10d maxDowntimesInARecord\n",
           a_upDownP->maxDowntimesInARecord);
   fprintf(cm_outFD, "\t\t%10d sumOfDowntimes\n", a_upDownP->sumOfDowntimes);
   fprintf(cm_outFD, "\t\t%10d shortestDowntime\n",
           a_upDownP->shortestDowntime);
   fprintf(cm_outFD, "\t\t%10d longestDowntime\n",
           a_upDownP->longestDowntime);

   /*
    * Now, print the array values.
    */
   fprintf(cm_outFD, "\t\tDowntime duration distribution:\n");
   fprintf(cm_outFD, "\t\t\t%8d: 0 min .. 10 min\n",
           a_upDownP->downDurations[0]);
   fprintf(cm_outFD, "\t\t\t%8d: 10 min .. 30 min\n",
           a_upDownP->downDurations[1]);
   fprintf(cm_outFD, "\t\t\t%8d: 30 min .. 1 hr\n",
           a_upDownP->downDurations[2]);
   fprintf(cm_outFD, "\t\t\t%8d: 1 hr .. 2 hr\n",
           a_upDownP->downDurations[3]);
   fprintf(cm_outFD, "\t\t\t%8d: 2 hr .. 4 hr\n",
           a_upDownP->downDurations[4]);
   fprintf(cm_outFD, "\t\t\t%8d: 4 hr .. 8 hr\n",
           a_upDownP->downDurations[5]);
   fprintf(cm_outFD, "\t\t\t%8d: > 8 hr\n", a_upDownP->downDurations[6]);

   fprintf(cm_outFD, "\t\tDowntime incident distribution:\n");
   fprintf(cm_outFD, "\t\t\t%8d: 0 times\n", a_upDownP->downIncidents[0]);
   fprintf(cm_outFD, "\t\t\t%8d: 1 time\n", a_upDownP->downIncidents[1]);
   fprintf(cm_outFD, "\t\t\t%8d: 2 .. 5 times\n",
           a_upDownP->downIncidents[2]);
   fprintf(cm_outFD, "\t\t\t%8d: 6 .. 10 times\n",
           a_upDownP->downIncidents[3]);
   fprintf(cm_outFD, "\t\t\t%8d: 10 .. 50 times\n",
           a_upDownP->downIncidents[4]);
   fprintf(cm_outFD, "\t\t\t%8d: > 50 times\n", a_upDownP->downIncidents[5]);

}   /* my_Print_cm_UpDownStats() */


/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_cm_XferTiming(a_opIdx, a_opNames, a_xferP, cm_outFD)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_xferData *a_xferP;
   FILE *cm_outFD;
{   /*Print_cm_XferTiming */

   fprintf(cm_outFD,
           "%s: %d xfers (%d OK), time sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           a_opNames[a_opIdx], a_xferP->numXfers, a_xferP->numSuccesses,
           a_xferP->sumTime.tv_sec, a_xferP->sumTime.tv_usec,
           a_xferP->minTime.tv_sec, a_xferP->minTime.tv_usec,
           a_xferP->maxTime.tv_sec, a_xferP->maxTime.tv_usec);
   fprintf(cm_outFD, "\t[bytes: sum=%d, min=%d, max=%d]\n", a_xferP->sumBytes,
           a_xferP->minBytes, a_xferP->maxBytes);
   fprintf(cm_outFD,
           "\t[buckets: 0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d 6: %d, 7: %d, 8: %d]\n",
           a_xferP->count[0], a_xferP->count[1], a_xferP->count[2],
           a_xferP->count[3], a_xferP->count[4], a_xferP->count[5],
           a_xferP->count[6], a_xferP->count[7], a_xferP->count[8]);

}   /* my_Print_cm_XferTiming() */


/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_cm_ErrInfo(a_opIdx, a_opNames, a_opErrP, cm_outFD)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_RPCErrors *a_opErrP;
   FILE *cm_outFD;
{   /*Print_cm_ErrInfo */

   fprintf(cm_outFD,
           "%15s: %d server, %d network, %d prot, %d vol, %d busies, %d other\n",
           a_opNames[a_opIdx], a_opErrP->err_Server, a_opErrP->err_Network,
           a_opErrP->err_Protection, a_opErrP->err_Volume,
           a_opErrP->err_VolumeBusies, a_opErrP->err_Other);

}   /* my_Print_cm_ErrInfo() */



/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_cm_OpTiming(a_opIdx, a_opNames, a_opTimeP, cm_outFD)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_opTimingData *a_opTimeP;
   FILE *cm_outFD;
{   /*Print_cm_OpTiming */

   fprintf(cm_outFD,
           "%15s: %d ops (%d OK); sum=%d.%06d, min=%d.%06d, max=%d.%06d\n",
           a_opNames[a_opIdx], a_opTimeP->numOps, a_opTimeP->numSuccesses,
           a_opTimeP->sumTime.tv_sec, a_opTimeP->sumTime.tv_usec,
           a_opTimeP->minTime.tv_sec, a_opTimeP->minTime.tv_usec,
           a_opTimeP->maxTime.tv_sec, a_opTimeP->maxTime.tv_usec);

}   /* my_Print_cm_OpTiming() */



/*
 * from src/afsmonitor/afsmon-output.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_Print_cm_OverallPerfInfo(a_ovP, cm_outFD)
   struct afs_stats_CMPerf *a_ovP;
   FILE *cm_outFD;
{

   fprintf(cm_outFD, "\t%10d numPerfCalls\n", a_ovP->numPerfCalls);

   fprintf(cm_outFD, "\t%10d epoch\n", a_ovP->epoch);
   fprintf(cm_outFD, "\t%10d numCellsVisible\n", a_ovP->numCellsVisible);
   fprintf(cm_outFD, "\t%10d numCellsContacted\n", a_ovP->numCellsContacted);
   fprintf(cm_outFD, "\t%10d dlocalAccesses\n", a_ovP->dlocalAccesses);
   fprintf(cm_outFD, "\t%10d vlocalAccesses\n", a_ovP->vlocalAccesses);
   fprintf(cm_outFD, "\t%10d dremoteAccesses\n", a_ovP->dremoteAccesses);
   fprintf(cm_outFD, "\t%10d vremoteAccesses\n", a_ovP->vremoteAccesses);
   fprintf(cm_outFD, "\t%10d cacheNumEntries\n", a_ovP->cacheNumEntries);
   fprintf(cm_outFD, "\t%10d cacheBlocksTotal\n", a_ovP->cacheBlocksTotal);
   fprintf(cm_outFD, "\t%10d cacheBlocksInUse\n", a_ovP->cacheBlocksInUse);
   fprintf(cm_outFD, "\t%10d cacheBlocksOrig\n", a_ovP->cacheBlocksOrig);
   fprintf(cm_outFD, "\t%10d cacheMaxDirtyChunks\n",
           a_ovP->cacheMaxDirtyChunks);
   fprintf(cm_outFD, "\t%10d cacheCurrDirtyChunks\n",
           a_ovP->cacheCurrDirtyChunks);
   fprintf(cm_outFD, "\t%10d dcacheHits\n", a_ovP->dcacheHits);
   fprintf(cm_outFD, "\t%10d vcacheHits\n", a_ovP->vcacheHits);
   fprintf(cm_outFD, "\t%10d dcacheMisses\n", a_ovP->dcacheMisses);
   fprintf(cm_outFD, "\t%10d vcacheMisses\n", a_ovP->vcacheMisses);
   fprintf(cm_outFD, "\t%10d cacheFilesReused\n", a_ovP->cacheFilesReused);
   fprintf(cm_outFD, "\t%10d vcacheXAllocs\n", a_ovP->vcacheXAllocs);

   fprintf(cm_outFD, "\t%10d bufAlloced\n", a_ovP->bufAlloced);
   fprintf(cm_outFD, "\t%10d bufHits\n", a_ovP->bufHits);
   fprintf(cm_outFD, "\t%10d bufMisses\n", a_ovP->bufMisses);
   fprintf(cm_outFD, "\t%10d bufFlushDirty\n", a_ovP->bufFlushDirty);

   fprintf(cm_outFD, "\t%10d LargeBlocksActive\n", a_ovP->LargeBlocksActive);
   fprintf(cm_outFD, "\t%10d LargeBlocksAlloced\n",
           a_ovP->LargeBlocksAlloced);
   fprintf(cm_outFD, "\t%10d SmallBlocksActive\n", a_ovP->SmallBlocksActive);
   fprintf(cm_outFD, "\t%10d SmallBlocksAlloced\n",
           a_ovP->SmallBlocksAlloced);
   fprintf(cm_outFD, "\t%10d OutStandingMemUsage\n",
           a_ovP->OutStandingMemUsage);
   fprintf(cm_outFD, "\t%10d OutStandingAllocs\n", a_ovP->OutStandingAllocs);
   fprintf(cm_outFD, "\t%10d CallBackAlloced\n", a_ovP->CallBackAlloced);
   fprintf(cm_outFD, "\t%10d CallBackFlushes\n", a_ovP->CallBackFlushes);

   fprintf(cm_outFD, "\t%10d srvRecords\n", a_ovP->srvRecords);
   fprintf(cm_outFD, "\t%10d srvNumBuckets\n", a_ovP->srvNumBuckets);
   fprintf(cm_outFD, "\t%10d srvMaxChainLength\n", a_ovP->srvMaxChainLength);

src/Monitor.xs  view on Meta::CPAN

      srcbuf++;
      sprintf(a_cmData->data[idx], "%d", *srcbuf);  /* numSuccesses */
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* sum time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* sqr time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* min time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
      tmpbuf = srcbuf++;    /* max time */
      sprintf(a_cmData->data[idx], "%d.%06d", *tmpbuf, *srcbuf);
      idx++;
      srcbuf++;
   }

   /*printf("Ending index value = %d\n",idx-1); */

   /* copy authentication info */

   srcbuf = (afs_int32 *) & (fullP->authent);
   numLongs = sizeof(struct afs_stats_AuthentInfo) / sizeof(afs_int32);
   for (i = 0; i < numLongs; i++) {
      sprintf(a_cmData->data[idx], "%d", *srcbuf);
      idx++;
      srcbuf++;
   }

   /*printf("Ending index value = %d\n",idx-1); */

   /* copy CM [un]replicated access info */

   srcbuf = (afs_int32 *) & (fullP->accessinf);
   numLongs = sizeof(struct afs_stats_AccessInfo) / sizeof(afs_int32);
   for (i = 0; i < numLongs; i++) {
      sprintf(a_cmData->data[idx], "%d", *srcbuf);
      idx++;
      srcbuf++;
   }

   /*printf("Ending index value = %d\n",idx-1); */
   return (0);

}   /* my_cm_Results_ltoa() */




/* cm_Results_to_Hash() */

void
cm_Results_to_Hash(struct cm_Display_Data *cmData, HV *HOSTINFO,
                   short *showFlags, int showDefault)
{
   int secidx;
   int grpidx;
   int numgrp;
   int fromidx;
   int toidx;
   char section[CFG_STR_LEN] = "";
   char group[CFG_STR_LEN] = "";
   HV *ENTRY;
   HV *GROUP;
   HV *SECTION;
   int i;

   secidx = 0;
   grpidx = secidx + 1;

   while (secidx < CM_NUM_DATA_CATEGORIES) {

      sscanf(cm_categories[secidx], "%s %d", section, &numgrp);
      SECTION = newHV();

      while (grpidx <= secidx + numgrp) {
         GROUP = newHV();
         sscanf(cm_categories[grpidx], "%s %d %d", group, &fromidx, &toidx);
         for (i = fromidx; i <= toidx; i++) {
            if (showFlags[i] || showDefault) {
               ENTRY = newHV();
               hv_store(ENTRY, "value", 5, newSVnv(atof(cmData->data[i])), 0);
               hv_store(GROUP, cm_varNames[i], strlen(cm_varNames[i]),
                        newRV_inc((SV *) ENTRY), 0);
            }
         }
         if (HvKEYS(GROUP))
            hv_store(SECTION, group, strlen(group), newRV_inc((SV *) GROUP),
                     0);
         grpidx++;
      }
      if (HvKEYS(SECTION))
         hv_store(HOSTINFO, section, strlen(section),
                  newRV_inc((SV *) SECTION), 0);
      secidx += numgrp + 1;
      grpidx = secidx + 1;
   }
}   /* cm_Results_to_Hash() */



/*
 * from src/afsmonitor/afsmonitor.c:
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_save_CM_data_forDisplay(a_cmResults, HOSTINFO, numCM, CMnameList,
                           cm_showFlags, cm_showDefault, buffer)
   struct xstat_cm_ProbeResults *a_cmResults;
   HV *HOSTINFO;
   int numCM;
   struct afsmon_hostEntry *CMnameList;
   short *cm_showFlags;
   int cm_showDefault;
   char *buffer;
{
   struct cm_Display_Data *curr_cmDataP;
   struct afsmon_hostEntry *curr_host = 0;
   int i = 0;
   int code = 0;
   int done = 0;
   char buff2[256] = "";

   curr_cmDataP =
      (struct cm_Display_Data *)malloc(sizeof(struct cm_Display_Data));
   if (curr_cmDataP == (struct cm_Display_Data *) NULL) {
      sprintf(buffer, "Memory allocation failure");
      return (-10);
   }
   memset(curr_cmDataP, 0, sizeof(struct cm_Display_Data));

   hv_store(HOSTINFO, "hostName", 8, newSVpv(a_cmResults->connP->hostName, 0),
            0);

   /*  Check the status of the probe. If it succeeded, we store its
    * results in the display data structure. If it failed we only mark
    * the failed status in the display data structure. */

   if (a_cmResults->probeOK) {  /* 1 => notOK the xstat results */
      hv_store(HOSTINFO, "probeOK", 7, newSViv(0), 0);
   }
   else {   /* probe succeeded, update display data structures */
      hv_store(HOSTINFO, "probeOK", 7, newSViv(1), 0);

      my_cm_Results_ltoa(curr_cmDataP, a_cmResults);

      cm_Results_to_Hash(curr_cmDataP, HOSTINFO, cm_showFlags,
                         cm_showDefault);

      done = 0;
      curr_host = CMnameList;
      for (i = 0; i < numCM; i++) {
         if (strcasecmp(curr_host->hostName, a_cmResults->connP->hostName)
             == 0) {
            done = 1;
            break;
         }
         curr_host = curr_host->next;;
      }
      if (!done) {
         sprintf(buffer, "Error storing results for CM host %s (100)",
                 a_cmResults->connP->hostName);
         return (100);
      }

      code = my_check_thresholds(curr_host, HOSTINFO, CM, buff2);
      if (code) {
         sprintf(buffer, "Error in checking thresholds (105) %s", buff2);
         return (105);
      }

   }

   return (0);
}   /* my_save_CM_data_forDisplay() */



/*
 * from src/afsmonitor/afsmonitor.c:
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_afsmon_CM_Handler(xstat_cm_Results, numCM, conn_idx, buffer, argp)
   struct xstat_cm_ProbeResults xstat_cm_Results;
   int numCM;
   int conn_idx;
   char *buffer;
   va_list argp;
{
   int code = 0;

   char *outputfile = va_arg(argp, char *);
   int detailed = va_arg(argp, int);
   AV *CACHEMAN = va_arg(argp, AV *);
   struct afsmon_hostEntry *CMnameList =
      va_arg(argp, struct afsmon_hostEntry *);
   short *cm_showFlags = va_arg(argp, short *);
   int cm_showDefault = va_arg(argp, int);

   HV *HOSTINFO = newHV();

   if (outputfile) {
      my_afsmon_cmOutput(outputfile, detailed, xstat_cm_Results);
   }

   /* add everything to data structure */
   code =
      my_save_CM_data_forDisplay(&xstat_cm_Results, HOSTINFO, numCM,
                                 CMnameList, cm_showFlags, cm_showDefault,
                                 buffer);
   if (code) {

src/Monitor.xs  view on Meta::CPAN

         currCollIDP = xstat_cm_collIDP;
         for (numColls = 0;
              numColls < xstat_cm_numCollections; numColls++, currCollIDP++) {
            /*
             * Initialize the per-probe values.
             */
            xstat_cm_Results.collectionNumber = *currCollIDP;
            xstat_cm_Results.data.AFSCB_CollData_len = AFSCB_MAX_XSTAT_LONGS;
            memset(xstat_cm_Results.data.AFSCB_CollData_val, 0,
                   AFSCB_MAX_XSTAT_LONGS * 4);

            xstat_cm_Results.connP = curr_conn;

            xstat_cm_Results.probeOK =
               RXAFSCB_GetXStats(curr_conn->rxconn,
                                 clientVersionNumber, *currCollIDP,
                                 &srvVersionNumber,
                                 &(xstat_cm_Results.probeTime),
                                 &(xstat_cm_Results.data));

            code =
               ProbeHandler(xstat_cm_Results, xstat_cm_numServers, index,
                            buff2, argp);
            index++;

            if (code) {
               sprintf(buffer, "Handler routine got error code %d. %s",
                       code, buff2);
               return (code);
            }

         }  /* For each collection */
      } /*Valid Rx connection */

      /*
       * Advance the xstat_fs connection pointer.
       */
      curr_conn++;

   }    /* For each xstat_cm connection */
   return (0);
}   /* my_xstat_cm_LWP() */



/*
 * from src/xstat/xstat_cm.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_xstat_cm_Init(int (*ProbeHandler) (), int xstat_cm_numServers,
                 struct sockaddr_in *a_socketArray,
                 int xstat_cm_numCollections, afs_int32 * xstat_cm_collIDP,
                 char *buffer, ...)
{
   int curr_srv = 0;
   int conn_err = 0;
   char *hostNameFound = "";
   struct xstat_cm_ConnectionInfo *curr_conn = 0, *xstat_cm_ConnInfo = 0;
   struct rx_securityClass *secobj = 0; /*Client security object */
   char buff2[256] = "";
   int code = 0;
   va_list argp;

   xstat_cm_ConnInfo = (struct xstat_cm_ConnectionInfo *)
      malloc(xstat_cm_numServers * sizeof(struct xstat_cm_ConnectionInfo));
   if (xstat_cm_ConnInfo == (struct xstat_cm_ConnectionInfo *) NULL) {
      sprintf(buffer,
              "Can't allocate %d connection info structs (%d bytes)",
              xstat_cm_numServers,
              (xstat_cm_numServers * sizeof(struct xstat_cm_ConnectionInfo)));
      return (-1);  /*No cleanup needs to be done yet */
   }

   code = rx_Init(htons(0));
   if (code) {
      sprintf(buffer, "Fatal error in rx_Init(), error=%d", code);
      return (-1);
   }

    /*
     * Create a null Rx client security object, to be used by the
     * probe LWP.
     */
   secobj = rxnull_NewClientSecurityObject();
   if (secobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_xstat_cm_Cleanup(1, xstat_cm_numServers, xstat_cm_ConnInfo, buff2);
      sprintf(buffer, "Can't create probe LWP client security object. %s",
              buff2);
      return (-1);
   }

   curr_conn = xstat_cm_ConnInfo;
   conn_err = 0;
   for (curr_srv = 0; curr_srv < xstat_cm_numServers; curr_srv++) {
      /*
       * Copy in the socket info for the current server, resolve its
       * printable name if possible.
       */

      memcpy(&(curr_conn->skt), a_socketArray + curr_srv,
             sizeof(struct sockaddr_in));

      hostNameFound = hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr);
      if (hostNameFound == NULL) {
         warn("Can't map Internet address %lu to a string name",
              curr_conn->skt.sin_addr.s_addr);
         curr_conn->hostName[0] = '\0';
      }
      else {
         strcpy(curr_conn->hostName, hostNameFound);
      }

      /*
       * Make an Rx connection to the current server.
       */

      curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,  /*Server addr */
                                           curr_conn->skt.sin_port, /*Server port */
                                           1,   /*AFS service # */
                                           secobj,  /*Security obj */
                                           0);  /*# of above */
      if (curr_conn->rxconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "Can't create Rx connection to server '%s' (%lu)",
                 curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         my_xstat_cm_Cleanup(1, xstat_cm_numServers, xstat_cm_ConnInfo,
                             buff2);
         return (-2);
      }
      /*
       * Bump the current xstat_fs connection to set up.
       */
      curr_conn++;

   }    /*for curr_srv */


   va_start(argp, buffer);
   code =
      my_xstat_cm_LWP(ProbeHandler, xstat_cm_ConnInfo, xstat_cm_numServers,
                      xstat_cm_collIDP, xstat_cm_numCollections, buffer,
                      argp);
   va_end(argp);

   if (code) {
      return (code);
   }
   my_xstat_cm_Cleanup(1, xstat_cm_numServers, xstat_cm_ConnInfo, buff2);
   return (0);


}   /* my_xstat_cm_Init() */


/*
 * from src/xstat/xstat_cm.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_xstat_cm_Cleanup(int a_releaseMem, int xstat_cm_numServers,
                    struct xstat_cm_ConnectionInfo *xstat_cm_ConnInfo,
                    char *buffer)
{
   int code = 0;                /*Return code */
   int conn_idx = 0;            /*Current connection index */
   struct xstat_cm_ConnectionInfo *curr_conn = 0;   /*Ptr to xstat_fs connection */

   /*
    * Take care of all Rx connections first.  Check to see that the
    * server count is a legal value.
    */
   if (xstat_cm_numServers <= 0) {
      sprintf(buffer,
              "Illegal number of servers (xstat_cm_numServers = %d)",
              xstat_cm_numServers);
      code = -1;
   }
   else {
      if (xstat_cm_ConnInfo != (struct xstat_cm_ConnectionInfo *) NULL) {

src/Monitor.xs  view on Meta::CPAN

          * and close up any Rx connections it holds.
          */
         curr_conn = fsprobe_ConnInfo;
         for (conn_idx = 0; conn_idx < fsprobe_numServers; conn_idx++) {
            if (curr_conn->rxconn != (struct rx_connection *) NULL) {
               rx_DestroyConnection(curr_conn->rxconn);
               curr_conn->rxconn = (struct rx_connection *) NULL;
            }
            if (curr_conn->rxVolconn != (struct rx_connection *) NULL) {
               rx_DestroyConnection(curr_conn->rxVolconn);
               curr_conn->rxVolconn = (struct rx_connection *) NULL;
            }
            curr_conn++;
         }  /*for each fsprobe connection */
      } /*fsprobe connection structure exists */
   }    /*Legal number of servers */

   /*
    * Now, release all the space we've allocated
    */
   if (fsprobe_ConnInfo != (struct fsprobe_ConnectionInfo *) NULL)
      free(fsprobe_ConnInfo);
   if (fsprobe_Results->stats != (struct ProbeViceStatistics *) NULL)
      free(fsprobe_Results->stats);
   if (fsprobe_Results->probeOK != (int *) NULL)
      free(fsprobe_Results->probeOK);

   /*
    * Return the news, whatever it is.
    */
   return (code);


}


/*
 * from src/fsprobe/fsprobe.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_fsprobe_Init(fsprobe_Results, fsprobe_ConnInfo, a_numServers,
                a_socketArray, RETVAL, scout_debugfd, buffer)
   struct fsprobe_ProbeResults *fsprobe_Results;    /*Latest probe results */
   struct fsprobe_ConnectionInfo **fsprobe_ConnInfo;    /*Ptr to connection array */
   int a_numServers;
   struct sockaddr_in *a_socketArray;
   AV *RETVAL;
   FILE *scout_debugfd;
   char *buffer;
{
   static char rn[] = "my_fsprobe_Init";
   struct fsprobe_ConnectionInfo *curr_conn;    /*Current connection */
   int fsprobe_statsBytes;      /*Num bytes in stats block */
   int fsprobe_probeOKBytes;    /*Num bytes in probeOK block */
   int conn_err = 0, code = 0;
   int curr_srv;
   char *hostNameFound;
   int PortToUse;
   struct rx_securityClass *secobj;
   struct rx_securityClass *CBsecobj;
   struct rx_service *rxsrv_afsserver;
   char buff2[256] = "";

   struct rx_call *rxcall;      /*Bogus param */
   AFSCBFids *Fids_Array;       /*Bogus param */
   AFSCBs *CallBack_Array;      /*Bogus param */
   struct interfaceAddr *interfaceAddr; /*Bogus param */


   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fflush(scout_debugfd);
   }
   if (a_numServers <= 0) {
      sprintf(buffer, "[%s] Illegal number of servers: %d", rn, a_numServers);
      return (-1);
   }
   if (a_socketArray == (struct sockaddr_in *) NULL) {
      sprintf(buffer, "[%s] Null server socket array argument", rn);
      return (-1);
   }

   memset(fsprobe_Results, 0, sizeof(struct fsprobe_ProbeResults));


   rxcall = (struct rx_call *) NULL;
   Fids_Array = (AFSCBFids *) NULL;
   CallBack_Array = (AFSCBs *) NULL;
   interfaceAddr = (struct interfaceAddr *) NULL;

   SRXAFSCB_CallBack(rxcall, Fids_Array, CallBack_Array);
   SRXAFSCB_InitCallBackState2(rxcall, interfaceAddr);
   SRXAFSCB_Probe(rxcall);



   *fsprobe_ConnInfo = (struct fsprobe_ConnectionInfo *)
      malloc(a_numServers * sizeof(struct fsprobe_ConnectionInfo));
   if (*fsprobe_ConnInfo == (struct fsprobe_ConnectionInfo *) NULL) {
      sprintf(buffer,
              "[%s] Can't allocate %d connection info structs (%d bytes)\n",
              rn, a_numServers,
              (a_numServers * sizeof(struct fsprobe_ConnectionInfo)));
      return (-1);  /*No cleanup needs to be done yet */
   }
   else if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] *fsprobe_ConnInfo allocated (%d bytes)\n",
              rn, a_numServers * sizeof(struct fsprobe_ConnectionInfo));
      fflush(scout_debugfd);
   }

   fsprobe_statsBytes = a_numServers * sizeof(struct ProbeViceStatistics);
   fsprobe_Results->stats = (struct ProbeViceStatistics *)
      malloc(fsprobe_statsBytes);
   if (fsprobe_Results->stats == (struct ProbeViceStatistics *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't allocate %d statistics structs (%d bytes). %s", rn,

src/Monitor.xs  view on Meta::CPAN

   else if (scout_debugfd) {
      fprintf(scout_debugfd,
              "[%s] fsprobe_Results->stats allocated (%d bytes)\n", rn,
              fsprobe_statsBytes);
      fflush(scout_debugfd);
   }

   fsprobe_probeOKBytes = a_numServers * sizeof(int);
   fsprobe_Results->probeOK = (int *)malloc(fsprobe_probeOKBytes);
   if (fsprobe_Results->probeOK == (int *) NULL) {
      /* Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't allocate %d probeOK array entries (%d bytes). %s",
              rn, a_numServers, fsprobe_probeOKBytes, buff2);
      return (-1);
   }
   else if (scout_debugfd) {
      fprintf(scout_debugfd,
              "[%s] fsprobe_Results->probeOK allocated (%d bytes)\n",
              rn, fsprobe_probeOKBytes);
      fflush(scout_debugfd);
   }
   fsprobe_Results->probeNum = 0;
   fsprobe_Results->probeTime = 0;
   memset(fsprobe_Results->stats, 0,
          (a_numServers * sizeof(struct ProbeViceStatistics)));

   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Initializing Rx\n", rn);
      fflush(scout_debugfd);
   }
   PortToUse = FSPROBE_CBPORT;
   do {
      code = rx_Init(htons(PortToUse));
      if (code) {
         if (code == RX_ADDRINUSE) {
            if (scout_debugfd) {
               fprintf(scout_debugfd,
                       "[%s] Callback port %d in use, advancing\n", rn,
                       PortToUse);
               fflush(scout_debugfd);
            }
            PortToUse++;
         }
         else {
            sprintf(buffer, "[%s] Fatal error in rx_Init()\n", rn);
            return (-1);
         }
      }
   } while (code);
   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Rx initialized on port %d\n", rn,
              PortToUse);
      fflush(scout_debugfd);
   }


   /*
    * Create a null Rx server security object, to be used by the
    * Callback listener.
    */
   CBsecobj = (struct rx_securityClass *)rxnull_NewServerSecurityObject();
   if (CBsecobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't create null security object for the callback listener. %s",
              rn, buff2);
      return (-1);
   }
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Callback server security object created\n",
              rn);


   /*
    * Create a null Rx client security object, to be used by the
    * probe LWP.
    */
   secobj = (struct rx_securityClass *)rxnull_NewClientSecurityObject();
   if (secobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't create client security object for probe LWP. %s",
              rn, buff2);
      return (-1);
   }
   if (scout_debugfd) {
      fprintf(scout_debugfd,
              "[%s] Probe LWP client security object created\n", rn);
      fflush(scout_debugfd);
   }


   curr_conn = *fsprobe_ConnInfo;
   conn_err = 0;
   for (curr_srv = 0; curr_srv < a_numServers; curr_srv++) {
      /*
       * Copy in the socket info for the current server, resolve its
       * printable name if possible.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd,
                 "[%s] Copying in the following socket info:\n", rn);
         fprintf(scout_debugfd, "[%s] IP addr 0x%lx, port %d\n", rn,
                 (a_socketArray + curr_srv)->sin_addr.s_addr,
                 (a_socketArray + curr_srv)->sin_port);
         fflush(scout_debugfd);
      }
      memcpy(&(curr_conn->skt), a_socketArray + curr_srv,
             sizeof(struct sockaddr_in));

      hostNameFound = hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr);
      if (hostNameFound == (char *) NULL) {
         warn("Can't map Internet address %lu to a string name\n",
              curr_conn->skt.sin_addr.s_addr);
         curr_conn->hostName[0] = '\0';
      }
      else {
         strcpy(curr_conn->hostName, hostNameFound);
         if (scout_debugfd) {
            fprintf(scout_debugfd,
                    "[%s] Host name for server index %d is %s\n", rn,
                    curr_srv, curr_conn->hostName);
            fflush(scout_debugfd);
         }
      }

      /*
       * Make an Rx connection to the current server.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd,
                 "[%s] Connecting to srv idx %d, IP addr 0x%lx, port %d, service 1\n",
                 rn, curr_srv, curr_conn->skt.sin_addr.s_addr,
                 curr_conn->skt.sin_port);
         fflush(scout_debugfd);
      }

      curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,  /*Server addr */
                                           curr_conn->skt.sin_port, /*Server port */
                                           1,   /*AFS service num */
                                           secobj,  /*Security object */
                                           0);  /*Number of above */
      if (curr_conn->rxconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "[%s] Can't create Rx connection to server %s (%lu)",
                 rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         conn_err = 1;
      }
      if (scout_debugfd) {
         fprintf(scout_debugfd, "[%s] New connection at 0x%lx\n",
                 rn, curr_conn->rxconn);
         fflush(scout_debugfd);
      }

      /*
       * Make an Rx connection to the current volume server.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd,
                 "[%s] Connecting to srv idx %d, IP addr 0x%lx, port %d, service 1\n",
                 rn, curr_srv, curr_conn->skt.sin_addr.s_addr, htons(7005));
         fflush(scout_debugfd);
      }
      curr_conn->rxVolconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,   /*Server addr */
                                              htons(AFSCONF_VOLUMEPORT),    /*Volume Server port */
                                              VOLSERVICE_ID,    /*AFS service num */
                                              secobj,   /*Security object */
                                              0);   /*Number of above */
      if (curr_conn->rxVolconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "[%s] Can't create Rx connection to volume server %s (%lu)\n",
                 rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         conn_err = 1;
      }
      else {
         int i, cnt;

         memset(&curr_conn->partList, 0, sizeof(struct partList));
         curr_conn->partCnt = 0;
         i = my_XListPartitions(curr_conn->rxVolconn, &curr_conn->partList,
                                &cnt, scout_debugfd);
         if (!i) {
            curr_conn->partCnt = cnt;
         }
      }
      if (scout_debugfd) {
         fprintf(scout_debugfd, "[%s] New connection at 0x%lx\n",
                 rn, curr_conn->rxVolconn);
         fflush(scout_debugfd);
      }


      /*
       * Bump the current fsprobe connection to set up.
       */
      curr_conn++;
   }    /*for curr_srv */

   /*
    * Create the AFS callback service (listener).
    */
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Creating AFS callback listener\n", rn);
   rxsrv_afsserver = rx_NewService(0,   /*Use default port */
                                   1,   /*Service ID */
                                   "afs",   /*Service name */
                                   &CBsecobj,   /*Ptr to security object(s) */
                                   1,   /*Number of security objects */
                                   RXAFSCB_ExecuteRequest); /*Dispatcher */
   if (rxsrv_afsserver == (struct rx_service *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer, "[%s] Can't create callback Rx service/listener. %s",
              rn, buff2);
      return (-1);
   }
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Callback listener created\n", rn);

   /*
    * Start up the AFS callback service.
    */
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Starting up callback listener.\n", rn);
   rx_StartServer(0 /*Don't donate yourself to LWP pool */ );

   /* start probe */
   code = my_fsprobe_LWP(a_numServers, *fsprobe_ConnInfo, fsprobe_Results,
                         fsprobe_statsBytes, fsprobe_probeOKBytes,
                         scout_debugfd, RETVAL, buffer);
   if (code)
      return (code);

   if (conn_err)
      return (-2);
   else
      return (0);

}   /* my_fsprobe_Init() */


/*
 * from src/scout/scout.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_FS_Handler(fsprobe_Results, numServers, fsprobe_ConnInfo, scout_debugfd,
              RETVAL, buffer)
   struct fsprobe_ProbeResults fsprobe_Results;
   int numServers;
   struct fsprobe_ConnectionInfo *fsprobe_ConnInfo;
   FILE *scout_debugfd;
   AV *RETVAL;
   char *buffer;
{
   static char rn[] = "my_FS_Handler";  /*Routine name */
   int code;                    /*Return code */
   struct ProbeViceStatistics *curr_stats;  /*Ptr to current stats */
   struct fsprobe_ConnectionInfo *curr_conn;
   ViceDisk *curr_diskstat;
   int curr_disk;
   int *curr_probeOK;           /*Ptr to current probeOK field */
   int i = 0, j = 0;
   HV *RESULTS;
   HV *STATS;
   AV *DISKS;

src/Monitor.xs  view on Meta::CPAN

                  newSViv(curr_stats->Spare5), 0);
         hv_store(STATS, "Spare6", strlen("Spare6"),
                  newSViv(curr_stats->Spare6), 0);
         hv_store(STATS, "Spare7", strlen("Spare7"),
                  newSViv(curr_stats->Spare7), 0);
         hv_store(STATS, "Spare8", strlen("Spare8"),
                  newSViv(curr_stats->Spare8), 0);

         DISKS = newAV();

         curr_diskstat = (ViceDisk *) curr_stats->Disk;
         j = 0;
         for (curr_disk = 0; curr_disk < VOLMAXPARTS; curr_disk++) {
            if (strncmp("/vice", curr_diskstat->Name, 5) == 0) {
               DISK = newHV();
               hv_store(DISK, "Name", 4, newSVpv(&curr_diskstat->Name[6], 0),
                        0);
               hv_store(DISK, "TotalBlocks", 10,
                        newSViv(curr_diskstat->TotalBlocks), 0);
               hv_store(DISK, "BlocksAvailable", 15,
                        newSViv(curr_diskstat->BlocksAvailable), 0);
               av_store(DISKS, j, newRV_inc((SV *) DISK));
               curr_diskstat++;
               j++;
            }
         }

         hv_store(STATS, "Disk", 4, newRV_inc((SV *) DISKS), 0);
         hv_store(RESULTS, "stats", 5, newRV_inc((SV *) STATS), 0);
      }
      av_store(RETVAL, i, newRV_inc((SV *) RESULTS));
      curr_stats++;
      curr_probeOK++;
      curr_conn++;
   }

   code =
      my_fsprobe_Cleanup(&fsprobe_Results, fsprobe_ConnInfo, numServers,
                         scout_debugfd, buffer);

   return code;
}

/* end of scout helper functions */



/* xstat_fs_test helper functions */

/*
 * from src/xstat/xstat_fs_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_PrintOpTiming(int a_opIdx, struct fs_stats_opTimingData *a_opTimeP, HV *DATA)
{
   HV *OPTIMING = newHV();

   hv_store(OPTIMING, "sumTime", 7,
            newSVnv(a_opTimeP->sumTime.tv_sec +
                    a_opTimeP->sumTime.tv_usec / 1000000.0), 0);
   hv_store(OPTIMING, "sqrTime", 7,
            newSVnv(a_opTimeP->sqrTime.tv_sec +
                    a_opTimeP->sqrTime.tv_usec / 1000000.0), 0);
   hv_store(OPTIMING, "minTime", 7,
            newSVnv(a_opTimeP->minTime.tv_sec +
                    a_opTimeP->minTime.tv_usec / 1000000.0), 0);
   hv_store(OPTIMING, "maxTime", 7,
            newSVnv(a_opTimeP->maxTime.tv_sec +
                    a_opTimeP->maxTime.tv_usec / 1000000.0), 0);
   hv_store(OPTIMING, "numSuccesses", 12, newSViv(a_opTimeP->numSuccesses),
            0);
   hv_store(OPTIMING, "numOps", 6, newSViv(a_opTimeP->numOps), 0);

   hv_store(DATA, fsOpNames[a_opIdx], strlen(fsOpNames[a_opIdx]),
            newRV_inc((SV *) OPTIMING), 0);
}


/*
 * from src/xstat/xstat_fs_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_PrintXferTiming(int a_opIdx, struct fs_stats_xferData *a_xferP, HV *DATA)
{
   HV *XFERTIMING = newHV();
   AV *COUNT = newAV();
   int i;

   hv_store(XFERTIMING, "sumTime", 7,
            newSVnv(a_xferP->sumTime.tv_sec +
                    a_xferP->sumTime.tv_usec / 1000000.0), 0);
   hv_store(XFERTIMING, "sqrTime", 7,
            newSVnv(a_xferP->sqrTime.tv_sec +
                    a_xferP->sqrTime.tv_usec / 1000000.0), 0);
   hv_store(XFERTIMING, "minTime", 7,
            newSVnv(a_xferP->minTime.tv_sec +
                    a_xferP->minTime.tv_usec / 1000000.0), 0);
   hv_store(XFERTIMING, "maxTime", 7,
            newSVnv(a_xferP->maxTime.tv_sec +
                    a_xferP->maxTime.tv_usec / 1000000.0), 0);
   hv_store(XFERTIMING, "numSuccesses", 12, newSViv(a_xferP->numSuccesses),
            0);
   hv_store(XFERTIMING, "numXfers", 8, newSViv(a_xferP->numXfers), 0);

   hv_store(XFERTIMING, "sumBytes", 8, newSViv(a_xferP->sumBytes), 0);
   hv_store(XFERTIMING, "minBytes", 8, newSViv(a_xferP->minBytes), 0);
   hv_store(XFERTIMING, "maxBytes", 8, newSViv(a_xferP->maxBytes), 0);

   for (i = 0; i <= 8; i++)
      av_store(COUNT, i, newSViv(a_xferP->count[i]));

   hv_store(XFERTIMING, "count", 5, newRV_inc((SV *) COUNT), 0);

   hv_store(DATA, xferOpNames[a_opIdx], strlen(xferOpNames[a_opIdx]),
            newRV_inc((SV *) XFERTIMING), 0);
}


/*
 * from src/xstat/xstat_fs_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_PrintDetailedPerfInfo(struct fs_stats_DetailedStats *a_detP, HV *DATA)
{
   int currIdx;
   HV *OPTIMES = newHV();
   HV *XFERS = newHV();

   hv_store(DATA, "epoch", 5,
            newSVnv(a_detP->epoch.tv_sec + a_detP->epoch.tv_usec / 1000000.0),
            0);

   for (currIdx = 0; currIdx < FS_STATS_NUM_RPC_OPS; currIdx++)
      my_PrintOpTiming(currIdx, &(a_detP->rpcOpTimes[currIdx]), OPTIMES);

   hv_store(DATA, "rpcOpTimes", 10, newRV_inc((SV *) OPTIMES), 0);

   for (currIdx = 0; currIdx < FS_STATS_NUM_XFER_OPS; currIdx++)
      my_PrintXferTiming(currIdx, &(a_detP->xferOpTimes[currIdx]), XFERS);

   hv_store(DATA, "xferOpTimes", 11, newRV_inc((SV *) XFERS), 0);
}


/*
 * from src/xstat/xstat_fs_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_PrintOverallPerfInfo(struct afs_PerfStats *a_ovP, HV *DATA)
{
   hv_store(DATA, "numPerfCalls", strlen("numPerfCalls"),
            newSViv(a_ovP->numPerfCalls), 0);

   /*
    * Vnode cache section.
    */
   hv_store(DATA, "vcache_L_Entries", strlen("vcache_L_Entries"),
            newSViv(a_ovP->vcache_L_Entries), 0);
   hv_store(DATA, "vcache_L_Allocs", strlen("vcache_L_Allocs"),
            newSViv(a_ovP->vcache_L_Allocs), 0);
   hv_store(DATA, "vcache_L_Gets", strlen("vcache_L_Gets"),
            newSViv(a_ovP->vcache_L_Gets), 0);
   hv_store(DATA, "vcache_L_Reads", strlen("vcache_L_Reads"),
            newSViv(a_ovP->vcache_L_Reads), 0);
   hv_store(DATA, "vcache_L_Writes", strlen("vcache_L_Writes"),
            newSViv(a_ovP->vcache_L_Writes), 0);

   hv_store(DATA, "vcache_S_Entries", strlen("vcache_S_Entries"),
            newSViv(a_ovP->vcache_S_Entries), 0);
   hv_store(DATA, "vcache_S_Allocs", strlen("vcache_S_Allocs"),
            newSViv(a_ovP->vcache_S_Allocs), 0);
   hv_store(DATA, "vcache_S_Gets", strlen("vcache_S_Gets"),
            newSViv(a_ovP->vcache_S_Gets), 0);
   hv_store(DATA, "vcache_S_Reads", strlen("vcache_S_Reads"),
            newSViv(a_ovP->vcache_S_Reads), 0);
   hv_store(DATA, "vcache_S_Writes", strlen("vcache_S_Writes"),
            newSViv(a_ovP->vcache_S_Writes), 0);

   hv_store(DATA, "vcache_H_Entries", strlen("vcache_H_Entries"),
            newSViv(a_ovP->vcache_H_Entries), 0);
   hv_store(DATA, "vcache_H_Gets", strlen("vcache_H_Gets"),
            newSViv(a_ovP->vcache_H_Gets), 0);
   hv_store(DATA, "vcache_H_Replacements", strlen("vcache_H_Replacements"),
            newSViv(a_ovP->vcache_H_Replacements), 0);

   /*
    * Directory package section.
    */
   hv_store(DATA, "dir_Buffers", strlen("dir_Buffers"),
            newSViv(a_ovP->dir_Buffers), 0);
   hv_store(DATA, "dir_Calls", strlen("dir_Calls"),
            newSViv(a_ovP->dir_Calls), 0);
   hv_store(DATA, "dir_IOs", strlen("dir_IOs"), newSViv(a_ovP->dir_IOs), 0);

   /*
    * Rx section.
    */
   hv_store(DATA, "rx_packetRequests", strlen("rx_packetRequests"),
            newSViv(a_ovP->rx_packetRequests), 0);
   hv_store(DATA, "rx_noPackets_RcvClass", strlen("rx_noPackets_RcvClass"),
            newSViv(a_ovP->rx_noPackets_RcvClass), 0);
   hv_store(DATA, "rx_noPackets_SendClass", strlen("rx_noPackets_SendClass"),
            newSViv(a_ovP->rx_noPackets_SendClass), 0);
   hv_store(DATA, "rx_noPackets_SpecialClass",
            strlen("rx_noPackets_SpecialClass"),
            newSViv(a_ovP->rx_noPackets_SpecialClass), 0);
   hv_store(DATA, "rx_socketGreedy", strlen("rx_socketGreedy"),
            newSViv(a_ovP->rx_socketGreedy), 0);
   hv_store(DATA, "rx_bogusPacketOnRead", strlen("rx_bogusPacketOnRead"),
            newSViv(a_ovP->rx_bogusPacketOnRead), 0);
   hv_store(DATA, "rx_bogusHost", strlen("rx_bogusHost"),
            newSViv(a_ovP->rx_bogusHost), 0);
   hv_store(DATA, "rx_noPacketOnRead", strlen("rx_noPacketOnRead"),
            newSViv(a_ovP->rx_noPacketOnRead), 0);
   hv_store(DATA, "rx_noPacketBuffersOnRead",
            strlen("rx_noPacketBuffersOnRead"),
            newSViv(a_ovP->rx_noPacketBuffersOnRead), 0);
   hv_store(DATA, "rx_selects", strlen("rx_selects"),
            newSViv(a_ovP->rx_selects), 0);
   hv_store(DATA, "rx_sendSelects", strlen("rx_sendSelects"),
            newSViv(a_ovP->rx_sendSelects), 0);
   hv_store(DATA, "rx_packetsRead_RcvClass",
            strlen("rx_packetsRead_RcvClass"),
            newSViv(a_ovP->rx_packetsRead_RcvClass), 0);
   hv_store(DATA, "rx_packetsRead_SendClass",
            strlen("rx_packetsRead_SendClass"),
            newSViv(a_ovP->rx_packetsRead_SendClass), 0);
   hv_store(DATA, "rx_packetsRead_SpecialClass",
            strlen("rx_packetsRead_SpecialClass"),
            newSViv(a_ovP->rx_packetsRead_SpecialClass), 0);
   hv_store(DATA, "rx_dataPacketsRead", strlen("rx_dataPacketsRead"),
            newSViv(a_ovP->rx_dataPacketsRead), 0);
   hv_store(DATA, "rx_ackPacketsRead", strlen("rx_ackPacketsRead"),
            newSViv(a_ovP->rx_ackPacketsRead), 0);
   hv_store(DATA, "rx_dupPacketsRead", strlen("rx_dupPacketsRead"),
            newSViv(a_ovP->rx_dupPacketsRead), 0);
   hv_store(DATA, "rx_spuriousPacketsRead", strlen("rx_spuriousPacketsRead"),
            newSViv(a_ovP->rx_spuriousPacketsRead), 0);
   hv_store(DATA, "rx_packetsSent_RcvClass",
            strlen("rx_packetsSent_RcvClass"),
            newSViv(a_ovP->rx_packetsSent_RcvClass), 0);
   hv_store(DATA, "rx_packetsSent_SendClass",
            strlen("rx_packetsSent_SendClass"),
            newSViv(a_ovP->rx_packetsSent_SendClass), 0);
   hv_store(DATA, "rx_packetsSent_SpecialClass",
            strlen("rx_packetsSent_SpecialClass"),
            newSViv(a_ovP->rx_packetsSent_SpecialClass), 0);
   hv_store(DATA, "rx_ackPacketsSent", strlen("rx_ackPacketsSent"),
            newSViv(a_ovP->rx_ackPacketsSent), 0);
   hv_store(DATA, "rx_pingPacketsSent", strlen("rx_pingPacketsSent"),
            newSViv(a_ovP->rx_pingPacketsSent), 0);
   hv_store(DATA, "rx_abortPacketsSent", strlen("rx_abortPacketsSent"),
            newSViv(a_ovP->rx_abortPacketsSent), 0);
   hv_store(DATA, "rx_busyPacketsSent", strlen("rx_busyPacketsSent"),
            newSViv(a_ovP->rx_busyPacketsSent), 0);
   hv_store(DATA, "rx_dataPacketsSent", strlen("rx_dataPacketsSent"),
            newSViv(a_ovP->rx_dataPacketsSent), 0);
   hv_store(DATA, "rx_dataPacketsReSent", strlen("rx_dataPacketsReSent"),
            newSViv(a_ovP->rx_dataPacketsReSent), 0);
   hv_store(DATA, "rx_dataPacketsPushed", strlen("rx_dataPacketsPushed"),
            newSViv(a_ovP->rx_dataPacketsPushed), 0);
   hv_store(DATA, "rx_ignoreAckedPacket", strlen("rx_ignoreAckedPacket"),
            newSViv(a_ovP->rx_ignoreAckedPacket), 0);
   hv_store(DATA, "rx_totalRtt_Sec", strlen("rx_totalRtt_Sec"),
            newSViv(a_ovP->rx_totalRtt_Sec), 0);
   hv_store(DATA, "rx_totalRtt_Usec", strlen("rx_totalRtt_Usec"),
            newSViv(a_ovP->rx_totalRtt_Usec), 0);
   hv_store(DATA, "rx_minRtt_Sec", strlen("rx_minRtt_Sec"),
            newSViv(a_ovP->rx_minRtt_Sec), 0);
   hv_store(DATA, "rx_minRtt_Usec", strlen("rx_minRtt_Usec"),
            newSViv(a_ovP->rx_minRtt_Usec), 0);
   hv_store(DATA, "rx_maxRtt_Sec", strlen("rx_maxRtt_Sec"),
            newSViv(a_ovP->rx_maxRtt_Sec), 0);
   hv_store(DATA, "rx_maxRtt_Usec", strlen("rx_maxRtt_Usec"),
            newSViv(a_ovP->rx_maxRtt_Usec), 0);
   hv_store(DATA, "rx_nRttSamples", strlen("rx_nRttSamples"),
            newSViv(a_ovP->rx_nRttSamples), 0);
   hv_store(DATA, "rx_nServerConns", strlen("rx_nServerConns"),
            newSViv(a_ovP->rx_nServerConns), 0);
   hv_store(DATA, "rx_nClientConns", strlen("rx_nClientConns"),
            newSViv(a_ovP->rx_nClientConns), 0);
   hv_store(DATA, "rx_nPeerStructs", strlen("rx_nPeerStructs"),
            newSViv(a_ovP->rx_nPeerStructs), 0);
   hv_store(DATA, "rx_nCallStructs", strlen("rx_nCallStructs"),
            newSViv(a_ovP->rx_nCallStructs), 0);
   hv_store(DATA, "rx_nFreeCallStructs", strlen("rx_nFreeCallStructs"),
            newSViv(a_ovP->rx_nFreeCallStructs), 0);
#ifndef NOAFS_XSTATSCOLL_CBSTATS
   hv_store(DATA, "rx_nBusies", strlen("rx_nBusies"),
            newSViv(a_ovP->rx_nBusies), 0);
   hv_store(DATA, "fs_nBusies", strlen("fs_nBusies"),
            newSViv(a_ovP->fs_nBusies), 0);
   hv_store(DATA, "fs_GetCapabilities", strlen("fs_GetCapabilities"),
            newSViv(a_ovP->fs_nGetCaps), 0);
#endif

   /*
    * Host module fields.
    */
   hv_store(DATA, "host_NumHostEntries", strlen("host_NumHostEntries"),
            newSViv(a_ovP->host_NumHostEntries), 0);
   hv_store(DATA, "host_HostBlocks", strlen("host_HostBlocks"),
            newSViv(a_ovP->host_HostBlocks), 0);
   hv_store(DATA, "host_NonDeletedHosts", strlen("host_NonDeletedHosts"),
            newSViv(a_ovP->host_NonDeletedHosts), 0);
   hv_store(DATA, "host_HostsInSameNetOrSubnet",
            strlen("host_HostsInSameNetOrSubnet"),
            newSViv(a_ovP->host_HostsInSameNetOrSubnet), 0);
   hv_store(DATA, "host_HostsInDiffSubnet", strlen("host_HostsInDiffSubnet"),
            newSViv(a_ovP->host_HostsInDiffSubnet), 0);
   hv_store(DATA, "host_HostsInDiffNetwork",
            strlen("host_HostsInDiffNetwork"),
            newSViv(a_ovP->host_HostsInDiffNetwork), 0);
   hv_store(DATA, "host_NumClients", strlen("host_NumClients"),
            newSViv(a_ovP->host_NumClients), 0);
   hv_store(DATA, "host_ClientBlocks", strlen("host_ClientBlocks"),
            newSViv(a_ovP->host_ClientBlocks), 0);

   hv_store(DATA, "sysname_ID", strlen("sysname_ID"),
            newSViv(a_ovP->sysname_ID), 0);
}



/*
 * from src/xstat/xstat_fs_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_PrintCallInfo(struct xstat_fs_ProbeResults *xstat_fs_Results, HV *HOSTINFO)
{
   int numInt32s;
   afs_int32 *currInt32;
   register int i;

src/Monitor.xs  view on Meta::CPAN

   data_name = "OutStandingAllocs";
   hv_store(PERF, data_name, strlen(data_name),
            newSViv(a_ovP->OutStandingAllocs), 0);
   data_name = "CallBackAlloced";
   hv_store(PERF, data_name, strlen(data_name),
            newSViv(a_ovP->CallBackAlloced), 0);
   data_name = "CallBackFlushes";
   hv_store(PERF, data_name, strlen(data_name),
            newSViv(a_ovP->CallBackFlushes), 0);
   data_name = "CallBackLoops";
   hv_store(PERF, "cbloops", strlen("cbloops"), newSViv(a_ovP->cbloops), 0);
   data_name = "srvRecords";
   hv_store(PERF, data_name, strlen(data_name), newSViv(a_ovP->srvRecords),
            0);
   data_name = "srvNumBuckets";
   hv_store(PERF, data_name, strlen(data_name), newSViv(a_ovP->srvNumBuckets),
            0);
   data_name = "srvMaxChainLength";
   hv_store(PERF, data_name, strlen(data_name),
            newSViv(a_ovP->srvMaxChainLength), 0);
   data_name = "srvMaxChainLengthHWM";
   hv_store(PERF, data_name, strlen(data_name),
            newSViv(a_ovP->srvMaxChainLengthHWM), 0);
   data_name = "srvRecordsHWM";
   hv_store(PERF, data_name, strlen(data_name), newSViv(a_ovP->srvRecordsHWM),
            0);
   data_name = "sysName_ID";
   hv_store(PERF, data_name, strlen(data_name), newSViv(a_ovP->sysName_ID),
            0);

   my_cm_PrintUpDownStats(&(a_ovP->fs_UpDown[0]), FS_UPDOWN, 0);

   my_cm_PrintUpDownStats(&(a_ovP->fs_UpDown[1]), FS_UPDOWN, 1);

   my_cm_PrintUpDownStats(&(a_ovP->vl_UpDown[0]), VL_UPDOWN, 0);

   my_cm_PrintUpDownStats(&(a_ovP->vl_UpDown[1]), VL_UPDOWN, 1);

   hv_store(PERF, "fs_UpDown", 9, newRV_inc((SV *) FS_UPDOWN), 0);
   hv_store(PERF, "vl_UpDown", 9, newRV_inc((SV *) VL_UPDOWN), 0);

}


/*
 * from src/xstat/xstat_cm_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_cm_PrintOpTiming(a_opIdx, a_opNames, a_opTimeP, RPCTIMES)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_opTimingData *a_opTimeP;
   HV *RPCTIMES;
{
   HV *TIMES = newHV();
   hv_store(TIMES, "numOps", 6, newSViv(a_opTimeP->numOps), 0);
   hv_store(TIMES, "numSuccesses", 12, newSViv(a_opTimeP->numSuccesses), 0);

   hv_store(TIMES, "sumTime", 7, newSVnv(a_opTimeP->sumTime.tv_sec
                                         +
                                         (a_opTimeP->sumTime.tv_usec /
                                          1000000.0)), 0);
   hv_store(TIMES, "sqrTime", 7,
            newSVnv(a_opTimeP->sqrTime.tv_sec +
                    (a_opTimeP->sqrTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "minTime", 7,
            newSVnv(a_opTimeP->minTime.tv_sec +
                    (a_opTimeP->minTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "maxTime", 7,
            newSVnv(a_opTimeP->maxTime.tv_sec +
                    (a_opTimeP->maxTime.tv_usec / 1000000.0)), 0);

   hv_store(RPCTIMES, a_opNames[a_opIdx], strlen(a_opNames[a_opIdx]),
            newRV_inc((SV *) TIMES), 0);
}


/*
 * from src/xstat/xstat_cm_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_cm_PrintErrInfo(a_opIdx, a_opNames, a_opErrP, RPCERRORS)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_RPCErrors *a_opErrP;
   HV *RPCERRORS;
{
   HV *ERRORS = newHV();

   hv_store(ERRORS, "err_Server",       10, newSViv(a_opErrP->err_Server), 0);
   hv_store(ERRORS, "err_Network",      11, newSViv(a_opErrP->err_Network), 0);
   hv_store(ERRORS, "err_Protection",   14, newSViv(a_opErrP->err_Protection), 0);
   hv_store(ERRORS, "err_Volume",       10, newSViv(a_opErrP->err_Volume), 0);
   hv_store(ERRORS, "err_VolumeBusies", 16, newSViv(a_opErrP->err_VolumeBusies), 0);
   hv_store(ERRORS, "err_Other",         9, newSViv(a_opErrP->err_Other), 0);

   hv_store(RPCERRORS, a_opNames[a_opIdx], strlen(a_opNames[a_opIdx]),
            newRV_inc((SV *) ERRORS), 0);
}


/*
 * from src/xstat/xstat_cm_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_cm_PrintXferTiming(a_opIdx, a_opNames, a_xferP, XFERTIMES)
   int a_opIdx;
   char *a_opNames[];
   struct afs_stats_xferData *a_xferP;
   HV *XFERTIMES;
{
   HV *TIMES = newHV();
   AV *COUNT = newAV();
   int i;

   hv_store(TIMES, "numXfers", 8, newSViv(a_xferP->numXfers), 0);
   hv_store(TIMES, "numSuccesses", 12, newSViv(a_xferP->numSuccesses), 0);
   hv_store(TIMES, "sumTime", 7, newSVnv(a_xferP->sumTime.tv_sec
                                         +
                                         (a_xferP->sumTime.tv_usec /
                                          1000000.0)), 0);
   hv_store(TIMES, "sqrTime", 7, newSVnv(a_xferP->sqrTime.tv_sec +
                                 (a_xferP->sqrTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "minTime", 7, newSVnv(a_xferP->minTime.tv_sec +
                                 (a_xferP->minTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "maxTime", 7, newSVnv(a_xferP->maxTime.tv_sec +
                                 (a_xferP->maxTime.tv_usec / 1000000.0)), 0);
   hv_store(TIMES, "sumBytes", 8, newSViv(a_xferP->sumBytes), 0);
   hv_store(TIMES, "minBytes", 8, newSViv(a_xferP->minBytes), 0);
   hv_store(TIMES, "maxBytes", 8, newSViv(a_xferP->maxBytes), 0);


   for (i = 0; i <= 8; i++)
      av_store(COUNT, i, newSViv(a_xferP->count[i]));

   hv_store(TIMES, "count", 5, newRV_inc((SV *) COUNT), 0);

   hv_store(XFERTIMES, a_opNames[a_opIdx], strlen(a_opNames[a_opIdx]),
            newRV_inc((SV *) TIMES), 0);
}


/*
 * from src/xstat/xstat_cm_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_PrintRPCPerfInfo(struct afs_stats_RPCOpInfo *a_rpcP, HV *RPC)
{
   int currIdx;
   HV *FSRPCTIMES  = newHV();
   HV *FSRPCERRORS = newHV();
   HV *FSXFERTIMES = newHV();
   HV *CMRPCTIMES  = newHV();

   for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; currIdx++)
      my_cm_PrintOpTiming(currIdx, fsOpNames, &(a_rpcP->fsRPCTimes[currIdx]),
                          FSRPCTIMES);

   hv_store(RPC, "fsRPCTimes", 10, newRV_inc((SV *) FSRPCTIMES), 0);

   for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_RPC_OPS; currIdx++)
      my_cm_PrintErrInfo(currIdx, fsOpNames, &(a_rpcP->fsRPCErrors[currIdx]),
                         FSRPCERRORS);

   hv_store(RPC, "fsRPCErrors", 11, newRV_inc((SV *) FSRPCERRORS), 0);

   for (currIdx = 0; currIdx < AFS_STATS_NUM_FS_XFER_OPS; currIdx++)
      my_cm_PrintXferTiming(currIdx, xferOpNames,
                            &(a_rpcP->fsXferTimes[currIdx]), FSXFERTIMES);

   hv_store(RPC, "fsXferTimes", 11, newRV_inc((SV *) FSXFERTIMES), 0);

   for (currIdx = 0; currIdx < AFS_STATS_NUM_CM_RPC_OPS; currIdx++)
      my_cm_PrintOpTiming(currIdx, cmOpNames, &(a_rpcP->cmRPCTimes[currIdx]),
                          CMRPCTIMES);

   hv_store(RPC, "cmRPCTimes", 10, newRV_inc((SV *) CMRPCTIMES), 0);

}


/*
 * from src/xstat/xstat_cm_test.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

src/Monitor.xs  view on Meta::CPAN

       curr_skt->sin_port   = htons(7000);       /* FileServer port */
       curr_skt++;
    }
    code = my_fsprobe_Init(&fsprobe_Results, &fsprobe_ConnInfo, numservers,
                           FSSktArray, RETVAL, scout_debugfd, buffer);
    if(code) {
      if(buffer == "") {
        sprintf(buffer, "Error returned by fsprobe_Init: %d", code);
      }
      BSETCODE(code, buffer);
      if (scout_debugfd != (FILE *) NULL) {
        fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
        fclose(scout_debugfd);
      }
      XSRETURN_UNDEF;
    }
    code = my_FS_Handler(fsprobe_Results, numservers, fsprobe_ConnInfo,
                         scout_debugfd, RETVAL, buff2);
    if (code) {
      sprintf(buffer, "[%s] Handler routine returned error code %d. %s", rn, code, buff2);
      BSETCODE(code, buffer);
      if (scout_debugfd != (FILE *) NULL) {
        fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
        fclose(scout_debugfd);
      }
      XSRETURN_UNDEF;
    }

    if (scout_debugfd != (FILE *) NULL) {
       fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
       fclose(scout_debugfd);
    }

    ST(0) = sv_2mortal(newRV_inc((SV*)RETVAL));
    SETCODE(0);
    XSRETURN(1);
  }

void
afs_do_udebug(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {

    SV *value;
    I32 keylen = 0;
    char *key;
    int num_args = 0;
    char buffer[256] = "";

    char *hostName = (char *) NULL;
    char *portName = (char *) NULL;
    afs_int32 hostAddr;
    struct in_addr inhostAddr;
    register afs_int32 i, j, code;
    short port;
    int int32p = 0;
    struct hostent *th;
    struct rx_connection *tconn;
    struct rx_securityClass *sc;
    struct ubik_debug udebug;
    struct ubik_sdebug usdebug;
    int oldServer = 0;   /* are we talking to a pre 3.5 server? */
    afs_int32 isClone = 0;

    HV *RETVAL = newHV();
    AV *ADDRESSES;
    HV *LOCALVERSION;
    HV *SYNCVERSION;
    HV *SYNCTID;
    AV *SERVERS;
    HV *USDEBUG;
    AV *ALTADDR;
    HV *REMOTEVERSION;

    /* parse arguments */
    num_args = hv_iterinit(args);
    while (num_args--) {

      value = hv_iternextsv(args, &key, &keylen);

      switch (*key) {

        case 'l':
          if(strncmp(key, "long", keylen) == 0 && keylen <= 4) {
            int32p = (int) SvIV(value);
          } else goto unrecognized;
        break;

        case 'p':
          if(strncmp(key, "port", keylen) == 0 && keylen <= 4) {
            portName = (char *) SvPV(value, PL_na);
          } else goto unrecognized;
        break;

        case 's':
          if(strncmp(key, "server", keylen) == 0 && keylen <= 6) {
            hostName = (char *) SvPV(value, PL_na);
          } else goto unrecognized;
        break;

        default:
          unrecognized:
          sprintf(buffer, "Unrecognized flag: %s", key);
          BSETCODE(-1, buffer);
          XSRETURN_UNDEF;
        break;
      } /* end switch */
    } /* end while */
    /* done parsing arguments */


    /* lookup host */
    if (hostName) {
       th = hostutil_GetHostByName(hostName);
       if (!th) {
          sprintf(buffer, "udebug: host %s not found in host table", hostName);
          BSETCODE(1, buffer);
          XSRETURN_UNDEF;
       }

src/Monitor.xs  view on Meta::CPAN

          if (code < 0) {
             warn("error code %d from VOTE_SDebug\n", code);
             break;
          }

          /* otherwise print the structure */
          USDEBUG = newHV();
          inhostAddr.s_addr = htonl(usdebug.addr);

          hv_store(USDEBUG, "addr", 4, newSVpv(afs_inet_ntoa(htonl(usdebug.addr)), 0), 0);

          ALTADDR = newAV();
          for ( j=0;((usdebug.altAddr[j]) && (j<UBIK_MAX_INTERFACE_ADDR-1)); j++) {
             av_store(ALTADDR, j, newSVpv(afs_inet_ntoa(htonl(usdebug.altAddr[j])), 0));
          }
          if (j) hv_store(USDEBUG, "altAddr", 7, newRV_inc((SV*)ALTADDR), 0);

          REMOTEVERSION = newHV();
          hv_store(REMOTEVERSION, "epoch", 5, newSViv(usdebug.remoteVersion.epoch), 0);
          hv_store(REMOTEVERSION, "counter", 7, newSViv(usdebug.remoteVersion.counter), 0);
          hv_store(USDEBUG, "remoteVersion", 13, newRV_inc((SV*)REMOTEVERSION), 0);

          hv_store(USDEBUG, "isClone", 7, newSViv(isClone), 0);

          hv_store(USDEBUG, "lastVoteTime", 12, newSViv(usdebug.lastVoteTime), 0);

          hv_store(USDEBUG, "lastBeaconSent", 14, newSViv(usdebug.lastBeaconSent), 0);
          hv_store(USDEBUG, "lastVote", 8, newSViv(usdebug.lastVote), 0);

          hv_store(USDEBUG, "currentDB", 9, newSViv(usdebug.currentDB), 0);
          hv_store(USDEBUG, "up", 2, newSViv(usdebug.up), 0);
          hv_store(USDEBUG, "beaconSinceDown", 15, newSViv(usdebug.beaconSinceDown), 0);

          av_store(SERVERS, i, newRV_inc((SV*)USDEBUG));
       }
       hv_store(RETVAL, "servers", 7, newRV_inc((SV*)SERVERS), 0);
    }

    /* return RETVAL */
    ST(0) = sv_2mortal(newRV_inc((SV*)RETVAL));
    SETCODE(0);
    XSRETURN(1);

  }

void
afs_do_cmdebug(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {
    SV *value;
    I32 keylen = 0;
    char *key;
    int num_args = 0;
    int code = 0;
    int aint32 = 0;
    struct rx_connection *conn;
    register char *hostName = "";
    register struct hostent *thp;
    struct rx_securityClass *secobj;
    afs_int32 addr = 0;
    afs_int32 port = 7001;
    char buffer[256] = "";

    AV *LOCKS = newAV();           /* return */
    AV *CACHE_ENTRIES = newAV();   /* values */

    /* parse arguments */
    num_args = hv_iterinit(args);
    while (num_args--) {
      value = hv_iternextsv(args, &key, &keylen);

      switch (*key) {

        case 'l':
          if(strncmp(key, "long", keylen) == 0 && keylen <= 4) {
            aint32 = (int) SvIV(value);
          } else goto unrecognized;
        break;

        case 'p':
          if(strncmp(key, "port", keylen) == 0 && keylen <= 4) {
            port = (int) SvIV(value);
          } else goto unrecognized;
        break;

        case 's':
          if(strncmp(key, "servers", keylen) == 0 && keylen <= 7) {
            hostName = (char *) SvPV(value, PL_na);
          } else goto unrecognized;
        break;

        default:
          unrecognized:
          sprintf(buffer, "Unrecognized flag: %s", key);
          BSETCODE(-1, buffer);
          XSRETURN_UNDEF;
        break;
      } /* end switch */
    } /* end while */
    /* done parsing arguments */

    rx_Init(0);

    thp = hostutil_GetHostByName(hostName);
    if (!thp) {
        sprintf(buffer, "can't resolve address for host %s", hostName);
        BSETCODE(1, buffer);
        XSRETURN_UNDEF;
    }
    memcpy(&addr, thp->h_addr, sizeof(afs_int32));
    secobj = rxnull_NewServerSecurityObject();
    conn = rx_NewConnection(addr, htons(port), 1, secobj, 0);
    if (!conn) {
        sprintf(buffer, "failed to create connection for host %s", hostName);
        BSETCODE(1, buffer);
        XSRETURN_UNDEF;
    }
    code = my_PrintLocks(conn, aint32, LOCKS, buffer);
    if(code) {
       BSETCODE(code, buffer);
       XSRETURN_UNDEF;
    }
    code = my_PrintCacheEntries(conn, aint32, CACHE_ENTRIES, buffer);
    if(code) {
       BSETCODE(code, buffer);
       XSRETURN_UNDEF;
    }

    SETCODE(0);
    EXTEND(SP, 2);
    PUSHs(sv_2mortal(newRV_inc((SV*)LOCKS)));
    PUSHs(sv_2mortal(newRV_inc((SV*)CACHE_ENTRIES)));

  }

void
afs_do_afsmonitor(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {
    I32 keylen = 0;
    char* key = 0;
    SV* value = 0;
    char* host = 0;
    AV* host_array = 0;
    AV* show_array = 0;
    AV* fsthresh_array = 0;
    AV* cmthresh_array = 0;
    HV* thresh_entry = 0;
    int global_fsThreshCount = 0;
    int global_cmThreshCount = 0;
    int found = 0;
    int numBytes = 0;
    char* thresh_name = "";
    char* thresh_value = 0;
    char* thresh_host = "";
    char* thresh_handler = "";
    int num_args = 0;
    int detailed = 0;
    char* config_filename = 0;
    char* output_filename = 0;
    FILE *outputFD = 0;
    struct afsmon_hostEntry *temp_host = 0;
    int numFS = 0;
    int numCM = 0;
    struct afsmon_hostEntry *last_hostEntry = 0;
    int lastHostType = 0;
    short fs_showFlags[NUM_FS_STAT_ENTRIES];
    short cm_showFlags[NUM_CM_STAT_ENTRIES];
    int fs_showDefault = 1;
    int cm_showDefault = 1;

src/Monitor.xs  view on Meta::CPAN

          warn("WARNING: returned Rx statistics of unexpected size (got %d)\n", code);
          /* handle other versions?... */
        }

        RXSTATS = newHV();

        myPrintTheseStats(RXSTATS, &rxstats);

        hv_store(RETVAL, "rxstats", 7, newRV_inc((SV*)(RXSTATS)), 0);

      }
    }

    /* get connections unless -noconns flag was set */
    /* array of connections added at key 'connections' in RETVAL hash */
    if (!noConns) {
      if (allconns) {
        if (!withAllConn) {
          warn("WARNING: Server doesn't support retrieval of all connections,\n");
          warn("         getting only interesting instead.\n");
          }
      }

      CONNECTIONS = newAV();
      index = 0;
      for ( i = 0; ; i++) {
        code = rx_GetServerConnections(s, host, port, &nextconn, allconns,
                      supportedDebugValues, &tconn,
                      &supportedConnValues);
        if (code < 0) {
          warn("getconn call failed with code %d\n", code);
          break;
        }
        if (tconn.cid == 0xffffffff) {
          break;
        }

        /* see if we're in nodally mode and all calls are dallying */
        if (nodally) {
          flag = 0;
          for (j = 0; j < RX_MAXCALLS; j++) {
             if (tconn.callState[j] != RX_STATE_NOTINIT &&
                 tconn.callState[j] != RX_STATE_DALLY) {
               flag = 1;
               break;
             }
          }
          if (flag == 0) {
            /* this call looks too ordinary, bump skipped count and go
             * around again */
            dallyCounter++;
            continue;
          }
        }
        if ((onlyHost != -1) && (onlyHost != tconn.host)) continue;
        if ((onlyPort != -1) && (onlyPort != tconn.port)) continue;
        if (onlyServer && (tconn.type != RX_SERVER_CONNECTION)) continue;
        if (onlyClient && (tconn.type != RX_CLIENT_CONNECTION)) continue;
        if (onlyAuth != 999) {
          if (onlyAuth == -1) {
            if (tconn.securityIndex != 0) continue;
          }
          else {
            if (tconn.securityIndex != 2) continue;
            if (withSecStats && (tconn.secStats.type == 3) &&
             (tconn.secStats.level != onlyAuth)) continue;
          }
        }
        TCONN = newHV();
        hostAddr.s_addr = tconn.host;
        hv_store(TCONN, "host", 4, newSVpv(inet_ntoa(hostAddr), 0), 0);
        hv_store(TCONN, "port", 4, newSViv(ntohs(tconn.port)), 0);

        hv_store(TCONN, "cid", 3, newSViv(tconn.cid), 0);
        hv_store(TCONN, "epoch", 5, newSViv(tconn.epoch), 0);
        hv_store(TCONN, "error", 5, newSViv(tconn.error), 0);
        hv_store(TCONN, "serial", 6, newSViv(tconn.serial), 0);
        hv_store(TCONN, "natMTU", 6, newSViv(tconn.natMTU), 0);

        hv_store(TCONN, "flags", 5, newSViv(tconn.flags), 0);

        hv_store(TCONN, "securityIndex", 13, newSViv(tconn.securityIndex), 0);

        hv_store(TCONN, "type", 4, newSViv(tconn.type), 0);

        if (withSecStats) {
          HV* SECSTATS = newHV();
          hv_store(SECSTATS, "type", 4,
                   newSViv(tconn.secStats.type), 0);
          hv_store(SECSTATS, "level", 5,
                   newSViv(tconn.secStats.level), 0);
          hv_store(SECSTATS, "flags", 5,
                   newSViv(tconn.secStats.flags), 0);
          hv_store(SECSTATS, "expires", 7,
                   newSViv(tconn.secStats.expires), 0);
          hv_store(SECSTATS, "packetsReceived", 15,
                   newSViv(tconn.secStats.packetsReceived), 0);
          hv_store(SECSTATS, "packetsSent", 11,
                   newSViv(tconn.secStats.packetsSent), 0);
          hv_store(SECSTATS, "bytesReceived", 13,
                   newSViv(tconn.secStats.bytesReceived), 0);
          hv_store(SECSTATS, "bytesSent", 9,
                   newSViv(tconn.secStats.bytesSent), 0);
          hv_store(TCONN, "secStats", 8, newRV_inc((SV*)(SECSTATS)), 0);
        }

        CALLSTATE = newAV();
        av_fill(CALLSTATE, RX_MAXCALLS-1);
        CALLMODE = newAV();
        av_fill(CALLMODE, RX_MAXCALLS-1);
        CALLFLAGS = newAV();
        av_fill(CALLFLAGS, RX_MAXCALLS-1);
        CALLOTHER = newAV();
        av_fill(CALLOTHER, RX_MAXCALLS-1);
        CALLNUMBER = newAV();
        av_fill(CALLNUMBER, RX_MAXCALLS-1);

        for (j = 0; j < RX_MAXCALLS; j++) {
          av_store(CALLSTATE, j, newSViv(tconn.callState[j]));
          av_store(CALLMODE, j, newSViv(tconn.callMode[j]));
          av_store(CALLFLAGS, j, newSViv(tconn.callFlags[j]));
          av_store(CALLOTHER, j, newSViv(tconn.callOther[j]));
          av_store(CALLNUMBER, j, newSViv(tconn.callNumber[j]));
        }

        hv_store(TCONN, "callState", 9, newRV_inc((SV*)(CALLSTATE)), 0);
        hv_store(TCONN, "callMode", 8, newRV_inc((SV*)(CALLMODE)), 0);
        hv_store(TCONN, "callFlags", 9, newRV_inc((SV*)(CALLFLAGS)), 0);
        hv_store(TCONN, "callOther", 9, newRV_inc((SV*)(CALLOTHER)), 0);
        hv_store(TCONN, "callNumber", 10, newRV_inc((SV*)(CALLNUMBER)), 0);

        av_store(CONNECTIONS, index, newRV_inc((SV*)(TCONN)));
        index++;
      } /* end of for loop */
      if (nodally) hv_store(RETVAL, "dallyCounter", 12, newSViv(dallyCounter), 0);
      hv_store(RETVAL, "connections", 11, newRV_inc((SV*)(CONNECTIONS)), 0);
    } /* end of if (!noConns) */

    /* get peers if requested */
    /* array of peers added at key 'peers' in RETVAL hash */
    if (showPeers && withPeers) {
      PEERS = newAV();
      index = 0;
      for (i = 0; ; i++) {
        struct rx_debugPeer tpeer;
        code = rx_GetServerPeers(s, host, port, &nextpeer, allconns,
                                 &tpeer, &supportedPeerValues);
        if (code < 0) {
          warn("getpeer call failed with code %d\n", code);
          break;
        }
        if (tpeer.host == 0xffffffff) {
          break;
        }

        if ((onlyHost != -1) && (onlyHost != tpeer.host)) continue;
        if ((onlyPort != -1) && (onlyPort != tpeer.port)) continue;

        TPEER = newHV();

        hostAddr.s_addr = tpeer.host;
        hv_store(TPEER, "host", 4, newSVpv(inet_ntoa(hostAddr), 0), 0);
        hv_store(TPEER, "port", 4, newSViv(ntohs(tpeer.port)), 0);

        hv_store(TPEER, "ifMTU", 5, newSViv(tpeer.ifMTU), 0);
        hv_store(TPEER, "natMTU", 6, newSViv(tpeer.natMTU), 0);
        hv_store(TPEER, "maxMTU", 6, newSViv(tpeer.maxMTU), 0);
        hv_store(TPEER, "nSent", 5, newSViv(tpeer.nSent), 0);
        hv_store(TPEER, "reSends", 7, newSViv(tpeer.reSends), 0);

        BYTESSENT = newHV();
        hv_store(BYTESSENT, "high", 4, newSViv(tpeer.bytesSent.high), 0);
        hv_store(BYTESSENT, "low", 3, newSViv(tpeer.bytesSent.low), 0);
        hv_store(TPEER, "bytesSent", 9, newRV_inc((SV*)(BYTESSENT)), 0);

        BYTESRECEIVED = newHV();
        hv_store(BYTESRECEIVED, "high", 4, newSViv(tpeer.bytesReceived.high), 0);
        hv_store(BYTESRECEIVED, "low", 3, newSViv(tpeer.bytesReceived.low), 0);
        hv_store(TPEER, "bytesReceived", 13, newRV_inc((SV*)(BYTESRECEIVED)), 0);

        hv_store(TPEER, "rtt", 3, newSViv(tpeer.rtt), 0);
        hv_store(TPEER, "rtt_dev", 7, newSViv(tpeer.rtt_dev), 0);

        TIMEOUT = newHV();
        hv_store(TIMEOUT, "sec", 3, newSViv(tpeer.timeout.sec), 0);
        hv_store(TIMEOUT, "usec", 4, newSViv(tpeer.timeout.usec), 0);
        hv_store(TPEER, "timeout", 7, newRV_inc((SV*)(TIMEOUT)), 0);

        if (showLong) {
          hv_store(TPEER, "inPacketSkew", 12,
                   newSViv(tpeer.inPacketSkew), 0);
          hv_store(TPEER, "outPacketSkew", 13,
                   newSViv(tpeer.outPacketSkew), 0);
          hv_store(TPEER, "cwind", 5,
                   newSViv(tpeer.cwind), 0);
          hv_store(TPEER, "MTU", 3,
                   newSViv(tpeer.MTU), 0);
          hv_store(TPEER, "nDgramPackets", 13,
                   newSViv(tpeer.nDgramPackets), 0);
          hv_store(TPEER, "ifDgramPackets", 14,
                   newSViv(tpeer.ifDgramPackets), 0);
          hv_store(TPEER, "maxDgramPackets", 15,
                   newSViv(tpeer.maxDgramPackets), 0);
        }

        av_store(PEERS, index, newRV_inc((SV*)(TPEER)));
        index++;
      }

      hv_store(RETVAL, "peers", 5, newRV_inc((SV*)(PEERS)), 0);
    }

    done:
    /* return RETVAL */
    ST(0) = sv_2mortal(newRV_inc((SV*)RETVAL));
    SETCODE(0);
    XSRETURN(1);
}





void
afs_error_message(code)
        int32   code
    PPCODE:
    {
        ST(0) = sv_newmortal();
        sv_setpv(ST(0), (char *) error_message(code));
        XSRETURN(1);
    }



  /* this function is generated automatically by constant_gen */
  /* You didn't think I would type in this crap did you? */
  /* thats what perl is for :-) */

void
constant(name, arg=0)
	char *	name
        int     arg
   PPCODE:
   {
  ST(0) = sv_newmortal();



( run in 1.145 second using v1.01-cache-2.11-cpan-39bf76dae61 )