Stefan Sperling has uploaded this change for review. ( https://gerrit.osmocom.org/11519
Change subject: add aggregated rtp connection stats to osmo-mgw ...................................................................... add aggregated rtp connection stats to osmo-mgw Add a counter group for aggregated RTP connection statistics. This group contains RTP counters which aggregate values of the ephemeral RTP counters maintained per connection (mgcp_conn). This provides a global overview of RTP processing for each trunk throughout the lifetime of the osmo-mgw process. The counters are displayed by 'show mgcp stats' and 'show rate-counters'. Change-Id: I80d36181600901ae2e0f321dc02b5d54ddc94139 Related: OS#2660 --- M include/osmocom/mgcp/mgcp.h M include/osmocom/mgcp/mgcp_conn.h M src/libosmo-mgcp/mgcp_conn.c M src/libosmo-mgcp/mgcp_protocol.c M src/libosmo-mgcp/mgcp_vty.c 5 files changed, 65 insertions(+), 7 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/19/11519/1 diff --git a/include/osmocom/mgcp/mgcp.h b/include/osmocom/mgcp/mgcp.h index c8c2cfd..4a307cd 100644 --- a/include/osmocom/mgcp/mgcp.h +++ b/include/osmocom/mgcp/mgcp.h @@ -194,9 +194,12 @@ int vty_number_endpoints; struct mgcp_endpoint *endpoints; - /* rate counters */ + /* Rate counter group which contains stats for processed CDCX commands. */ struct rate_ctr_group *mgcp_crcx_ctr_group; + /* Rate counter group which contains stats for processed MDCX commands. */ struct rate_ctr_group *mgcp_mdcx_ctr_group; + /* Rate counter group which aggregates stats of individual RTP connections. */ + struct rate_ctr_group *all_rtp_conn_stats; }; enum mgcp_role { diff --git a/include/osmocom/mgcp/mgcp_conn.h b/include/osmocom/mgcp/mgcp_conn.h index 3da7334..c5c8827 100644 --- a/include/osmocom/mgcp/mgcp_conn.h +++ b/include/osmocom/mgcp/mgcp_conn.h @@ -35,7 +35,8 @@ RTP_OCTETS_RX_CTR, RTP_PACKETS_TX_CTR, RTP_OCTETS_TX_CTR, - RTP_DROPPED_PACKETS_CTR + RTP_DROPPED_PACKETS_CTR, + RTP_NUM_CONNECTIONS, }; struct mgcp_conn *mgcp_conn_alloc(void *ctx, struct mgcp_endpoint *endp, diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c index 820c63a..e040bc5 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -31,13 +31,14 @@ #include <osmocom/core/rate_ctr.h> #include <ctype.h> +/* Must be kept in sync with all_rtp_conn_rate_ctr_desc in mgcp_protocol.c */ static const struct rate_ctr_desc rate_ctr_desc[] = { [IN_STREAM_ERR_TSTMP_CTR] = {"stream_err_tstmp:in", "Inbound rtp-stream timestamp errors."}, [OUT_STREAM_ERR_TSTMP_CTR] = {"stream_err_tstmp:out", "Outbound rtp-stream timestamp errors."}, [RTP_PACKETS_RX_CTR] = {"rtp:packets_rx", "Inbound rtp packets."}, [RTP_OCTETS_RX_CTR] = {"rtp:octets_rx", "Inbound rtp octets."}, [RTP_PACKETS_TX_CTR] = {"rtp:packets_tx", "Outbound rtp packets."}, - [RTP_OCTETS_TX_CTR] = {"rtp:octets_rx", "Outbound rtp octets."}, + [RTP_OCTETS_TX_CTR] = {"rtp:octets_tx", "Outbound rtp octets."}, [RTP_DROPPED_PACKETS_CTR] = {"rtp:dropped", "dropped rtp packets."} }; @@ -234,6 +235,23 @@ return NULL; } +static void +aggregate_rtp_conn_stats(struct mgcp_trunk_config *trunk, struct mgcp_conn_rtp *conn_rtp) +{ + struct rate_ctr_group *all_stats = trunk->all_rtp_conn_stats; + struct rate_ctr_group *conn_stats = conn_rtp->rate_ctr_group; + int i; + + if (all_stats == NULL || conn_stats == NULL) + return; + + OSMO_ASSERT(conn_stats->desc->num_ctr + 1 == all_stats->desc->num_ctr); + for (i = 0; i < conn_stats->desc->num_ctr; i++) + rate_ctr_add(&all_stats->ctr[i], conn_stats->ctr[i].current); + + rate_ctr_inc(&all_stats->ctr[RTP_NUM_CONNECTIONS]); +} + /*! free a connection by its ID. * \param[in] endp associated endpoint * \param[in] id identification number of the connection */ @@ -253,6 +271,7 @@ switch (conn->type) { case MGCP_CONN_TYPE_RTP: + aggregate_rtp_conn_stats(endp->tcfg, &conn->u.rtp); mgcp_rtp_conn_cleanup(&conn->u.rtp); break; default: diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index 3a0e4ea..767faa9 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -42,6 +42,7 @@ #include <osmocom/mgcp/mgcp_endp.h> #include <osmocom/mgcp/mgcp_sdp.h> #include <osmocom/mgcp/mgcp_codec.h> +#include <osmocom/mgcp/mgcp_conn.h> struct mgcp_request { char *name; @@ -103,6 +104,28 @@ .ctr_desc = mgcp_mdcx_ctr_desc }; +/* Must be kept in sync with rate_ctr_desc in mgcp_conn.c */ +static const struct rate_ctr_desc all_rtp_conn_rate_ctr_desc[] = { + [IN_STREAM_ERR_TSTMP_CTR] = {"all_rtp:err_tstmp_in", "Total inbound rtp-stream timestamp errors."}, + [OUT_STREAM_ERR_TSTMP_CTR] = {"all_rtp:err_tstmp_out", "Total outbound rtp-stream timestamp errors."}, + [RTP_PACKETS_RX_CTR] = {"all_rtp:packets_rx", "Total inbound rtp packets."}, + [RTP_OCTETS_RX_CTR] = {"all_rtp:octets_rx", "Total inbound rtp octets."}, + [RTP_PACKETS_TX_CTR] = {"all_rtp:packets_tx", "Total outbound rtp packets."}, + [RTP_OCTETS_TX_CTR] = {"all_rtp:octets_tx", "Total outbound rtp octets."}, + [RTP_DROPPED_PACKETS_CTR] = {"all_rtp:dropped", "Total dropped rtp packets."}, + + /* This last counter does not exist in mgcp_conn's per-connection stats, only here. */ + [RTP_NUM_CONNECTIONS] = {"all_rtp:num_closed_conns", "Total number of rtp connections closed."} +}; + +const static struct rate_ctr_group_desc all_rtp_conn_rate_ctr_group_desc = { + .group_name_prefix = "all_rtp_conn", + .group_description = "aggregated statistics for all rtp connections", + .class_id = 1, + .num_ctr = ARRAY_SIZE(all_rtp_conn_rate_ctr_desc), + .ctr_desc = all_rtp_conn_rate_ctr_desc +}; + static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *data); static struct msgb *handle_create_con(struct mgcp_parse_data *data); static struct msgb *handle_delete_con(struct mgcp_parse_data *data); @@ -1487,13 +1510,14 @@ return 0; } -static void alloc_mgcp_rate_counters(struct mgcp_trunk_config *trunk, void *ctx) +static void alloc_rate_counters(struct mgcp_trunk_config *trunk, void *ctx) { /* FIXME: Each new rate counter group requires a unique index. At the * moment we generate an index using a counter, but perhaps there is * a better way of assigning indices? */ static unsigned int crcx_rate_ctr_index = 0; static unsigned int mdcx_rate_ctr_index = 0; + static unsigned int all_rtp_conn_rate_ctr_index = 0; if (trunk->mgcp_crcx_ctr_group == NULL) { trunk->mgcp_crcx_ctr_group = rate_ctr_group_alloc(ctx, &mgcp_crcx_ctr_group_desc, crcx_rate_ctr_index); @@ -1507,6 +1531,13 @@ talloc_set_destructor(trunk->mgcp_mdcx_ctr_group, free_rate_counter_group); mdcx_rate_ctr_index++; } + if (trunk->all_rtp_conn_stats == NULL) { + trunk->all_rtp_conn_stats = rate_ctr_group_alloc(ctx, &all_rtp_conn_rate_ctr_group_desc, + all_rtp_conn_rate_ctr_index); + OSMO_ASSERT(trunk->all_rtp_conn_stats); + talloc_set_destructor(trunk->all_rtp_conn_stats, free_rate_counter_group); + all_rtp_conn_rate_ctr_index++; + } } /*! allocate configuration with default values. @@ -1546,7 +1577,7 @@ cfg->trunk.audio_send_name = 1; cfg->trunk.omit_rtcp = 0; mgcp_trunk_set_keepalive(&cfg->trunk, MGCP_KEEPALIVE_ONCE); - alloc_mgcp_rate_counters(&cfg->trunk, cfg); + alloc_rate_counters(&cfg->trunk, cfg); INIT_LLIST_HEAD(&cfg->trunks); @@ -1578,7 +1609,7 @@ trunk->vty_number_endpoints = 33; trunk->omit_rtcp = 0; mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE); - alloc_mgcp_rate_counters(trunk, trunk); + alloc_rate_counters(trunk, trunk); llist_add_tail(&trunk->entry, &cfg->trunks); return trunk; @@ -1625,7 +1656,7 @@ } tcfg->number_endpoints = tcfg->vty_number_endpoints; - alloc_mgcp_rate_counters(tcfg, tcfg->cfg); + alloc_rate_counters(tcfg, tcfg->cfg); return 0; } diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c index ed8aca5..e40d412 100644 --- a/src/libosmo-mgcp/mgcp_vty.c +++ b/src/libosmo-mgcp/mgcp_vty.c @@ -253,6 +253,10 @@ vty_out(vty, " %s:%s", cfg->mgcp_mdcx_ctr_group->desc->group_description, VTY_NEWLINE); vty_out_rate_ctr_group_fmt(vty, " %25n: %10c (%S/s %M/m %H/h %D/d) %d", cfg->mgcp_mdcx_ctr_group); } + if (show_stats && cfg->all_rtp_conn_stats) { + vty_out(vty, " %s:%s", cfg->all_rtp_conn_stats->desc->group_description, VTY_NEWLINE); + vty_out_rate_ctr_group_fmt(vty, " %25n: %10c (%S/s %M/m %H/h %D/d) %d", cfg->all_rtp_conn_stats); + } } #define SHOW_MGCP_STR "Display information about the MGCP Media Gateway\n" -- To view, visit https://gerrit.osmocom.org/11519 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-MessageType: newchange Gerrit-Change-Id: I80d36181600901ae2e0f321dc02b5d54ddc94139 Gerrit-Change-Number: 11519 Gerrit-PatchSet: 1 Gerrit-Owner: Stefan Sperling <ssperl...@sysmocom.de>