Changeset 7b927621aa1d1fb7e9e915e74ab2a86ce90f73ac

Show
Ignore:
Timestamp:
02/19/08 23:18:15 (7 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1203463095 +0000
git-parent:

[ab565fae806825018d27c990172e58aa9e999c17]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1203463095 +0000
Message:

make the metrics stuff more flexible, setup check/status/metrics logging.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/Makefile.in

    ra7f575a r7b92762  
    2727OBJS=noitd.o noit_listener.o \ 
    2828        noit_console.o noit_console_state.o noit_console_telnet.o \ 
    29         noit_check.o
     29        noit_check.o noit_check_log.o
    3030        noit_module.o noit_conf.o noit_tokenizer.o 
    3131 
  • src/modules/http.c

    r646e6d2 r7b92762  
    5555typedef struct buf_t { 
    5656  char *b; 
    57   int l; 
     57  int32_t l; 
    5858} buf_t; 
    5959 
     
    177177  current.status = human_buffer; 
    178178  if(current.available == NP_AVAILABLE) { 
    179     noit_stats_set_metric_string(&current, "code", ci->status.code?code:NULL); 
    180     noit_stats_set_metric_int(&current, "bytes", &ci->body.l); 
     179    noit_stats_set_metric(&current, "code", 
     180                          METRIC_STRING, ci->status.code?code:NULL); 
     181    noit_stats_set_metric(&current, "bytes", 
     182                          METRIC_INT32, &ci->body.l); 
    181183  } 
    182184  else { 
    183     noit_stats_set_metric_int(&current, "code", NULL); 
    184     noit_stats_set_metric_int(&current, "bytes", NULL); 
     185    noit_stats_set_metric(&current, "code", METRIC_STRING, NULL); 
     186    noit_stats_set_metric(&current, "bytes", METRIC_INT32, NULL); 
    185187  } 
    186188  noit_check_set_stats(self, check, &current); 
     
    241243  struct timeval duration; 
    242244  stats_t current; 
    243   int services = 0; 
     245  int32_t services = 0; 
    244246  char human_buffer[256], rt[14]; 
    245247  xmlDocPtr resmon_results = NULL; 
     
    290292  current.status = human_buffer; 
    291293 
    292   noit_stats_set_metric_int(&current, "services", &services); 
     294  noit_stats_set_metric(&current, "services", METRIC_INT32, &services); 
    293295  if(services) { 
    294296    int i; 
     
    311313 
    312314        for(a=0; a<3; a++) { 
    313           int intval; 
     315          int32_t intval; 
    314316          sobj = xmlXPathEval((xmlChar *)attrs[a], xpath_ctxt); 
    315317          attrnode = xmlXPathNodeSetItem(sobj->nodesetval, 0); 
     
    321323              /* The first is integer */ 
    322324              intval = (int)(atof(value) * 1000.0); 
    323               noit_stats_set_metric_int(&current, attr, &intval); 
     325              noit_stats_set_metric(&current, attr, METRIC_INT32, &intval); 
    324326              break; 
    325327            case 1: 
     328              noit_stats_set_metric(&current, attr, METRIC_STRING, value); 
     329              break; 
    326330            case 2: 
    327               noit_stats_set_metric_string(&current, attr, (char *)value); 
     331              noit_stats_set_metric(&current, attr, METRIC_GUESS, value); 
    328332              break; 
    329333          } 
  • src/modules/ping_icmp.c

    r646e6d2 r7b92762  
    3131  int check_seq_no; 
    3232  int seq; 
    33   int expected_count; 
     33  int32_t expected_count; 
    3434  float *turnaround; 
    3535  eventer_t timeout_event; 
     
    7676static void ping_icmp_log_results(noit_module_t *self, noit_check_t *check) { 
    7777  struct check_info *data; 
    78   float avail, min = MAXFLOAT, max = 0.0, avg = 0.0, cnt; 
     78  double avail, min = MAXFLOAT, max = 0.0, avg = 0.0, cnt; 
    7979  int i, points = 0; 
    8080  char human_buffer[256]; 
     
    112112  current.state = (avail < 1.0) ? NP_BAD : NP_GOOD; 
    113113  current.status = human_buffer; 
    114   noit_stats_set_metric_int(&current, "count", &data->expected_count); 
     114  noit_stats_set_metric(&current, "count", 
     115                        METRIC_INT32, &data->expected_count); 
    115116  avail *= 100.0; 
    116   noit_stats_set_metric_float(&current, "available", &avail); 
    117   noit_stats_set_metric_float(&current, "minimum", avail > 0.0 ? &min : NULL); 
    118   noit_stats_set_metric_float(&current, "maximum", avail > 0.0 ? &max : NULL); 
    119   noit_stats_set_metric_float(&current, "average", avail > 0.0 ? &avg : NULL); 
     117  noit_stats_set_metric(&current, "available", METRIC_DOUBLE, &avail); 
     118  noit_stats_set_metric(&current, "minimum", 
     119                        METRIC_DOUBLE, avail > 0.0 ? &min : NULL); 
     120  noit_stats_set_metric(&current, "maximum", 
     121                        METRIC_DOUBLE, avail > 0.0 ? &max : NULL); 
     122  noit_stats_set_metric(&current, "average", 
     123                        METRIC_DOUBLE, avail > 0.0 ? &avg : NULL); 
    120124  noit_check_set_stats(self, check, &current); 
    121125} 
  • src/noit_check.c

    r646e6d2 r7b92762  
    378378    new_check->flags |= NP_DISABLED; 
    379379  } 
     380  noit_check_log_check(new_check); 
    380381  return 0; 
    381382} 
     
    490491} 
    491492 
    492 void 
    493 noit_stats_set_metric_int(stats_t *newstate, char *name, int *value) { 
    494   metric_t *m = calloc(1, sizeof(*m)); 
     493static size_t 
     494noit_metric_sizes(metric_type_t type, void *value) { 
     495  switch(type) { 
     496    case METRIC_INT32: 
     497    case METRIC_UINT32: 
     498      return sizeof(int32_t); 
     499    case METRIC_INT64: 
     500    case METRIC_UINT64: 
     501      return sizeof(int64_t); 
     502    case METRIC_DOUBLE: 
     503      return sizeof(double); 
     504    case METRIC_STRING: 
     505      return strlen((char *)value) + 1; 
     506    case METRIC_GUESS: 
     507      break; 
     508  } 
     509  assert(type != type); 
     510  return 0; 
     511
     512static metric_type_t 
     513noit_metric_guess_type(const char *s) { 
     514  if(!s) return METRIC_GUESS; 
     515  return METRIC_STRING; 
     516
     517void 
     518noit_stats_set_metric(stats_t *newstate, char *name, metric_type_t type, 
     519                      void *value) { 
     520  metric_t *m; 
     521  if(type == METRIC_GUESS) type = noit_metric_guess_type((char *)value); 
     522  if(type == METRIC_GUESS) return; 
     523 
     524  m = calloc(1, sizeof(*m)); 
    495525  m->metric_name = strdup(name); 
    496   m->metric_type = METRIC_INT
     526  m->metric_type = type
    497527  if(value) { 
    498     m->metric_value.i = malloc(sizeof(*value)); 
    499     *(m->metric_value.i) = *value; 
    500   } 
    501   __stats_add_metric(newstate, m); 
    502 
    503  
    504 void 
    505 noit_stats_set_metric_float(stats_t *newstate, char *name, float *value) { 
    506   metric_t *m = calloc(1, sizeof(*m)); 
    507   m->metric_name = strdup(name); 
    508   m->metric_type = METRIC_FLOAT; 
    509   if(value) { 
    510     m->metric_value.f = malloc(sizeof(*value)); 
    511     *(m->metric_value.f) = *value; 
    512   } 
    513   __stats_add_metric(newstate, m); 
    514 
    515  
    516 void 
    517 noit_stats_set_metric_string(stats_t *newstate, char *name, char *value) { 
    518   metric_t *m = calloc(1, sizeof(*m)); 
    519   m->metric_name = strdup(name); 
    520   m->metric_type = METRIC_STRING; 
    521   m->metric_value.s = value ? strdup(value) : NULL; 
     528    size_t len; 
     529    len = noit_metric_sizes(type, value); 
     530    m->metric_value.vp = calloc(1, len); 
     531    memcpy(m->metric_value.vp, value, len); 
     532  } 
    522533  __stats_add_metric(newstate, m); 
    523534} 
     
    554565          __noit_check_state_string(check->stats.current.state)); 
    555566  } 
     567 
     568  /* Write out our status */ 
     569  noit_check_log_status(check); 
     570  /* Write out all metrics */ 
     571  noit_check_log_metrics(check); 
     572 
    556573  for(dep = check->causal_checks; dep; dep = dep->next) { 
    557574    noit_module_t *mod; 
  • src/noit_check.h

    r646e6d2 r7b92762  
    4545#define NP_GOOD 'G'                /* stats_t.state */ 
    4646 
     47typedef enum { 
     48  METRIC_GUESS = '0', 
     49  METRIC_INT32 = 'i', 
     50  METRIC_UINT32 = 'I', 
     51  METRIC_INT64 = 'l', 
     52  METRIC_UINT64 = 'L', 
     53  METRIC_DOUBLE = 'n', 
     54  METRIC_STRING = 's' 
     55} metric_type_t; 
     56 
    4757typedef struct { 
    4858  char *metric_name; 
    49   enum { METRIC_INT, METRIC_FLOAT, METRIC_STRING } metric_type; 
     59  metric_type_t metric_type; 
    5060  union { 
    51     float *f; 
    52     int *i; 
     61    double *n; 
     62    int32_t *i; 
     63    u_int32_t *I; 
     64    int64_t *l; 
     65    u_int64_t *L; 
    5366    char *s; 
     67    void *vp; /* used for clever assignments */ 
    5468  } metric_value; 
    5569} metric_t; 
     
    152166 
    153167API_EXPORT(void) 
    154   noit_stats_set_metric_int(stats_t *newstate, char *name, int *value); 
    155 API_EXPORT(void) 
    156   noit_stats_set_metric_float(stats_t *newstate, char *name, float *value); 
    157 API_EXPORT(void) 
    158   noit_stats_set_metric_string(stats_t *newstate, char *name, char *value); 
     168  noit_stats_set_metric(stats_t *, char *, metric_type_t, void *); 
     169 
     170/* These are from noit_check_log.c */ 
     171API_EXPORT(void) noit_check_log_check(noit_check_t *check); 
     172API_EXPORT(void) noit_check_log_status(noit_check_t *check); 
     173API_EXPORT(void) noit_check_log_metrics(noit_check_t *check); 
    159174 
    160175#endif 
  • src/sample.conf

    r1648bed r7b92762  
    1313    <log name="debug" disabled="true"> 
    1414      <outlet name="stderr" /> 
     15    </log> 
     16    <!--<log name="feed" type="jlog" path="/var/log/noitd.feed" />--> 
     17    <log name="feed"><outlet name="stderr"/></log> 
     18    <log name="check"> 
     19      <outlet name="feed" /> 
     20    </log> 
     21    <log name="status"> 
     22      <outlet name="feed" /> 
     23    </log> 
     24    <log name="metrics"> 
     25      <outlet name="feed" /> 
    1526    </log> 
    1627  </logs>