From ea073a9bbdf2eee39159794b4fd943583c62276f Mon Sep 17 00:00:00 2001 From: Unbit Date: Tue, 15 Oct 2013 11:11:18 +0200 Subject: [PATCH] exposes metrics to stats --- core/master_utils.c | 26 ++++++++++++++++++++++++++ core/metrics.c | 18 ++---------------- core/uwsgi.c | 2 +- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/core/master_utils.c b/core/master_utils.c index 2b3342ea..85bb1fab 100644 --- a/core/master_utils.c +++ b/core/master_utils.c @@ -871,6 +871,32 @@ struct uwsgi_stats *uwsgi_master_generate_stats() { goto end; } + if (uwsgi.has_metrics) { + if (uwsgi_stats_key(us, "metrics")) + goto end; + + if (uwsgi_stats_object_open(us)) + goto end; + + uwsgi_rlock(uwsgi.metrics_lock); + struct uwsgi_metric *um = uwsgi.metrics; + while(um) { + int64_t um_val = um->initial_value+*um->value; + if (uwsgi_stats_keyslong(us, um->name, (long long) um_val)) { + uwsgi_rwunlock(uwsgi.metrics_lock); + goto end; + } + um = um->next; + } + uwsgi_rwunlock(uwsgi.metrics_lock); + + if (uwsgi_stats_object_close(us)) + goto end; + + if (uwsgi_stats_comma(us)) + goto end; + } + if (uwsgi_stats_key(us, "sockets")) goto end; diff --git a/core/metrics.c b/core/metrics.c index 3277caee..65ecdcd1 100644 --- a/core/metrics.c +++ b/core/metrics.c @@ -406,23 +406,9 @@ int64_t uwsgi_metric_get(char *name, char *oid) { if (!um) return 0; // now (in rlocked context) we get the value from - // the external pointer or from the map - // + // the map uwsgi_rlock(uwsgi.metrics_lock); - switch(um->collect_way) { - case UWSGI_METRIC_PTR: - ret = um->initial_value+*um->ptr; - break; - /* - case UWSGI_METRIC_MANUAL: - case UWSGI_METRIC_FUNC: - case UWSGI_METRIC_FILE: - */ - default: - ret = um->initial_value+*um->value; - break; - } - + ret = um->initial_value+*um->value; // unlock uwsgi_rwunlock(uwsgi.metrics_lock); return ret; diff --git a/core/uwsgi.c b/core/uwsgi.c index 82d557da..48030ae9 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -504,7 +504,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"reload-on-exception-repr", required_argument, 0, "reload a worker when a specific exception type+value (language-specific) is raised", uwsgi_opt_add_string_list, &uwsgi.reload_on_exception_repr, 0}, {"exception-handler", required_argument, 0, "add an exception handler", uwsgi_opt_add_string_list, &uwsgi.exception_handlers_instance, UWSGI_OPT_MASTER}, - {"enable-metrics", required_argument, 0, "enable metrics subsystem", uwsgi_opt_true, &uwsgi.has_metrics, 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},