Changeset 7a237a223e8874bc0bffede7505313cb1a933910

Show
Ignore:
Timestamp:
03/08/12 01:21:04 (7 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1331169664 -0500
git-parent:

[42eb2c1c2706d6c086e6841479db964ed2d61504]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1331169664 -0500
Message:

Normalize the stats APIs to:

  • never take the module, and
  • always take the check
Files:

Legend:

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

    r4593184 r7a237a2  
    12251225  if(check->flags & NP_TRANSIENT) return 0; 
    12261226 
    1227   noit_check_stats_clear(&current); 
     1227  noit_check_stats_clear(check, &current); 
    12281228  gettimeofday(&current.whence, NULL); 
    12291229 
    12301230  // Concat all the names together so they fit into the flat noitd model  
    12311231  concat_metrics(buffer, n->plugin, n->plugin_instance, n->type, n->type_instance); 
    1232   noit_stats_set_metric(&ccl->current, buffer, METRIC_STRING, n->message); 
     1232  noit_stats_set_metric(check, &ccl->current, buffer, METRIC_STRING, n->message); 
    12331233  immediate = noit_collects_check_aynsch(self,check); 
    12341234  if(immediate) 
    12351235    noit_stats_log_immediate_metric(check, buffer, METRIC_STRING, n->message); 
    1236   noit_check_passive_set_stats(self, check, &current); 
     1236  noit_check_passive_set_stats(check, &current); 
    12371237  noitL(nldeb, "collectd: dispatch_notifications(%s, %s, %s)\n",check->target, buffer, n->message); 
    12381238  return 0; 
     
    12621262    { 
    12631263      case DS_TYPE_COUNTER: 
    1264         noit_stats_set_metric(&ccl->current, buffer, METRIC_UINT64, &vl->values[i].counter); 
     1264        noit_stats_set_metric(check, &ccl->current, buffer, METRIC_UINT64, &vl->values[i].counter); 
    12651265        if(immediate) noit_stats_log_immediate_metric(check, buffer, METRIC_UINT64, &vl->values[i].counter); 
    12661266        break; 
    12671267 
    12681268      case DS_TYPE_GAUGE: 
    1269         noit_stats_set_metric(&ccl->current, buffer, METRIC_DOUBLE, &vl->values[i].gauge); 
     1269        noit_stats_set_metric(check, &ccl->current, buffer, METRIC_DOUBLE, &vl->values[i].gauge); 
    12701270        if(immediate) noit_stats_log_immediate_metric(check, buffer, METRIC_DOUBLE, &vl->values[i].gauge); 
    12711271        break; 
    12721272 
    12731273      case DS_TYPE_DERIVE: 
    1274         noit_stats_set_metric(&ccl->current, buffer, METRIC_INT64, &vl->values[i].derive); 
     1274        noit_stats_set_metric(check, &ccl->current, buffer, METRIC_INT64, &vl->values[i].derive); 
    12751275        if(immediate) noit_stats_log_immediate_metric(check, buffer, METRIC_INT64, &vl->values[i].derive); 
    12761276        break; 
    12771277 
    12781278      case DS_TYPE_ABSOLUTE: 
    1279         noit_stats_set_metric(&ccl->current, buffer, METRIC_INT64, &vl->values[i].absolute); 
     1279        noit_stats_set_metric(check, &ccl->current, buffer, METRIC_INT64, &vl->values[i].absolute); 
    12801280        if(immediate) noit_stats_log_immediate_metric(check, buffer, METRIC_INT64, &vl->values[i].absolute); 
    12811281        break; 
     
    12911291  } 
    12921292  return 0; 
    1293 }  
    1294  
    1295 static void clear_closure(collectd_closure_t *ccl) { 
     1293} 
     1294 
     1295static void clear_closure(noit_check_t *check, collectd_closure_t *ccl) { 
    12961296  ccl->stats_count = 0; 
    12971297  ccl->ntfy_count = 0; 
    1298   noit_check_stats_clear(&ccl->current); 
     1298  noit_check_stats_clear(check, &ccl->current); 
    12991299 
    13001300} 
     
    13301330        NP_GOOD : NP_BAD; 
    13311331    ccl->current.status = human_buffer; 
    1332     noit_check_passive_set_stats(self, check, &ccl->current); 
     1332    noit_check_passive_set_stats(check, &ccl->current); 
    13331333 
    13341334    memcpy(&check->last_fire_time, &ccl->current.whence, sizeof(duration)); 
    13351335  } 
    1336   clear_closure(ccl); 
     1336  clear_closure(check, ccl); 
    13371337  return 0; 
    13381338} 
  • src/modules/dns.c

    r470b93f r7a237a2  
    211211             ci->nrr, ci->nrr == 1 ? "record" : "records"); 
    212212    ci->current.status = strdup(buff); 
    213     noit_stats_set_metric(&ci->current, "rtt", METRIC_DOUBLE, 
     213    noit_stats_set_metric(ci->check, &ci->current, "rtt", METRIC_DOUBLE, 
    214214                          ci->timed_out ? NULL : &rtt); 
    215215  } 
    216216 
    217   noit_check_set_stats(ci->self, ci->check, &ci->current); 
     217  noit_check_set_stats(ci->check, &ci->current); 
    218218  if(ci->error) free(ci->error); 
    219219  if(ci->current.status) free(ci->current.status); 
     
    407407 
    408408  ttl = rr->dnsrr_ttl; 
    409   noit_stats_set_metric(&ci->current, "ttl", METRIC_UINT32, &ttl); 
     409  noit_stats_set_metric(ci->check, &ci->current, "ttl", METRIC_UINT32, &ttl); 
    410410 
    411411  switch(rr->dnsrr_typ) { 
     
    444444     if(dns_getdn(pkt, &dptr, end, dn, DNS_MAXDN) <= 0) goto decode_err; 
    445445     dns_dntop(dn, buff, sizeof(buff)); 
    446      noit_stats_set_metric(&ci->current, "name-server", METRIC_STRING, buff); 
     446     noit_stats_set_metric(ci->check, &ci->current, "name-server", METRIC_STRING, buff); 
    447447     if(dns_getdn(pkt, &dptr, end, dn, DNS_MAXDN) <= 0) goto decode_err; 
    448448     dns_dntop(dn, buff, sizeof(buff)); 
    449      noit_stats_set_metric(&ci->current, "email-addr", METRIC_STRING, buff); 
     449     noit_stats_set_metric(ci->check, &ci->current, "email-addr", METRIC_STRING, buff); 
    450450     if(dptr + 5 * sizeof(u_int32_t) != dend) goto decode_err; 
    451451     vu = dns_get32(dptr); dptr += sizeof(u_int32_t); 
    452      noit_stats_set_metric(&ci->current, "serial", METRIC_UINT32, &vu); 
     452     noit_stats_set_metric(ci->check, &ci->current, "serial", METRIC_UINT32, &vu); 
    453453     /* the serial is what we elect to store as the "answer" as text... 
    454454      * because it rarely changes and that seems the most interesting thing 
     
    457457     snprintf(buff, sizeof(buff), "%u", vu); 
    458458     vs = dns_get32(dptr); dptr += sizeof(int32_t); 
    459      noit_stats_set_metric(&ci->current, "refresh", METRIC_UINT32, &vs); 
     459     noit_stats_set_metric(ci->check, &ci->current, "refresh", METRIC_UINT32, &vs); 
    460460     vs = dns_get32(dptr); dptr += sizeof(int32_t); 
    461      noit_stats_set_metric(&ci->current, "retry", METRIC_UINT32, &vs); 
     461     noit_stats_set_metric(ci->check, &ci->current, "retry", METRIC_UINT32, &vs); 
    462462     vs = dns_get32(dptr); dptr += sizeof(int32_t); 
    463      noit_stats_set_metric(&ci->current, "expiry", METRIC_UINT32, &vs); 
     463     noit_stats_set_metric(ci->check, &ci->current, "expiry", METRIC_UINT32, &vs); 
    464464     vs = dns_get32(dptr); dptr += sizeof(int32_t); 
    465      noit_stats_set_metric(&ci->current, "minimum", METRIC_UINT32, &vs); 
     465     noit_stats_set_metric(ci->check, &ci->current, "minimum", METRIC_UINT32, &vs); 
    466466     break; 
    467467 
     
    548548        /* This actually updates what we're looking for */ 
    549549        dns_dntodn(p.dnsp_dnbuf, ci->dn, sizeof(dn)); 
    550         noit_stats_set_metric(&ci->current, "cname", METRIC_INT32, &on); 
     550        noit_stats_set_metric(ci->check, &ci->current, "cname", METRIC_INT32, &on); 
    551551 
    552552        /* Now follow the leader */ 
     
    585585    free(result_str[i]); /* free as we go */ 
    586586  } 
    587   noit_stats_set_metric(&ci->current, "answer", METRIC_STRING, result_combined); 
     587  noit_stats_set_metric(ci->check, &ci->current, "answer", METRIC_STRING, result_combined); 
    588588 
    589589 cleanup: 
  • src/modules/external.c

    r840a13b r7a237a2  
    126126  struct timeval duration; 
    127127 
    128   noit_check_stats_clear(&current); 
     128  noit_check_stats_clear(check, &current); 
    129129 
    130130  data = noit_module_get_userdata(self); 
     
    167167                                   "value", value, sizeof(value)) > 0) { 
    168168        /* We're able to extract something... */ 
    169         noit_stats_set_metric(&current, metric, METRIC_GUESS, value); 
     169        noit_stats_set_metric(check, &current, metric, METRIC_GUESS, value); 
    170170      } 
    171171      noitL(data->nldeb, "going to match output at %d/%d\n", startoffset, len); 
     
    175175 
    176176  current.status = ci->output; 
    177   noit_check_set_stats(self, check, &current); 
     177  noit_check_set_stats(check, &current); 
    178178 
    179179  /* If we didn't exit normally, or we core, or we have stderr to report... 
  • src/modules/httptrap.c

    rded8598 r7a237a2  
    141141} 
    142142 
    143 static void clear_closure(httptrap_closure_t *ccl) { 
     143static void clear_closure(noit_check_t *check, httptrap_closure_t *ccl) { 
    144144  ccl->stats_count = 0; 
    145   noit_check_stats_clear(&ccl->current); 
     145  noit_check_stats_clear(check, &ccl->current); 
    146146} 
    147147 
     
    157157    ccl = check->closure = (void *)calloc(1, sizeof(httptrap_closure_t));  
    158158    memset(ccl, 0, sizeof(httptrap_closure_t)); 
     159    ccl->self = self; 
    159160  } else { 
    160161    // Don't count the first run 
     
    177178    ccl->current.status = human_buffer; 
    178179    if(check->last_fire_time.tv_sec) 
    179       noit_check_passive_set_stats(self, check, &ccl->current); 
     180      noit_check_passive_set_stats(check, &ccl->current); 
    180181 
    181182    memcpy(&check->last_fire_time, &ccl->current.whence, sizeof(duration)); 
    182183  } 
    183   clear_closure(ccl); 
     184  clear_closure(check, ccl); 
    184185  return 0; 
    185186} 
     
    194195#define setstat(key, mt, v) do { \ 
    195196  cnt++; \ 
    196   noit_stats_set_metric(&ccl->current, key, mt, v); \ 
     197  noit_stats_set_metric(check, &ccl->current, key, mt, v); \ 
    197198  if(immediate) noit_stats_log_immediate_metric(check, key, mt, v); \ 
    198199} while(0) 
  • src/modules/ip_acl.c

    r17458db r7a237a2  
    159159  snprintf(deny_msg, sizeof(deny_msg), "prevented by ACL '%s'", k ? k : "unknown"); 
    160160  current.status = deny_msg; 
    161   noit_check_set_stats(self, check, &current); 
     161  noit_check_set_stats(check, &current); 
    162162  return NOIT_HOOK_DONE; 
    163163} 
  • src/modules/lua.c

    r2e4d166 r7a237a2  
    315315  if(!lua_isstring(L, 1)) luaL_error(L, "argument #1 must be a string"); 
    316316  json = lua_tolstring(L, 1, &jsonlen); 
    317   rv = noit_check_stats_from_json_str(&ci->current, json, (int)jsonlen); 
     317  rv = noit_check_stats_from_json_str(check, &ci->current, json, (int)jsonlen); 
    318318  lua_pushinteger(L, rv); 
    319319  return 1; 
     
    339339  metric_type = lua_tointeger(L, lua_upvalueindex(2)); 
    340340  if(lua_isnil(L, 2)) { 
    341     noit_stats_set_metric(&ci->current, metric_name, metric_type, NULL); 
     341    noit_stats_set_metric(check, &ci->current, metric_name, metric_type, NULL); 
    342342    lua_pushboolean(L, 1); 
    343343    return 1; 
     
    350350    case METRIC_DOUBLE: 
    351351      if(!lua_isnumber(L, 2)) { 
    352         noit_stats_set_metric(&ci->current, metric_name, metric_type, NULL); 
     352        noit_stats_set_metric(check, &ci->current, metric_name, metric_type, NULL); 
    353353        lua_pushboolean(L, 0); 
    354354        return 1; 
     
    360360    case METRIC_GUESS: 
    361361    case METRIC_STRING: 
    362       noit_stats_set_metric(&ci->current, metric_name, metric_type, 
     362      noit_stats_set_metric(check, &ci->current, metric_name, metric_type, 
    363363                            (void *)lua_tostring(L, 2)); 
    364364      break; 
    365365    case METRIC_INT32: 
    366366      __i = strtol(lua_tostring(L, 2), NULL, 10); 
    367       noit_stats_set_metric(&ci->current, metric_name, metric_type, &__i); 
     367      noit_stats_set_metric(check, &ci->current, metric_name, metric_type, &__i); 
    368368      break; 
    369369    case METRIC_UINT32: 
    370370      __I = strtoul(lua_tostring(L, 2), NULL, 10); 
    371       noit_stats_set_metric(&ci->current, metric_name, metric_type, &__I); 
     371      noit_stats_set_metric(check, &ci->current, metric_name, metric_type, &__I); 
    372372      break; 
    373373    case METRIC_INT64: 
    374374      __l = strtoll(lua_tostring(L, 2), NULL, 10); 
    375       noit_stats_set_metric(&ci->current, metric_name, metric_type, &__l); 
     375      noit_stats_set_metric(check, &ci->current, metric_name, metric_type, &__l); 
    376376      break; 
    377377    case METRIC_UINT64: 
    378378      __L = strtoull(lua_tostring(L, 2), NULL, 10); 
    379       noit_stats_set_metric(&ci->current, metric_name, metric_type, &__L); 
     379      noit_stats_set_metric(check, &ci->current, metric_name, metric_type, &__L); 
    380380      break; 
    381381    case METRIC_DOUBLE: 
    382382      __n = luaL_optnumber(L, 2, 0); 
    383       noit_stats_set_metric(&ci->current, metric_name, metric_type, &__n); 
     383      noit_stats_set_metric(check, &ci->current, metric_name, metric_type, &__n); 
    384384      break; 
    385385  } 
     
    669669  if(ci->current.state != NP_UNKNOWN || 
    670670     ci->current.available != NP_UNKNOWN) 
    671     noit_check_set_stats(self, check, &ci->current); 
     671    noit_check_set_stats(check, &ci->current); 
    672672  free(ci->current.status); 
    673673} 
     
    782782  ci->check = check; 
    783783  ci->cause = cause; 
    784   noit_check_stats_clear(&ci->current); 
     784  noit_check_stats_clear(check, &ci->current); 
    785785 
    786786  gettimeofday(&__now, NULL); 
  • src/modules/mysql.c

    r8b4fa37 r7a237a2  
    116116              piv = &iv; 
    117117            } 
    118             noit_stats_set_metric(&ci->current, mname, METRIC_INT32, piv); 
     118            noit_stats_set_metric(ci->check, &ci->current, mname, METRIC_INT32, piv); 
    119119            break; 
    120120          case FIELD_TYPE_INT24: 
     
    125125              plv = &lv; 
    126126            } 
    127             noit_stats_set_metric(&ci->current, mname, METRIC_INT64, plv); 
     127            noit_stats_set_metric(ci->check, &ci->current, mname, METRIC_INT64, plv); 
    128128            break; 
    129129          case FIELD_TYPE_DECIMAL: 
     
    135135              pdv = &dv; 
    136136            } 
    137             noit_stats_set_metric(&ci->current, mname, METRIC_DOUBLE, pdv); 
     137            noit_stats_set_metric(ci->check, &ci->current, mname, METRIC_DOUBLE, pdv); 
    138138            break; 
    139139          default: 
    140140            if(!row[j]) sv = NULL; 
    141141            else sv = row[j]; 
    142             noit_stats_set_metric(&ci->current, mname, METRIC_GUESS, sv); 
     142            noit_stats_set_metric(ci->check, &ci->current, mname, METRIC_GUESS, sv); 
    143143            break; 
    144144        } 
     
    170170 
    171171  if(ci->rv >= 0) 
    172     noit_stats_set_metric(&ci->current, "row_count", METRIC_INT32, &ci->rv); 
     172    noit_stats_set_metric(check, &ci->current, "row_count", METRIC_INT32, &ci->rv); 
    173173  if(ci->connect_duration) 
    174     noit_stats_set_metric(&ci->current, "connect_duration", METRIC_DOUBLE, 
     174    noit_stats_set_metric(check, &ci->current, "connect_duration", METRIC_DOUBLE, 
    175175                          ci->connect_duration); 
    176176  if(ci->query_duration) 
    177     noit_stats_set_metric(&ci->current, "query_duration", METRIC_DOUBLE, 
     177    noit_stats_set_metric(check, &ci->current, "query_duration", METRIC_DOUBLE, 
    178178                          ci->query_duration); 
    179179 
    180   noit_check_set_stats(self, check, &ci->current); 
     180  noit_check_set_stats(check, &ci->current); 
    181181} 
    182182 
     
    264264  switch(mask) { 
    265265    case EVENTER_ASYNCH_WORK: 
    266       noit_check_stats_clear(&ci->current); 
     266      noit_check_stats_clear(ci->check, &ci->current); 
    267267      ci->connect_duration = NULL; 
    268268      ci->query_duration = NULL; 
  • src/modules/ping_icmp.c

    rf91ddca r7a237a2  
    129129  struct timeval duration; 
    130130 
    131   noit_check_stats_clear(&current); 
     131  noit_check_stats_clear(check, &current); 
    132132 
    133133  data = (struct check_info *)check->closure; 
     
    163163  current.state = (avail < ((float)avail_needed / 100.0)) ? NP_BAD : NP_GOOD; 
    164164  current.status = human_buffer; 
    165   noit_stats_set_metric(&current, "count", 
     165  noit_stats_set_metric(check, &current, "count", 
    166166                        METRIC_INT32, &data->expected_count); 
    167167  avail *= 100.0; 
    168   noit_stats_set_metric(&current, "available", METRIC_DOUBLE, &avail); 
    169   noit_stats_set_metric(&current, "minimum", 
     168  noit_stats_set_metric(check, &current, "available", METRIC_DOUBLE, &avail); 
     169  noit_stats_set_metric(check, &current, "minimum", 
    170170                        METRIC_DOUBLE, avail > 0.0 ? &min : NULL); 
    171   noit_stats_set_metric(&current, "maximum", 
     171  noit_stats_set_metric(check, &current, "maximum", 
    172172                        METRIC_DOUBLE, avail > 0.0 ? &max : NULL); 
    173   noit_stats_set_metric(&current, "average", 
     173  noit_stats_set_metric(check, &current, "average", 
    174174                        METRIC_DOUBLE, avail > 0.0 ? &avg : NULL); 
    175   noit_check_set_stats(self, check, &current); 
     175  noit_check_set_stats(check, &current); 
    176176} 
    177177static int ping_icmp_timeout(eventer_t e, int mask, 
  • src/modules/postgres.c

    rd0f189b r7a237a2  
    105105    nrows = PQntuples(ci->result); 
    106106    ncols = PQnfields(ci->result); 
    107     noit_stats_set_metric(&ci->current, "row_count", METRIC_INT32, &nrows); 
     107    noit_stats_set_metric(ci->check, &ci->current, "row_count", METRIC_INT32, &nrows); 
    108108    for (i=0; i<nrows; i++) { 
    109109      noitL(nldeb, "postgres: row %d [%d cols]:\n", i, ncols); 
     
    130130              piv = &iv; 
    131131            } 
    132             noit_stats_set_metric(&ci->current, mname, METRIC_INT32, piv); 
     132            noit_stats_set_metric(ci->check, &ci->current, mname, METRIC_INT32, piv); 
    133133            break; 
    134134          case INT2OID: 
     
    140140              plv = &lv; 
    141141            } 
    142             noit_stats_set_metric(&ci->current, mname, METRIC_INT64, plv); 
     142            noit_stats_set_metric(ci->check, &ci->current, mname, METRIC_INT64, plv); 
    143143            break; 
    144144          case FLOAT4OID: 
     
    150150              pdv = &dv; 
    151151            } 
    152             noit_stats_set_metric(&ci->current, mname, METRIC_DOUBLE, pdv); 
     152            noit_stats_set_metric(ci->check, &ci->current, mname, METRIC_DOUBLE, pdv); 
    153153            break; 
    154154          default: 
    155155            if(PQgetisnull(ci->result, i, j)) sv = NULL; 
    156156            else sv = PQgetvalue(ci->result, i, j); 
    157             noit_stats_set_metric(&ci->current, mname, METRIC_GUESS, sv); 
     157            noit_stats_set_metric(ci->check, &ci->current, mname, METRIC_GUESS, sv); 
    158158            break; 
    159159        } 
     
    172172  ci->current.state = NP_BAD; 
    173173  if(ci->connect_duration) 
    174     noit_stats_set_metric(&ci->current, "connect_duration", METRIC_DOUBLE, 
     174    noit_stats_set_metric(ci->check, &ci->current, "connect_duration", METRIC_DOUBLE, 
    175175                          ci->connect_duration); 
    176176  if(ci->query_duration) 
    177     noit_stats_set_metric(&ci->current, "query_duration", METRIC_DOUBLE, 
     177    noit_stats_set_metric(ci->check, &ci->current, "query_duration", METRIC_DOUBLE, 
    178178                          ci->query_duration); 
    179179  if(ci->error) ci->current.status = ci->error; 
     
    191191  else ci->current.status = "internal error"; 
    192192 
    193   noit_check_set_stats(self, check, &ci->current); 
     193  noit_check_set_stats(check, &ci->current); 
    194194} 
    195195 
     
    230230  switch(mask) { 
    231231    case EVENTER_ASYNCH_WORK: 
    232       noit_check_stats_clear(&ci->current); 
     232      noit_check_stats_clear(ci->check, &ci->current); 
    233233      ci->connect_duration = NULL; 
    234234      ci->query_duration = NULL; 
  • src/modules/selfcheck.c

    r811c412 r7a237a2  
    5555} selfcheck_info_t; 
    5656 
     57struct threadq_crutch { 
     58  noit_check_t *check; 
     59  stats_t *current; 
     60}; 
     61 
    5762static noit_log_stream_t nlerr = NULL; 
    5863static noit_log_stream_t nldeb = NULL; 
     
    6873  int s32; 
    6974  char buffer[128]; 
    70   stats_t *current = (stats_t *)closure; 
     75  struct threadq_crutch *crutch = (struct threadq_crutch *)closure; 
    7176  s32 = jobq->concurrency; 
    7277  if(s32 == 0) return; /* omit if no concurrency */ 
    7378  snprintf(buffer, sizeof(buffer), "%s_threads", jobq->queue_name); 
    74   noit_stats_set_metric(current, buffer, METRIC_INT32, &s32); 
    75 } 
    76 static int selfcheck_feed_details(jlog_feed_stats_t *s, void *vcurrent) { 
     79  noit_stats_set_metric(crutch->check, crutch->current, buffer, METRIC_INT32, &s32); 
     80} 
     81static int selfcheck_feed_details(jlog_feed_stats_t *s, void *closure) { 
    7782  char buff[256]; 
    7883  uint64_t ms; 
    7984  struct timeval now, diff; 
    80   stats_t *current = (stats_t *)vcurrent
     85  struct threadq_crutch *crutch = (struct threadq_crutch *)closure
    8186  gettimeofday(&now, NULL); 
    8287 
     
    8590    ms = diff.tv_sec * 1000 + diff.tv_usec / 1000; 
    8691    snprintf(buff, sizeof(buff), "feed`%s`last_connection_ms", s->feed_name); 
    87     noit_stats_set_metric(current, buff, METRIC_UINT64, &ms); 
     92    noit_stats_set_metric(crutch->check, crutch->current, buff, METRIC_UINT64, &ms); 
    8893  } 
    8994 
     
    9297    ms = diff.tv_sec * 1000 + diff.tv_usec / 1000; 
    9398    snprintf(buff, sizeof(buff), "feed`%s`last_checkpoint_ms", s->feed_name); 
    94     noit_stats_set_metric(current, buff, METRIC_UINT64, &ms); 
     99    noit_stats_set_metric(crutch->check, crutch->current, buff, METRIC_UINT64, &ms); 
    95100  } 
    96101  return 1; 
     
    102107  int32_t s32; 
    103108  stats_t current; 
     109  struct threadq_crutch crutch; 
    104110  struct timeval duration, epoch, diff; 
    105111  selfcheck_info_t *ci = check->closure; 
    106112 
    107   noit_check_stats_clear(&current); 
     113  crutch.check = check; 
     114  crutch.current = &current; 
     115  noit_check_stats_clear(check, &current); 
    108116 
    109117  gettimeofday(&current.whence, NULL); 
     
    120128  /* Set all the metrics here */ 
    121129  s64 = (int64_t)ci->logsize; 
    122   noit_stats_set_metric(&current, "feed_bytes", METRIC_INT64, &s64); 
     130  noit_stats_set_metric(check, &current, "feed_bytes", METRIC_INT64, &s64); 
    123131  s32 = noit_poller_check_count(); 
    124   noit_stats_set_metric(&current, "check_cnt", METRIC_INT32, &s32); 
     132  noit_stats_set_metric(check, &current, "check_cnt", METRIC_INT32, &s32); 
    125133  s32 = noit_poller_transient_check_count(); 
    126   noit_stats_set_metric(&current, "transient_cnt", METRIC_INT32, &s32); 
     134  noit_stats_set_metric(check, &current, "transient_cnt", METRIC_INT32, &s32); 
    127135  if(eventer_get_epoch(&epoch)) s64 = 0; 
    128136  else { 
     
    130138    s64 = diff.tv_sec; 
    131139  } 
    132   noit_stats_set_metric(&current, "uptime", METRIC_INT64, &s64); 
    133   eventer_jobq_process_each(jobq_thread_helper, &current); 
     140  noit_stats_set_metric(check, &current, "uptime", METRIC_INT64, &s64); 
     141  eventer_jobq_process_each(jobq_thread_helper, &crutch); 
    134142  noit_build_version(buff, sizeof(buff)); 
    135   noit_stats_set_metric(&current, "version", METRIC_STRING, buff); 
     143  noit_stats_set_metric(check, &current, "version", METRIC_STRING, buff); 
    136144  u64 = noit_check_completion_count(); 
    137   noit_stats_set_metric(&current, "checks_run", METRIC_UINT64, &u64); 
     145  noit_stats_set_metric(check, &current, "checks_run", METRIC_UINT64, &u64); 
    138146  /* feed pull info */ 
    139   noit_jlog_foreach_feed_stats(selfcheck_feed_details, &current); 
    140  
    141   noit_check_set_stats(self, check, &current); 
     147  noit_jlog_foreach_feed_stats(selfcheck_feed_details, &crutch); 
     148 
     149  noit_check_set_stats(check, &current); 
    142150} 
    143151 
  • src/modules/snmp.c

    r84946f6 r7a237a2  
    215215  int nresults = 0; 
    216216 
    217   noit_check_stats_clear(&current); 
     217  noit_check_stats_clear(check, &current); 
    218218 
    219219  if(pdu) 
     
    231231  /* We have no results over which to iterate. */ 
    232232  if(!pdu) { 
    233     noit_check_set_stats(self, check, &current); 
     233    noit_check_set_stats(check, &current); 
    234234    return; 
    235235  } 
     
    267267    } 
    268268 
    269 #define SETM(a,b) noit_stats_set_metric(&current, \ 
     269#define SETM(a,b) noit_stats_set_metric(check, &current, \ 
    270270                                        info->oids[oid_idx].confname, a, b) 
    271271    if(info->oids[oid_idx].type_should_override) { 
     
    273273      sp = strchr(varbuff, ' '); 
    274274      if(sp) sp++; 
    275       noit_stats_set_metric_coerce(&current, info->oids[oid_idx].confname, 
     275      noit_stats_set_metric_coerce(check, &current, info->oids[oid_idx].confname, 
    276276                                   info->oids[oid_idx].type_override, 
    277277                                   sp); 
     
    327327    nresults++; 
    328328  } 
    329   noit_check_set_stats(self, check, &current); 
     329  noit_check_set_stats(check, &current); 
    330330} 
    331331 
     
    566566 
    567567static int 
    568 noit_snmp_trapvars_to_stats(stats_t *current, netsnmp_variable_list *var) { 
     568noit_snmp_trapvars_to_stats(noit_check_t *check, stats_t *current, 
     569                            netsnmp_variable_list *var) { 
    569570  if(isoidprefix(var->name, var->name_length, reconnoiter_check_status_oid, 
    570571                 reconnoiter_check_status_oid_len)) { 
     
    650651      case ASN_TIMETICKS: 
    651652      case ASN_INTEGER64: 
    652         noit_stats_set_metric(current, metric_name, 
     653        noit_stats_set_metric(check, current, metric_name, 
    653654                              METRIC_INT64, var->val.integer); 
    654655        break; 
     
    656657        u64 = ((u_int64_t)var->val.counter64->high) << 32; 
    657658        u64 |= var->val.counter64->low; 
    658         noit_stats_set_metric(current, metric_name, 
     659        noit_stats_set_metric(check, current, metric_name, 
    659660                              METRIC_UINT64, &u64); 
    660661        break; 
    661662      case ASN_OPAQUE_FLOAT: 
    662663        doubleVal = (double)*var->val.floatVal; 
    663         noit_stats_set_metric(current, metric_name, 
     664        noit_stats_set_metric(check, current, metric_name, 
    664665                              METRIC_DOUBLE, &doubleVal); 
    665666        break; 
    666667      case ASN_OPAQUE_DOUBLE: 
    667         noit_stats_set_metric(current, metric_name, 
     668        noit_stats_set_metric(check, current, metric_name, 
    668669                              METRIC_DOUBLE, var->val.doubleVal); 
    669670        break; 
     
    684685          } 
    685686        } 
    686         noit_stats_set_metric(current, metric_name, 
     687        noit_stats_set_metric(check, current, metric_name, 
    687688                              METRIC_STRING, (cp && *cp) ? cp : NULL); 
    688689        break; 
     
    776777 
    777778  for(; var != NULL; var = var->next_variable) 
    778     if(noit_snmp_trapvars_to_stats(&current, var) == 0) success++; 
     779    if(noit_snmp_trapvars_to_stats(check, &current, var) == 0) success++; 
    779780  if(success) { 
    780781    char buff[24]; 
     
    787788    current.status = strdup("no data"); 
    788789  } 
    789   noit_check_set_stats(ts->self, check, &current); 
     790  noit_check_set_stats(check, &current); 
    790791 
    791792 cleanup: 
  • src/modules/ssh2.c

    rf91ddca r7a237a2  
    115115  ssh2_check_info_t *ci = check->closure; 
    116116 
    117   noit_check_stats_clear(&current); 
     117  noit_check_stats_clear(check, &current); 
    118118 
    119119  gettimeofday(&current.whence, NULL); 
     
    130130  if(ci->fingerprint[0]) { 
    131131    u_int32_t mduration = current.duration; 
    132     noit_stats_set_metric(&current, "duration", METRIC_UINT32, &mduration); 
    133     noit_stats_set_metric(&current, "fingerprint", METRIC_STRING, 
     132    noit_stats_set_metric(check, &current, "duration", METRIC_UINT32, &mduration); 
     133    noit_stats_set_metric(check, &current, "fingerprint", METRIC_STRING, 
    134134                          ci->fingerprint); 
    135135  } 
    136   noit_check_set_stats(self, check, &current); 
     136  noit_check_set_stats(check, &current); 
    137137} 
    138138static int ssh2_drive_session(eventer_t e, int mask, void *closure, 
  • src/modules/test_abort.c

    rf91ddca r7a237a2  
    100100     */ 
    101101    stats_t current; 
    102     noit_check_stats_clear(&current); 
     102    noit_check_stats_clear(check, &current); 
    103103    current.available = NP_AVAILABLE; 
    104104    current.state = ci->timed_out ? NP_BAD : NP_GOOD; 
    105105    noitL(nlerr, "test_abort: EVENTER_READ | EVENTER_WRITE\n"); 
    106     noit_check_set_stats(ci->self, check, &current); 
     106    noit_check_set_stats(check, &current); 
    107107    check->flags &= ~NP_RUNNING; 
    108108    return 0; 
     
    113113      r = modf(ci->timeout, &i); 
    114114      ci->timed_out = 1; 
    115        
     115 
    116116      if(ci->ignore_signals) { /* compuational loop */ 
    117117        double trash = 1.0; 
  • src/noit_check.c

    r1a07d8a r7a237a2  
    10121012  assert(!(check->flags & NP_RUNNING)); 
    10131013  check->flags |= NP_RUNNING; 
    1014   noit_check_stats_clear(&current); 
     1014  noit_check_stats_clear(check, &current); 
    10151015  gettimeofday(&current.whence, NULL); 
    10161016  current.duration = 0; 
     
    10201020           check->module); 
    10211021  current.status = buff; 
    1022   noit_check_set_stats(self, check, &current); 
     1022  noit_check_set_stats(check, &current); 
    10231023  check->flags &= ~NP_RUNNING; 
    10241024  return 0; 
    10251025} 
    10261026void 
    1027 noit_check_stats_clear(stats_t *s) { 
     1027noit_check_stats_clear(noit_check_t *check, stats_t *s) { 
    10281028  memset(s, 0, sizeof(*s)); 
    10291029  s->state = NP_UNKNOWN; 
     
    12001200} 
    12011201void 
    1202 noit_stats_set_metric(stats_t *newstate, const char *name, metric_type_t type, 
     1202noit_stats_set_metric(noit_check_t *check, 
     1203                      stats_t *newstate, const char *name, metric_type_t type, 
    12031204                      const void *value) { 
    12041205  metric_t *m = calloc(1, sizeof(*m)); 
     
    12101211} 
    12111212void 
    1212 noit_stats_set_metric_coerce(stats_t *stat, const char *name, metric_type_t t, 
     1213noit_stats_set_metric_coerce(noit_check_t *check, 
     1214                             stats_t *stat, const char *name, metric_type_t t, 
    12131215                             const char *v) { 
    12141216  char *endptr; 
    12151217  if(v == NULL) { 
    12161218   bogus: 
    1217     noit_stats_set_metric(stat, name, t, NULL); 
     1219    noit_stats_set_metric(check, stat, name, t, NULL); 
    12181220    return; 
    12191221  } 
    12201222  switch(t) { 
    12211223    case METRIC_STRING: 
    1222       noit_stats_set_metric(stat, name, t, v); 
     1224      noit_stats_set_metric(check, stat, name, t, v); 
    12231225      break; 
    12241226    case METRIC_INT32: 
     
    12271229      val = strtol(v, &endptr, 10); 
    12281230      if(endptr == v) goto bogus; 
    1229       noit_stats_set_metric(stat, name, t, &val); 
     1231      noit_stats_set_metric(check, stat, name, t, &val); 
    12301232      break; 
    12311233    } 
     
    12351237      val = strtoul(v, &endptr, 10); 
    12361238      if(endptr == v) goto bogus; 
    1237       noit_stats_set_metric(stat, name, t, &val); 
     1239      noit_stats_set_metric(check, stat, name, t, &val); 
    12381240      break; 
    12391241    } 
     
    12431245      val = strtoll(v, &endptr, 10); 
    12441246      if(endptr == v) goto bogus; 
    1245       noit_stats_set_metric(stat, name, t, &val); 
     1247      noit_stats_set_metric(check, stat, name, t, &val); 
    12461248      break; 
    12471249    } 
     
    12511253      val = strtoull(v, &endptr, 10); 
    12521254      if(endptr == v) goto bogus; 
    1253       noit_stats_set_metric(stat, name, t, &val); 
     1255      noit_stats_set_metric(check, stat, name, t, &val); 
    12541256      break; 
    12551257    } 
     
    12591261      val = strtod(v, &endptr); 
    12601262      if(endptr == v) goto bogus; 
    1261       noit_stats_set_metric(stat, name, t, &val); 
     1263      noit_stats_set_metric(check, stat, name, t, &val); 
    12621264      break; 
    12631265    } 
    12641266    case METRIC_GUESS: 
    1265       noit_stats_set_metric(stat, name, t, v); 
     1267      noit_stats_set_metric(check, stat, name, t, v); 
    12661268      break; 
    12671269  } 
     
    12831285 
    12841286void 
    1285 noit_check_passive_set_stats(struct _noit_module *module,  
    1286                              noit_check_t *check, stats_t *newstate) { 
     1287noit_check_passive_set_stats(noit_check_t *check, stats_t *newstate) { 
    12871288  noit_skiplist_node *next; 
    12881289  noit_check_t n; 
     
    12911292  n.period = 0; 
    12921293 
    1293   noit_check_set_stats(module,check,newstate); 
     1294  noit_check_set_stats(check,newstate); 
    12941295  noit_skiplist_find_neighbors(&watchlist, &n, NULL, NULL, &next); 
    12951296  while(next && next->data) { 
     
    13121313} 
    13131314void 
    1314 noit_check_set_stats(struct _noit_module *module, 
    1315                      noit_check_t *check, stats_t *newstate) { 
     1315noit_check_set_stats(noit_check_t *check, stats_t *newstate) { 
    13161316  int report_change = 0; 
    13171317  char *cp; 
  • src/noit_check.h

    rab62dcb r7a237a2  
    234234 
    235235API_EXPORT(void) 
    236   noit_check_stats_clear(stats_t *s); 
     236  noit_check_stats_clear(noit_check_t *check, stats_t *s); 
    237237 
    238238struct _noit_module; 
    239239/* This if for modules (passive) than cannot be watched... */ 
    240240API_EXPORT(void) 
    241   noit_check_passive_set_stats(struct _noit_module *self, noit_check_t *check, 
     241  noit_check_passive_set_stats(noit_check_t *check, 
    242242                               stats_t *newstate); 
    243243/* This is for normal (active) modules... */ 
    244244API_EXPORT(void) 
    245   noit_check_set_stats(struct _noit_module *self, noit_check_t *check, 
     245  noit_check_set_stats(noit_check_t *check, 
    246246                        stats_t *newstate); 
    247247 
    248248API_EXPORT(void) 
    249   noit_stats_set_metric(stats_t *, const char *, metric_type_t, const void *); 
    250  
    251 API_EXPORT(void) 
    252   noit_stats_set_metric_coerce(stats_t *, const char *, metric_type_t, 
     249  noit_stats_set_metric(noit_check_t *check, 
     250                        stats_t *, const char *, metric_type_t, const void *); 
     251 
     252API_EXPORT(void) 
     253  noit_stats_set_metric_coerce(noit_check_t *check, 
     254                               stats_t *, const char *, metric_type_t, 
    253255                               const char *); 
    254256 
  • src/noit_check_tools.c

    r14748d7 r7a237a2  
    174174 
    175175static int 
    176 populate_stats_from_resmon_formatted_json(stats_t *s, struct json_object *o, 
     176populate_stats_from_resmon_formatted_json(noit_check_t *check, 
     177                                          stats_t *s, struct json_object *o, 
    177178                                          const char *prefix) { 
    178179  int count = 0; 
     
    184185  if(o == NULL) { 
    185186    if(prefix) { 
    186       noit_stats_set_metric(s, prefix, METRIC_STRING, NULL); 
     187      noit_stats_set_metric(check, s, prefix, METRIC_STRING, NULL); 
    187188      count++; 
    188189    } 
     
    197198        struct json_object *item = json_object_array_get_idx(o, i); 
    198199        MKKEY("%d", i); 
    199         count += populate_stats_from_resmon_formatted_json(s, item, keybuff); 
     200        count += populate_stats_from_resmon_formatted_json(check, s, item, keybuff); 
    200201      } 
    201202    } 
     
    213214          struct json_object *item = (struct json_object *)el->v; 
    214215          MKKEY("%s", (const char *)el->k); 
    215           count += populate_stats_from_resmon_formatted_json(s, item, keybuff); 
     216          count += populate_stats_from_resmon_formatted_json(check, s, item, keybuff); 
    216217        } 
    217218      } 
     
    228229          case METRIC_DOUBLE: 
    229230          case METRIC_STRING: 
    230             noit_stats_set_metric_coerce(s, prefix, 
     231            noit_stats_set_metric_coerce(check, s, prefix, 
    231232                                         (metric_type_t)*type_str, value_str); 
    232233            count++; 
     
    241242    case json_type_string: 
    242243      if(prefix) { 
    243         noit_stats_set_metric(s, prefix, METRIC_GUESS, 
     244        noit_stats_set_metric(check, s, prefix, METRIC_GUESS, 
    244245                              (char *)json_object_get_string(o)); 
    245246        count++; 
     
    249250      if(prefix) { 
    250251        int val = json_object_get_boolean(o) ? 1 : 0; 
    251         noit_stats_set_metric(s, prefix, METRIC_INT32, &val); 
     252        noit_stats_set_metric(check, s, prefix, METRIC_INT32, &val); 
    252253        count++; 
    253254      } 
     
    255256    case json_type_null: 
    256257      if(prefix) { 
    257         noit_stats_set_metric(s, prefix, METRIC_STRING, NULL); 
     258        noit_stats_set_metric(check, s, prefix, METRIC_STRING, NULL); 
    258259        count++; 
    259260      } 
     
    262263      if(prefix) { 
    263264        double val = json_object_get_double(o); 
    264         noit_stats_set_metric(s, prefix, METRIC_DOUBLE, &val); 
     265        noit_stats_set_metric(check, s, prefix, METRIC_DOUBLE, &val); 
    265266        count++; 
    266267      } 
     
    273274          case json_overflow_int: 
    274275            i64 = json_object_get_int(o); 
    275             noit_stats_set_metric(s, prefix, METRIC_INT64, &i64); 
     276            noit_stats_set_metric(check, s, prefix, METRIC_INT64, &i64); 
    276277            count++; 
    277278            break; 
    278279          case json_overflow_int64: 
    279280            i64 = json_object_get_int64(o); 
    280             noit_stats_set_metric(s, prefix, METRIC_INT64, &i64); 
     281            noit_stats_set_metric(check, s, prefix, METRIC_INT64, &i64); 
    281282            count++; 
    282283            break; 
    283284          case json_overflow_uint64: 
    284285            u64 = json_object_get_uint64(o); 
    285             noit_stats_set_metric(s, prefix, METRIC_UINT64, &u64); 
     286            noit_stats_set_metric(check, s, prefix, METRIC_UINT64, &u64); 
    286287            count++; 
    287288            break; 
     
    292293} 
    293294int 
    294 noit_check_stats_from_json_str(stats_t *s, const char *json_str, int len) { 
     295noit_check_stats_from_json_str(noit_check_t *check, stats_t *s, 
     296                               const char *json_str, int len) { 
    295297  int rv = -1; 
    296298  struct json_tokener *tok = NULL; 
     
    298300  tok = json_tokener_new(); 
    299301  root = json_tokener_parse_ex(tok, json_str, len); 
    300   if(root) rv = populate_stats_from_resmon_formatted_json(s, root, NULL); 
     302  if(root) rv = populate_stats_from_resmon_formatted_json(check, s, root, NULL); 
    301303  if(tok) json_tokener_free(tok); 
    302304  if(root) json_object_put(root); 
  • src/noit_check_tools.h

    r278ca95 r7a237a2  
    6161 
    6262API_EXPORT(int) 
    63   noit_check_stats_from_json_str(stats_t *s, const char *json_str, int len); 
     63  noit_check_stats_from_json_str(noit_check_t *check, stats_t *s, 
     64                                 const char *json_str, int len); 
    6465 
    6566/*#* DOCBOOK