diff options
author | David Goulet <dgoulet@torproject.org> | 2020-10-19 15:50:45 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2020-10-27 10:43:42 -0400 |
commit | a882d1bf0abbbcf2bc4f8c039f9b82262462292c (patch) | |
tree | c37c263e44ba53924929062f473c913e2124dd93 /src/feature/metrics/metrics.c | |
parent | ec731290a5a790093961f0fdb06cf69000194adf (diff) | |
download | tor-a882d1bf0abbbcf2bc4f8c039f9b82262462292c.tar.gz tor-a882d1bf0abbbcf2bc4f8c039f9b82262462292c.zip |
metrics: New feature module to track tor metrics
Related to #40063
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/metrics/metrics.c')
-rw-r--r-- | src/feature/metrics/metrics.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/feature/metrics/metrics.c b/src/feature/metrics/metrics.c new file mode 100644 index 0000000000..5f6fe776b7 --- /dev/null +++ b/src/feature/metrics/metrics.c @@ -0,0 +1,66 @@ +/* Copyright (c) 2007-2020, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * @file metrics.c + * @brief Metrics subsystem. + **/ + +#include "orconfig.h" + +#include "lib/container/smartlist.h" +#include "lib/log/util_bug.h" +#include "lib/malloc/malloc.h" +#include "lib/metrics/metrics_store.h" +#include "lib/string/printf.h" + +#include "feature/metrics/metrics.h" + +#include "app/main/subsysmgr.h" + +/** Return newly allocated string containing the output of all subsystems + * having metrics. + * + * This is used to output the content on the MetricsPort. */ +char * +metrics_get_output(const metrics_format_t fmt) +{ + char *data; + smartlist_t *chunks = smartlist_new(); + + /* Go over all subsystems that exposes a metrics store. */ + for (unsigned i = 0; i < n_tor_subsystems; ++i) { + const smartlist_t *stores; + const subsys_fns_t *sys = tor_subsystems[i]; + + /* Skip unsupported subsystems. */ + if (!sys->supported) { + continue; + } + + if (sys->get_metrics && (stores = sys->get_metrics())) { + SMARTLIST_FOREACH_BEGIN(stores, const metrics_store_t *, store) { + smartlist_add(chunks, metrics_store_get_output(fmt, store)); + } SMARTLIST_FOREACH_END(store); + } + } + + data = smartlist_join_strings(chunks, "\n", 0, NULL); + + SMARTLIST_FOREACH(chunks, char *, c, tor_free(c)); + smartlist_free(chunks); + + return data; +} + +/** Initialize the subsystem. */ +void +metrics_init(void) +{ +} + +/** Cleanup and free any global memory of this subsystem. */ +void +metrics_cleanup(void) +{ +} |