From 35764c5c6327952f96e6bde48c18cb0ec8a3df5c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 26 Sep 2018 11:04:22 -0400 Subject: [PATCH] TT#44702 add CLI command for interface/port stats Change-Id: I670b3779d748e81097995961d6411d21a279bd08 --- daemon/cli.c | 25 +++++++++++++++++++++++++ daemon/media_socket.c | 3 +++ include/media_socket.h | 4 ++++ 3 files changed, 32 insertions(+) diff --git a/daemon/cli.c b/daemon/cli.c index 2d5fb131f..62f23ef13 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -25,6 +25,7 @@ #include "str.h" #include "statistics.h" #include "main.h" +#include "media_socket.h" #include "rtpengine_config.h" @@ -84,6 +85,7 @@ static void cli_incoming_list_redisdisabletime(str *instr, struct streambuf *rep static void cli_incoming_list_redisconnecttimeout(str *instr, struct streambuf *replybuffer); static void cli_incoming_list_rediscmdtimeout(str *instr, struct streambuf *replybuffer); static void cli_incoming_list_controltos(str *instr, struct streambuf *replybuffer); +static void cli_incoming_list_interfaces(str *instr, struct streambuf *replybuffer); static const cli_handler_t cli_top_handlers[] = { { "list", cli_incoming_list }, @@ -134,6 +136,7 @@ static const cli_handler_t cli_list_handlers[] = { { "redisconnecttimeout", cli_incoming_list_redisconnecttimeout }, { "rediscmdtimeout", cli_incoming_list_rediscmdtimeout }, { "controltos", cli_incoming_list_controltos }, + { "interfaces", cli_incoming_list_interfaces }, { NULL, }, }; @@ -1363,6 +1366,28 @@ static void cli_incoming_set_rediscmdtimeout(str *instr, struct streambuf *reply streambuf_printf(replybuffer, "Success setting redis-cmd-timeout to %ld\n", timeout); } +static void cli_incoming_list_interfaces(str *instr, struct streambuf *replybuffer) { + 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; + streambuf_printf(replybuffer, "Interface '%s' address '%s' (%s)\n", lif->logical->name.s, + sockaddr_print_buf(&lif->spec->local_address.addr), + lif->spec->local_address.addr.family->name); + streambuf_printf(replybuffer, " Port range: %5u - %5u\n", + lif->spec->port_pool.min, + 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; + streambuf_printf(replybuffer, " Ports used: %5u / %5u (%5.1f%%)\n", + r - f, r, (double) (r - f) * 100.0 / r); + streambuf_printf(replybuffer, " Last port used: %5u\n", + l); + } +} + static void cli_incoming_list_controltos(str *instr, struct streambuf *replybuffer) { rwlock_lock_r(&rtpe_config.config_lock); streambuf_printf(replybuffer, "%d\n", rtpe_config.control_tos); diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 1d45a8890..5ac12f3c3 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -285,6 +285,8 @@ static GHashTable *__intf_spec_addr_type_hash; // addr + type -> struct intf_spe static GHashTable *__local_intf_addr_type_hash; // addr + type -> GList of struct local_intf static GQueue __preferred_lists_for_family[__SF_LAST]; +GQueue all_local_interfaces = G_QUEUE_INIT; + /* checks for free no_ports on a local interface */ @@ -580,6 +582,7 @@ static void __interface_append(struct intf_config *ifa, sockfamily_t *fam) { ifc->logical = lif; g_hash_table_insert(lif->addr_hash, &spec->local_address, ifc); + g_queue_push_tail(&all_local_interfaces, ifc); __insert_local_intf_addr_type(&spec->local_address, ifc); __insert_local_intf_addr_type(&ifc->advertised_address, ifc); diff --git a/include/media_socket.h b/include/media_socket.h index 59a4a52f7..6d86e4584 100644 --- a/include/media_socket.h +++ b/include/media_socket.h @@ -97,6 +97,10 @@ struct media_packet { +extern GQueue all_local_interfaces; // read-only during runtime + + + void interfaces_init(GQueue *interfaces); struct logical_intf *get_logical_interface(const str *name, sockfamily_t *fam, int num_ports);