Changeset c385b68fdd537ec15c1467e6c8541b32d3838bf6

Show
Ignore:
Timestamp:
05/22/12 14:48:01 (2 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1337698081 -0400
git-parent:

[c0606177e96ca2dd9ca395a81715892807816f5c]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1337698081 -0400
Message:

Add lookup by ip/module.

Make the counters into a rate like statsd does.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/statsd.c

    rc060617 rc385b68  
    4646#include "utils/noit_hash.h" 
    4747 
    48 #define MAX_DEPTH 32 
     48#define MAX_CHECKS 3 
    4949 
    5050static noit_log_stream_t nlerr = NULL; 
     
    153153  /* Next the actual data */ 
    154154  snprintf(buff, sizeof(buff), "%s`%s", key, 
    155            (type == 'c') ? "counter" : (type == 'g') ? "gauge" : "timing"); 
     155           (type == 'c') ? "rate" : (type == 'g') ? "gauge" : "timing"); 
    156156  m = noit_stats_get_metric(check, &ccl->current, buff); 
    157157  if(type == 'c') { 
    158     double v = diff * (1.0 / sample)
     158    double v = diff * (1.0 / sample) / (check->period / 1000.0)
    159159    if(m && m->metric_type == METRIC_DOUBLE && m->metric_value.n != NULL) { 
    160160      (*m->metric_value.n) += v; 
     
    176176 
    177177static void 
    178 statsd_handle_payload(noit_check_t *parent, noit_check_t *single
     178statsd_handle_payload(noit_check_t **checks, int nchecks
    179179                      char *payload, int len) { 
    180180  char *cp, *ecp, *endptr; 
     
    182182  endptr = payload + len - 1; 
    183183  while(ecp != NULL && ecp < endptr) { 
    184     int idx = 0, last_space = 0; 
     184    int i, idx = 0, last_space = 0; 
    185185    char key[256], *value; 
    186186    const char *type = NULL; 
     
    240240        case 'c': 
    241241        case 'm': 
    242           if(parent) update_check(parent, key, *type, diff, sampleRate); 
    243           if(single) update_check(single, key, *type, diff, sampleRate); 
     242          for(i=0;i<nchecks;i++) 
     243            update_check(checks[i], key, *type, diff, sampleRate); 
    244244          break; 
    245245        default: 
     
    259259  int packets_per_cycle; 
    260260  statsd_mod_config_t *conf; 
    261   noit_check_t *check = NULL, *parent = NULL; 
     261  noit_check_t *parent = NULL; 
    262262 
    263263  conf = noit_module_get_userdata(self); 
     
    266266  packets_per_cycle = MAX(conf->packets_per_cycle, 1); 
    267267  for( ; packets_per_cycle > 0; packets_per_cycle--) { 
     268    noit_check_t *checks[MAX_CHECKS]; 
     269    int nchecks = 0; 
    268270    char ip[INET6_ADDRSTRLEN]; 
    269271    union { 
     
    277279                   (struct sockaddr *)&addr, &addrlen); 
    278280    if(len < 0) { 
    279       if(errno == EAGAIN) 
     281      if(errno != EAGAIN) 
    280282        noitL(nlerr, "statsd: recvfrom() -> %s\n", strerror(errno)); 
    281283      break; 
     
    294296    } 
    295297    conf->payload[len] = '\0'; 
    296     check = *ip ? noit_poller_lookup_by_name(ip, "statsd") : NULL; 
    297     if(parent || check) 
    298       statsd_handle_payload(parent, check, conf->payload, len); 
     298    nchecks = 0; 
     299    if(*ip) 
     300      nchecks = noit_poller_lookup_by_ip_module(ip, self->hdr.name, 
     301                                                checks, MAX_CHECKS-1); 
     302    if(parent) checks[nchecks++] = parent; 
     303    if(nchecks) 
     304      statsd_handle_payload(checks, nchecks, conf->payload, len); 
    299305  } 
    300306  return EVENTER_READ | EVENTER_EXCEPTION; 
  • src/noit_check.c

    rac0eb62 rc385b68  
    999999} 
    10001000int 
    1001 noit_poller_target_do(char *target, int (*f)(noit_check_t *, void *), 
     1001noit_poller_target_do(const char *target, int (*f)(noit_check_t *, void *), 
    10021002                      void *closure) { 
    10031003  int count = 0; 
     
    10061006 
    10071007  memset(&pivot, 0, sizeof(pivot)); 
    1008   pivot.target = target; 
     1008  pivot.target = (char *)target; 
    10091009  pivot.name = ""; 
    10101010  noit_skiplist_find_neighbors(&polls_by_name, &pivot, NULL, NULL, &next); 
     
    10161016  } 
    10171017  return count; 
     1018} 
     1019struct ip_module_collector_crutch { 
     1020  noit_check_t **array; 
     1021  const char *module; 
     1022  int idx; 
     1023  int allocd; 
     1024}; 
     1025static int ip_module_collector(noit_check_t *check, void *cl) { 
     1026  struct ip_module_collector_crutch *c = cl; 
     1027  if(c->idx >= c->allocd) return 0; 
     1028  if(strcmp(check->module, c->module)) return 0; 
     1029  c->array[c->idx++] = check; 
     1030  return 1; 
     1031} 
     1032int 
     1033noit_poller_lookup_by_ip_module(const char *ip, const char *mod, 
     1034                                noit_check_t **checks, int nchecks) { 
     1035  struct ip_module_collector_crutch crutch; 
     1036  crutch.array = checks; 
     1037  crutch.allocd = nchecks; 
     1038  crutch.idx = 0; 
     1039  crutch.module = mod; 
     1040  return noit_poller_target_do(ip, ip_module_collector, &crutch); 
    10181041} 
    10191042 
  • src/noit_check.h

    rac0eb62 rc385b68  
    228228 
    229229API_EXPORT(int) 
    230    noit_poller_target_do(char *target, int (*f)(noit_check_t *, void *), 
     230  noit_poller_lookup_by_ip_module(const char *ip, const char *mod, 
     231                                  noit_check_t **checks, int nchecks); 
     232 
     233API_EXPORT(int) 
     234   noit_poller_target_do(const char *target, int (*f)(noit_check_t *, void *), 
    231235                         void *closure); 
    232236