Changeset c0606177e96ca2dd9ca395a81715892807816f5c

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

[f22ed556234ab8522cbdd79c7fa6da2cf9d7b302]

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

add a sample check. change atoi() to strtod(). Do in-place metrics updating for performance reasons.

Files:

Legend:

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

    rc04fc7f rc060617  
    132132update_check(noit_check_t *check, const char *key, char type, 
    133133             double diff, double sample) { 
    134   u_int32_t count = 1; 
     134  u_int32_t one = 1; 
    135135  char buff[256]; 
    136136  statsd_closure_t *ccl; 
     
    143143  snprintf(buff, sizeof(buff), "%s`count", key); 
    144144  m = noit_stats_get_metric(check, &ccl->current, buff); 
    145   if(m && m->metric_type == METRIC_UINT32 && m->metric_value.I != NULL) 
    146     count = *m->metric_value.I + 1; 
    147   noit_stats_set_metric(check, &ccl->current, buff, METRIC_UINT32, &count); 
     145  if(!m) ccl->stats_count++; 
     146  if(m && m->metric_type == METRIC_UINT32 && m->metric_value.I != NULL) { 
     147    (*m->metric_value.I)++; 
     148    check_stats_set_metric_hook_invoke(check, &ccl->current, m); 
     149  } 
     150  else 
     151    noit_stats_set_metric(check, &ccl->current, buff, METRIC_UINT32, &one); 
    148152 
    149153  /* Next the actual data */ 
    150   m = noit_stats_get_metric(check, &ccl->current, key); 
     154  snprintf(buff, sizeof(buff), "%s`%s", key, 
     155           (type == 'c') ? "counter" : (type == 'g') ? "gauge" : "timing"); 
     156  m = noit_stats_get_metric(check, &ccl->current, buff); 
    151157  if(type == 'c') { 
    152158    double v = diff * (1.0 / sample); 
    153     if(m && m->metric_type == METRIC_DOUBLE && m->metric_value.n != NULL) 
    154       v += (*m->metric_value.n); 
    155     noit_stats_set_metric(check, &ccl->current, key, METRIC_DOUBLE, &v); 
     159    if(m && m->metric_type == METRIC_DOUBLE && m->metric_value.n != NULL) { 
     160      (*m->metric_value.n) += v; 
     161      check_stats_set_metric_hook_invoke(check, &ccl->current, m); 
     162    } 
     163    else 
     164      noit_stats_set_metric(check, &ccl->current, buff, METRIC_DOUBLE, &v); 
    156165  } 
    157166  else if(type == 'g' || type == 'm') { 
    158167    double v = diff; 
    159     noit_stats_set_metric(check, &ccl->current, key, METRIC_DOUBLE, &v); 
     168    if(m && m->metric_type == METRIC_DOUBLE && m->metric_value.n != NULL) { 
     169      (*m->metric_value.n) = v; 
     170      check_stats_set_metric_hook_invoke(check, &ccl->current, m); 
     171    } 
     172    else 
     173      noit_stats_set_metric(check, &ccl->current, buff, METRIC_DOUBLE, &v); 
    160174  } 
    161175} 
     
    218232          } 
    219233        } 
    220         diff = atoi(value); 
     234        diff = strtod(value, NULL); 
    221235      } 
    222236      if(type == NULL) type = COUNTER_STRING; 
  • src/noit.conf.in

    r94228ea rc060617  
    164164    </dc1> 
    165165    <check uuid="002d58ff-20ff-4db0-9420-782fc1748dc4" module="ssh2" target="10.80.117.2" period="60000" timeout="4000"/> 
     166    <check uuid="ff4f1de8-a405-11e1-8770-9347de0fce85" module="statsd" target="127.0.0.1" period="60000" timeout="59999"/> 
    166167  </checks> 
    167168  <filtersets>