static int statsd_submit(noit_module_t *self, noit_check_t *check, noit_check_t *cause) { statsd_closure_t *ccl; struct timeval duration; statsd_mod_config_t *conf; conf = noit_module_get_userdata(self); if(!conf->primary_active) conf->check = NULL; if(0 == memcmp(conf->primary, check->checkid, sizeof(uuid_t))) { conf->check = check; if(NOIT_CHECK_DISABLED(check) || NOIT_CHECK_KILLED(check)) { conf->check = NULL; return 0; } } /* We are passive, so we don't do anything for transient checks */ if(check->flags & NP_TRANSIENT) return 0; if(!check->closure) { ccl = check->closure = calloc(1, sizeof(*ccl)); ccl->self = self; memset(&check->stats.inprogress, 0, sizeof(check->stats.inprogress)); } else { // Don't count the first run char human_buffer[256]; ccl = (statsd_closure_t*)check->closure; gettimeofday(&check->stats.inprogress.whence, NULL); sub_timeval(check->stats.inprogress.whence, check->last_fire_time, &duration); check->stats.inprogress.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000; snprintf(human_buffer, sizeof(human_buffer), "dur=%d,run=%d,stats=%d", check->stats.inprogress.duration, check->generation, ccl->stats_count); noitL(nldeb, "statsd(%s) [%s]\n", check->target, human_buffer); // Not sure what to do here check->stats.inprogress.available = (ccl->stats_count > 0) ? NP_AVAILABLE : NP_UNAVAILABLE; check->stats.inprogress.state = (ccl->stats_count > 0) ? NP_GOOD : NP_BAD; check->stats.inprogress.status = human_buffer; if(check->last_fire_time.tv_sec) noit_check_passive_set_stats(check, &check->stats.inprogress); memcpy(&check->last_fire_time, &check->stats.inprogress.whence, sizeof(duration)); } ccl->stats_count = 0; noit_check_stats_clear(check, &check->stats.inprogress); return 0; }
static int httptrap_submit(noit_module_t *self, noit_check_t *check, noit_check_t *cause) { httptrap_closure_t *ccl; struct timeval duration; /* We are passive, so we don't do anything for transient checks */ if(check->flags & NP_TRANSIENT) return 0; mtev_httptrap_check_aynsch(self, check); if(!check->closure) { ccl = check->closure = (void *)calloc(1, sizeof(httptrap_closure_t)); memset(ccl, 0, sizeof(httptrap_closure_t)); ccl->self = self; } else { // Don't count the first run struct timeval now, *last; stats_t *inprogress; char human_buffer[256]; ccl = (httptrap_closure_t*)check->closure; gettimeofday(&now, NULL); sub_timeval(now, check->last_fire_time, &duration); noit_stats_set_whence(check, &now); noit_stats_set_duration(check, duration.tv_sec * 1000 + duration.tv_usec / 1000); snprintf(human_buffer, sizeof(human_buffer), "dur=%ld,run=%d,stats=%d", duration.tv_sec * 1000 + duration.tv_usec / 1000, check->generation, ccl->stats_count); mtevL(nldeb, "httptrap(%s) [%s]\n", check->target, human_buffer); // Not sure what to do here noit_stats_set_available(check, (ccl->stats_count > 0) ? NP_AVAILABLE : NP_UNAVAILABLE); noit_stats_set_state(check, (ccl->stats_count > 0) ? NP_GOOD : NP_BAD); noit_stats_set_status(check, human_buffer); if(check->last_fire_time.tv_sec) noit_check_passive_set_stats(check); inprogress = noit_check_get_stats_inprogress(check); last = noit_check_stats_whence(inprogress, NULL); memcpy(&check->last_fire_time, last, sizeof(duration)); } ccl->stats_count = 0; return 0; }