diff --git a/src/metric.c b/src/metric.c index c758605..a1b33bb 100644 --- a/src/metric.c +++ b/src/metric.c @@ -49,6 +49,7 @@ gauge__record(struct brubeck_metric *metric, value_t value, value_t sample_freq, } else { metric->as.gauge.value = value; } + metric->expire = BRUBECK_EXPIRE_ACTIVE; } pthread_spin_unlock(&metric->lock); } @@ -61,6 +62,7 @@ gauge__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa pthread_spin_lock(&metric->lock); { value = metric->as.gauge.value; + metric->expire = BRUBECK_EXPIRE_DISABLED; } pthread_spin_unlock(&metric->lock); @@ -82,6 +84,7 @@ meter__record(struct brubeck_metric *metric, value_t value, value_t sample_freq, pthread_spin_lock(&metric->lock); { metric->as.meter.value += value; + metric->expire = BRUBECK_EXPIRE_ACTIVE; } pthread_spin_unlock(&metric->lock); } @@ -95,6 +98,7 @@ meter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *opa { value = metric->as.meter.value; metric->as.meter.value = 0.0; + metric->expire = BRUBECK_EXPIRE_DISABLED; } pthread_spin_unlock(&metric->lock); @@ -124,6 +128,7 @@ counter__record(struct brubeck_metric *metric, value_t value, value_t sample_fre } metric->as.counter.previous = value; + metric->expire = BRUBECK_EXPIRE_ACTIVE; } pthread_spin_unlock(&metric->lock); } @@ -137,6 +142,7 @@ counter__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void *o { value = metric->as.counter.value; metric->as.counter.value = 0.0; + metric->expire = BRUBECK_EXPIRE_DISABLED; } pthread_spin_unlock(&metric->lock); @@ -155,6 +161,7 @@ histogram__record(struct brubeck_metric *metric, value_t value, value_t sample_f pthread_spin_lock(&metric->lock); { brubeck_histo_push(&metric->as.histogram, value, sample_freq); + metric->expire = BRUBECK_EXPIRE_ACTIVE; } pthread_spin_unlock(&metric->lock); } @@ -168,6 +175,7 @@ histogram__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void pthread_spin_lock(&metric->lock); { brubeck_histo_sample(&hsample, &metric->as.histogram); + metric->expire = BRUBECK_EXPIRE_DISABLED; } pthread_spin_unlock(&metric->lock); @@ -187,11 +195,6 @@ histogram__sample(struct brubeck_metric *metric, brubeck_sample_cb sample, void sample(key, hsample.count / (double)backend->sample_freq, opaque); } - /* if there have been no metrics during this sampling period, - * we don't need to report any of the histogram samples */ - if (hsample.count == 0.0) - return; - WITH_SUFFIX(".min") { sample(key, hsample.min, opaque); } @@ -333,6 +336,5 @@ brubeck_metric_find(struct brubeck_server *server, const char *key, size_t key_l brubeck_atomic_inc(&metric->flow); #endif - metric->expire = BRUBECK_EXPIRE_ACTIVE; return metric; } diff --git a/src/server.c b/src/server.c index 0584697..8fc96ca 100644 --- a/src/server.c +++ b/src/server.c @@ -63,16 +63,6 @@ update_proctitle(struct brubeck_server *server) setproctitle("brubeck", buf); } -static void -expire_metric(struct brubeck_metric *mt, void *_) -{ - /* If this metric is not disabled, turn "inactive" - * into "disabled" and "active" into "inactive" - */ - if (mt->expire > BRUBECK_EXPIRE_DISABLED) - mt->expire = mt->expire - 1; -} - static void dump_metric(struct brubeck_metric *mt, void *out_file) { @@ -192,7 +182,6 @@ static void load_config(struct brubeck_server *server, const char *path) json_t *backends, *samplers; /* optional */ - int expire = 0; char *http = NULL; server->name = "brubeck"; @@ -211,8 +200,7 @@ static void load_config(struct brubeck_server *server, const char *path) "capacity", &capacity, "backends", &backends, "samplers", &samplers, - "http", &http, - "expire", &expire); + "http", &http); gh_log_set_instance(server->name); @@ -224,7 +212,6 @@ static void load_config(struct brubeck_server *server, const char *path) load_samplers(server, samplers); if (http) brubeck_http_endpoint_init(server, http); - if (expire) server->fd_expire = load_timerfd(expire); } void brubeck_server_init(struct brubeck_server *server, const char *config) @@ -237,7 +224,6 @@ void brubeck_server_init(struct brubeck_server *server, const char *config) server->fd_signal = load_signalfd(); server->fd_update = load_timerfd(1); - server->fd_expire = -1; /* init the memory allocator */ brubeck_slab_init(&server->slab); @@ -272,7 +258,7 @@ static int signal_triggered(struct pollfd *fd) int brubeck_server_run(struct brubeck_server *server) { - struct pollfd fds[3]; + struct pollfd fds[2]; int nfd = 2; size_t i; @@ -284,11 +270,6 @@ int brubeck_server_run(struct brubeck_server *server) fds[1].fd = server->fd_update; fds[1].events = POLLIN; - if (server->fd_expire >= 0) { - fds[2].fd = server->fd_expire; - fds[2].events = POLLIN; - nfd++; - } server->running = 1; log_splunk("event=listening"); @@ -315,11 +296,6 @@ int brubeck_server_run(struct brubeck_server *server) update_flows(server); update_proctitle(server); } - - if (timer_elapsed(&fds[2])) { - log_splunk("event=expire_metrics"); - brubeck_hashtable_foreach(server->metrics, &expire_metric, NULL); - } } for (i = 0; i < server->active_backends; ++i)