TT#44702 add CLI command for interface/port stats

Change-Id: I670b3779d748e81097995961d6411d21a279bd08
changes/23/23823/1
Richard Fuchs 7 years ago
parent 71efae70e6
commit 35764c5c63

@ -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);

@ -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);

@ -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);

Loading…
Cancel
Save