From 203f502006af94dad51056820bc9ae63cac69cca Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 18 Jun 2020 14:15:10 -0400 Subject: [PATCH] TT#77806 add port stats to JSON/bencode output Change-Id: Ieff8e9442b20e3ee1de570a7ef10cfb92f605064 --- daemon/statistics.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/daemon/statistics.c b/daemon/statistics.c index 4ed99463f..3d7b4743b 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -577,6 +577,39 @@ GQueue *statistics_gather_metrics(void) { METRICs("totalerrorcount", "%u", total.errors); HEADER("}", ""); + + HEADER("interfaces", NULL); + HEADER("[", NULL); + for (GList *l = all_local_interfaces.head; l; l = l->next) { + struct local_intf *lif = l->data; + // only show first-order interface entries: socket families must match + if (lif->logical->preferred_family != lif->spec->local_address.addr.family) + continue; + + HEADER("{", NULL); + + METRICsva("name", "\"%s\"", lif->logical->name.s); + METRICsva("address", "\"%s\"", sockaddr_print_buf(&lif->spec->local_address.addr)); + + HEADER("ports", NULL); + HEADER("{", NULL); + + METRICs("min", "%u", lif->spec->port_pool.min); + METRICs("max", "%u", lif->spec->port_pool.max); + unsigned int f = g_atomic_int_get(&lif->spec->port_pool.free_ports); + unsigned int l = g_atomic_int_get(&lif->spec->port_pool.last_used); + unsigned int r = lif->spec->port_pool.max - lif->spec->port_pool.min + 1; + METRICs("used", "%u", r - f); + METRICs("used_pct", "%.2f", (double) (r - f) * 100.0 / r); + METRICs("free", "%u", f); + METRICs("totals", "%u", r); + METRICs("last", "%u", l); + + HEADER("}", NULL); + HEADER("}", NULL); + } + HEADER("]", NULL); + HEADER("}", NULL); return ret;