diff options
author | Vladimír Čunát <vladimir.cunat@nic.cz> | 2024-05-20 14:11:07 +0200 |
---|---|---|
committer | Oto Šťáva <oto.stava@nic.cz> | 2024-05-20 14:11:07 +0200 |
commit | 9acf77508fcf06299d2b00c272c1931bb00d1612 (patch) | |
tree | e886a51ad5fbc39602803874350ee849b2cb4c20 /modules | |
parent | modules/stats: split request.* metrics to IPv4 and IPv6 (diff) | |
download | knot-resolver-9acf77508fcf06299d2b00c272c1931bb00d1612.tar.xz knot-resolver-9acf77508fcf06299d2b00c272c1931bb00d1612.zip |
modules/stats: add back stats dropped in the previous commit
Just as read-only aggregates of the split v4+v6 pairs.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/stats/stats.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/modules/stats/stats.c b/modules/stats/stats.c index 285e9486..36796152 100644 --- a/modules/stats/stats.c +++ b/modules/stats/stats.c @@ -65,6 +65,28 @@ static struct const_metric_elm const_metrics[] = { CONST_METRICS(X) #undef X }; + +/// These metrics are read-only views, each simply summing a pair of const_metrics items. +struct sum_metric { + const char *key; + const size_t *val1, *val2; +}; +static const struct sum_metric sum_metrics[] = { + // We're using this to aggregate v4 + v6 pairs. + #define DEF(proto) { \ + .key = "request." #proto, \ + .val1 = &const_metrics[metric_request_ ## proto ## 4].val, \ + .val2 = &const_metrics[metric_request_ ## proto ## 6].val, \ + } + DEF(udp), + DEF(tcp), + DEF(xdp), + DEF(dot), + DEF(doh), + #undef DEF +}; +static const size_t sum_metrics_len = sizeof(sum_metrics) / sizeof(sum_metrics[0]); + /** @endcond */ /** @internal LRU hash of most frequent names. */ @@ -282,6 +304,7 @@ static int collect(kr_layer_t *ctx) * Set nominal value of a key. * * Input: { key, val } + * Aggregate metrics can't be set. * */ static char* stats_set(void *env, struct kr_module *module, const char *args) @@ -335,6 +358,16 @@ static char* stats_get(void *env, struct kr_module *module, const char *args) return str_value; } } + /* Check if it exists in aggregate metrics. */ + for (int i = 0; i < sum_metrics_len; ++i) { + const struct sum_metric *smi = &sum_metrics[i]; + if (strcmp(smi->key, args) == 0) { + ret = asprintf(&str_value, "%zu", *smi->val1 + *smi->val2); + if (ret < 0) + return NULL; + return str_value; + } + } /* Check in variable map */ trie_val_t *val = trie_get_try(data->trie, args, strlen(args)); if (!val) @@ -388,6 +421,13 @@ static char* stats_list(void *env, struct kr_module *module, const char *args) json_append_member(root, elm->key, json_mknumber((double)elm->val)); } } + for (int i = 0; i < sum_metrics_len; ++i) { + const struct sum_metric *elm = &sum_metrics[i]; + if (!args || strncmp(elm->key, args, args_len) == 0) { + size_t val = *elm->val1 + *elm->val2; + json_append_member(root, elm->key, json_mknumber(val)); + } + } struct list_entry_context ctx = { .root = root, .key_prefix = args, |