From d4bd658d84f06dd021e629d5e226f2ca195bafa7 Mon Sep 17 00:00:00 2001 From: Unbit Date: Mon, 21 Oct 2013 19:01:06 +0200 Subject: [PATCH] added restorable metrics --- core/metrics.c | 13 +++++++++++-- core/uwsgi.c | 5 ++++- uwsgi.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/metrics.c b/core/metrics.c index d4215b78..ec9faa56 100644 --- a/core/metrics.c +++ b/core/metrics.c @@ -385,13 +385,13 @@ static void *uwsgi_metrics_loop(void *arg) { // gather the new value based on the type of collection strategy switch(metric->collect_way) { case UWSGI_METRIC_PTR: - *metric->value = *metric->ptr; + *metric->value = metric->initial_value + *metric->ptr; break; // aliases are NOOP case UWSGI_METRIC_ALIAS: break; case UWSGI_METRIC_SUM: - *metric->value = uwsgi_metric_sum(metric); + *metric->value = metric->initial_value + uwsgi_metric_sum(metric); break; case UWSGI_METRIC_FILE: uwsgi_log("reading from file\n"); @@ -736,5 +736,14 @@ void uwsgi_setup_metrics() { if (uwsgi.metrics_dir) { uwsgi_log("memory allocated for metrics storage: %llu bytes (%llu MB)\n", uwsgi.metrics_cnt * uwsgi.page_size, (uwsgi.metrics_cnt * uwsgi.page_size)/1024/1024); + if (uwsgi.metrics_dir_restore) { + metric = uwsgi.metrics; + while(metric) { + if (metric->map) { + metric->initial_value = strtoll(metric->map, NULL, 10); + } + metric = metric->next; + } + } } } diff --git a/core/uwsgi.c b/core/uwsgi.c index b1f5c4d8..222adbd4 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -511,8 +511,11 @@ static struct uwsgi_option uwsgi_base_options[] = { {"exception-handler", required_argument, 0, "add an exception handler", uwsgi_opt_add_string_list, &uwsgi.exception_handlers_instance, UWSGI_OPT_MASTER}, {"enable-metrics", no_argument, 0, "enable metrics subsystem", uwsgi_opt_true, &uwsgi.has_metrics, UWSGI_OPT_MASTER}, - {"metrics-dir", required_argument, 0, "exports metrics as text files in the specified directory", uwsgi_opt_set_str, &uwsgi.metrics_dir, UWSGI_OPT_METRICS|UWSGI_OPT_MASTER}, {"metric", required_argument, 0, "add a custom metric", uwsgi_opt_add_string_list, &uwsgi.additional_metrics, UWSGI_OPT_METRICS|UWSGI_OPT_MASTER}, + {"metrics-dir", required_argument, 0, "exports metrics as text files in the specified directory", uwsgi_opt_set_str, &uwsgi.metrics_dir, UWSGI_OPT_METRICS|UWSGI_OPT_MASTER}, + {"metrics-dir-restore", no_argument, 0, "restore last value taken from the metrics dir", uwsgi_opt_true, &uwsgi.metrics_dir_restore, UWSGI_OPT_METRICS|UWSGI_OPT_MASTER}, + {"metric-dir", required_argument, 0, "exports metrics as text files in the specified directory", uwsgi_opt_set_str, &uwsgi.metrics_dir, UWSGI_OPT_METRICS|UWSGI_OPT_MASTER}, + {"metric-dir-restore", no_argument, 0, "restore last value taken from the metrics dir", uwsgi_opt_true, &uwsgi.metrics_dir_restore, UWSGI_OPT_METRICS|UWSGI_OPT_MASTER}, {"udp", required_argument, 0, "run the udp server on the specified address", uwsgi_opt_set_str, &uwsgi.udp_socket, UWSGI_OPT_MASTER}, {"stats", required_argument, 0, "enable the stats server on the specified address", uwsgi_opt_set_str, &uwsgi.stats, UWSGI_OPT_MASTER}, diff --git a/uwsgi.h b/uwsgi.h index ed17cccb..0b1b28ad 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2574,6 +2574,7 @@ struct uwsgi_server { struct uwsgi_metric *metrics; int has_metrics; char *metrics_dir; + int metrics_dir_restore; uint64_t metrics_cnt; struct uwsgi_string_list *additional_metrics;