AFS-Monitor

 view release on metacpan or  search on metacpan

examples/configs/badconfig  view on Meta::CPAN

#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# $Revision: 1.2 $ $Date: 2004/08/05 20:52:03 $ $Author: alfw $
#

# global show statments
show cm PerfStats_section
#show cm Auth_Stats_group
show cm fs_sc_numTtlRecords
show fs VnodeCache_group

#global thresholds
thresh fs FetchData_sqr 2000
thresh fs vcache_L_Allocs 20 ThreshHandlerScript
thresh cm fs_sc_maxDowntimesInARecord 100

#individual connections

cm afs01

fs sysdev11
show fs FetchData_sqr

examples/configs/configfile  view on Meta::CPAN

#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# $Revision: 1.3 $ $Date: 2004/08/09 16:16:59 $ $Author: alfw $
#

# global show statments
show fs VnodeCache_group
show fs FetchData_sqr
show cm PerfStats_section
show cm fs_oc_downDst_more_50

#global thresholds
thresh fs vcache_S_Entries 30
thresh fs vcache_L_Allocs 20

#individual connections


fs andrew.e.kth.se
thresh fs vcache_L_Entries 198 scripts/HandlerScript panic die

cm virtue.openafs.org

pod/afsmonitor.pod  view on Meta::CPAN


cmd_to_execute I<host_name> fs|cm I<field_name threshold_val actual_val> [E<lt>arg1E<gt>] . . . [E<lt>argnE<gt>]

The parameters cmd_to_execute, fs, cm, field_name, threshold_val,
and arg1 through argn correspond to the values with the same name
on the thresh line. The host_name parameter identifies the file
server or client machine where the statistic has exceeded the
threshold, and the actual_val parameter is the actual value of
field_name that equals or exceeds the threshold value.

Use the thresh line to set either a global threshold, which applies
to all file server machines listed on fs lines or client machines
listed on cm lines in the configuration file, or a machine-specific
threshold, which applies to only one file server or client machine.
To set a global threshold, place the thresh line before any of the
fs or cm lines in the file. To set a machine-specific threshold,
place the thresh line below the corresponding fs or cm line, and
above any other fs or cm lines. A machine-specific threshold value
always overrides the corresponding global threshold, if set. Do not
place a thresh fs line directly after a cm line or a thresh cm line
directly after a fs line.

=item B<show fs | cm I<field/group/section>>

Specifies which individual statistic, group of statistics, or
section of statistics to include in the File Servers (fs) and/or
Cache Managers (cm) data structure. The L<afsmon_stats(1)> documentation
specifies the group and section to which each statistic belongs.
Include as many show lines as necessary to customize the results

src/Monitor.xs  view on Meta::CPAN



/*
 * 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 */

src/Monitor.xs  view on Meta::CPAN

      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");

src/Monitor.xs  view on Meta::CPAN

}   /* 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;

src/Monitor.xs  view on Meta::CPAN

         }
      }
      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);

src/Monitor.xs  view on Meta::CPAN

            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++) {

src/Monitor.xs  view on Meta::CPAN

         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);

src/Monitor.xs  view on Meta::CPAN

   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);
   }

src/Monitor.xs  view on Meta::CPAN

      /* 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"); */

src/Monitor.xs  view on Meta::CPAN

      }
   }
   /* 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);

src/Monitor.xs  view on Meta::CPAN

               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",

src/Monitor.xs  view on Meta::CPAN

  {
    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;

src/Monitor.xs  view on Meta::CPAN

            thresh_handler = (char *) SvPV(value, PL_na);
          }
          else {
            thresh_name = key;
            thresh_value = (char *) SvPV(value, PL_na);
          }
        }
        sprintf(buffer, "thresh fs %s %s %s",
                thresh_name, thresh_value, thresh_handler);
        if(!thresh_host) {
          code = my_parse_threshEntry(buffer, &global_fsThreshCount,
                      &global_cmThreshCount, (struct afsmon_hostEntry *) NULL, 0, buff2);
          if (code) {
            sprintf(buffer, "Couldn't parse fsthresh entry. %s", buff2);
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
          }
        }
        else {
          temp_host = FSnameList;
          found = 0;
          for (j = 0; j < numFS; j++) {
            if(strcmp(thresh_host, temp_host->hostName) == 0) {
              found = 1;
              break;
            }
            temp_host = temp_host->next;
          }
          if(found) {
            code = my_parse_threshEntry(buffer, &global_fsThreshCount,
                                        &global_cmThreshCount, temp_host,
                                        1, buff2);
            if(code) {
              sprintf(buffer, "Couldn't parse fsthresh entry. %s", buff2);
              BSETCODE(code, buffer);
              XSRETURN_UNDEF;
            }
          }
          else {
            sprintf(buffer,
                    "Couldn't parse fsthresh entry for host %s; host not found",
                    thresh_host);
            BSETCODE(-1, buffer);
            XSRETURN_UNDEF;
          }
        }
      }
      if (global_fsThreshCount) {
        temp_host = FSnameList;
        for (i = 0; i < numFS; i++) {
          temp_host->numThresh += global_fsThreshCount;
          temp_host = temp_host->next;
        }
      }
      temp_host = FSnameList;
      for (i = 0; i < numFS; i++) {
        if (temp_host->numThresh) {
          numBytes = temp_host->numThresh * sizeof(struct Threshold);
          temp_host->thresh = (struct Threshold *)malloc(numBytes);
          if (temp_host->thresh == (struct Threshold *) NULL) {
            sprintf(buffer, "Memory Allocation error 1.5");

src/Monitor.xs  view on Meta::CPAN

            thresh_host = he->h_name;
          }
          else if(strcmp(key, "handler")==0) {
            thresh_handler = (char *) SvPV(value, PL_na);
          }
          else {
            thresh_name = key;
            thresh_value = (char *) SvPV(value, PL_na);
          }
        }
        if(thresh_host) global_fsThreshCount = 0;
        else global_fsThreshCount = 1;
        code = my_store_threshold(1, thresh_name, thresh_value, thresh_handler,
                           &global_fsThreshCount, FSnameList, thresh_host,
                           numFS, buff2);
        if(code) {
          sprintf(buffer, "Unable to store threshold %s. %s", thresh_name, buff2);
          BSETCODE(code, buffer);
          XSRETURN_UNDEF;
        }
      }
    }

    if (cmthresh_array) {

src/Monitor.xs  view on Meta::CPAN

          else if(strcmp(key, "handler")==0) {
            thresh_handler = (char *) SvPV(value, PL_na);
          }
          else {
            thresh_name = key;
            thresh_value = (char *) SvPV(value, PL_na);
          }
        }
        sprintf(buffer, "thresh cm %s %s %s", thresh_name, thresh_value, thresh_handler);
        if(!thresh_host) {
          code = my_parse_threshEntry(buffer, &global_fsThreshCount,
                      &global_cmThreshCount, (struct afsmon_hostEntry *) NULL, 0, buff2);
          if (code) {
            sprintf(buffer, "Couldn't parse cmthresh entry. %s", buff2);
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
          }
        }
        else {
          temp_host = CMnameList;
          found = 0;
          for (j = 0; j < numCM; j++) {
            if(strcmp(thresh_host, temp_host->hostName) == 0) {
              found = 1;
              break;
            }
            temp_host = temp_host->next;
          }
          if(found) {
            code = my_parse_threshEntry(buffer, &global_fsThreshCount,
                                        &global_cmThreshCount, temp_host,
                                        2, buff2);
            if(code) {
              sprintf(buffer, "Couldn't parse cmthresh entry. %s", buff2);
              BSETCODE(code, buffer);
              XSRETURN_UNDEF;
            }
          }
          else {
            sprintf(buffer,
                    "Couldn't parse cmthresh entry for host %s; host not found",
                    thresh_host);
            BSETCODE(-1, buffer);
            XSRETURN_UNDEF;
          }
        }
      }
      if (global_cmThreshCount) {
        temp_host = CMnameList;
        for (i = 0; i < numCM; i++) {
          temp_host->numThresh += global_cmThreshCount;
          temp_host = temp_host->next;
        }
      }
      temp_host = CMnameList;
      for (i = 0; i < numCM; i++) {
        if (temp_host->numThresh) {
          numBytes = temp_host->numThresh * sizeof(struct Threshold);
          temp_host->thresh = (struct Threshold *)malloc(numBytes);
          if (temp_host->thresh == (struct Threshold *) NULL) {
            sprintf(buffer, "Memory Allocation error 2.5");

src/Monitor.xs  view on Meta::CPAN

            thresh_host = he->h_name;
          }
          else if(strcmp(key, "handler")==0) {
            thresh_handler = (char *) SvPV(value, PL_na);
          }
          else {
            thresh_name = key;
            thresh_value = (char *) SvPV(value, PL_na);
          }
        }
        if(thresh_host) global_cmThreshCount = 0;
        else global_cmThreshCount = 1;
        code = my_store_threshold(2, thresh_name, thresh_value, thresh_handler,
                           &global_cmThreshCount, CMnameList, thresh_host,
                           numCM, buff2);
        if(code) {
          sprintf(buffer, "Unable to store threshold %s. %s", thresh_name, buff2);
          BSETCODE(code, buffer);
          XSRETURN_UNDEF;
        }
      }
    }

    /* process configuration file */

src/ppport.h  view on Meta::CPAN

   with the Perl maintainers. */

/* If you needed to customize this file for your project, please mention
   your changes, and visible alter the version number. */


/*
   In order for a Perl extension module to be as portable as possible
   across differing versions of Perl itself, certain steps need to be taken.
   Including this header is the first major one, then using dTHR is all the
   appropriate places and using a PL_ prefix to refer to global Perl
   variables is the second.
*/


/* If you use one of a few functions that were not present in earlier
   versions of Perl, please add a define before the inclusion of ppport.h
   for a static include, or use the GLOBAL request in a single module to
   produce a global definition that can be referenced from the other
   modules.

   Function:            Static define:           Extern define:
   newCONSTSUB()        NEED_newCONSTSUB         NEED_newCONSTSUB_GLOBAL

*/


/* To verify whether ppport.h is needed for your module, and whether any
   special defines should be used, ppport.h can be run through Perl to check
   your source code. Simply say:

   	perl -x ppport.h *.c *.h *.xs foo/*.c [etc]

   The result will be a list of patches suggesting changes that should at
   least be acceptable, if not necessarily the most efficient solution, or a
   fix for all possible problems. It won't catch where dTHR is needed, and
   doesn't attempt to account for global macro or function definitions,
   nested includes, typemaps, etc.

   In order to test for the need of dTHR, please try your module under a
   recent version of Perl that has threading compiled-in.

*/


/*
#!/usr/bin/perl
@ARGV = ("*.xs") if !@ARGV;
%badmacros = %funcs = %macros = (); $replace = 0;
foreach (<DATA>) {
	$funcs{$1} = 1 if /Provide:\s+(\S+)/;
	$macros{$1} = 1 if /^#\s*define\s+([a-zA-Z0-9_]+)/;
	$replace = $1 if /Replace:\s+(\d+)/;
	$badmacros{$2}=$1 if $replace and /^#\s*define\s+([a-zA-Z0-9_]+).*?\s+([a-zA-Z0-9_]+)/;
	$badmacros{$1}=$2 if /Replace (\S+) with (\S+)/;
}
foreach $filename (map(glob($_),@ARGV)) {
	unless (open(IN, "<$filename")) {
		warn "Unable to read from $file: $!\n";
		next;
	}
	print "Scanning $filename...\n";
	$c = ""; while (<IN>) { $c .= $_; } close(IN);
	$need_include = 0; %add_func = (); $changes = 0;
	$has_include = ($c =~ /#.*include.*ppport/m);

	foreach $func (keys %funcs) {



( run in 0.607 second using v1.01-cache-2.11-cpan-49f99fa48dc )