Change in osmo-mgw[master]: mgcp_ratectr: add stats items to monitor trunk usage

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

dexter gerrit-no-reply at lists.osmocom.org
Wed Jul 14 15:49:27 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/24942 )


Change subject: mgcp_ratectr: add stats items to monitor trunk usage
......................................................................

mgcp_ratectr: add stats items to monitor trunk usage

We are currently counting events in rate counters, but there is
currently no way to get a sample of the current situation of the trunk
usage. In particular how many endpoints are currently in use.

Change-Id: Ib7b654168dc3512f55e45cc4755dc1f6f423d023
Related: SYS#5535
---
M include/osmocom/mgcp/mgcp_ratectr.h
M include/osmocom/mgcp/mgcp_trunk.h
M src/libosmo-mgcp/mgcp_endp.c
M src/libosmo-mgcp/mgcp_ratectr.c
M src/libosmo-mgcp/mgcp_trunk.c
5 files changed, 87 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/42/24942/1

diff --git a/include/osmocom/mgcp/mgcp_ratectr.h b/include/osmocom/mgcp/mgcp_ratectr.h
index 78c687b..70c3e6c 100644
--- a/include/osmocom/mgcp/mgcp_ratectr.h
+++ b/include/osmocom/mgcp/mgcp_ratectr.h
@@ -95,3 +95,17 @@
 
 int mgcp_ratectr_global_alloc(struct mgcp_config *cfg);
 int mgcp_ratectr_trunk_alloc(struct mgcp_trunk *trunk);
+
+/* Trunk-global common stat items */
+enum {
+	TRUNK_STAT_ENDPOINTS_TOTAL,
+	TRUNK_STAT_ENDPOINTS_USED,
+};
+
+struct mgcp_stat_trunk {
+	/* Stat item group which contains general status values of the trunk. */
+	struct osmo_stat_item_group *common;
+};
+
+int mgcp_stat_trunk_alloc(struct mgcp_trunk *trunk);
+void mgcp_stat_trunk_update(struct mgcp_trunk *trunk);
diff --git a/include/osmocom/mgcp/mgcp_trunk.h b/include/osmocom/mgcp/mgcp_trunk.h
index 326b16a..c0e06cb 100644
--- a/include/osmocom/mgcp/mgcp_trunk.h
+++ b/include/osmocom/mgcp/mgcp_trunk.h
@@ -52,8 +52,9 @@
 	unsigned int number_endpoints;
 	struct mgcp_endpoint **endpoints;
 
-	/* global rate counters to measure the trunks overall performance and health */
+	/* rate counters and stat items to measure the trunks overall performance and health */
 	struct mgcp_ratectr_trunk ratectr;
+	struct mgcp_stat_trunk stats;
 
 	union {
 		/* Virtual trunk specific */
diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c
index ddfd6cf..95709a5 100644
--- a/src/libosmo-mgcp/mgcp_endp.c
+++ b/src/libosmo-mgcp/mgcp_endp.c
@@ -133,6 +133,9 @@
 
 	if (endp->trunk->trunk_type == MGCP_TRUNK_E1)
 		mgcp_e1_endp_release(endp);
+
+	/* Make sure trunk related stats items are updated */
+	mgcp_stat_trunk_update(endp->trunk);
 }
 
 /* Check if the endpoint name contains the prefix (e.g. "rtpbridge/" or
@@ -653,6 +656,9 @@
 		OSMO_ASSERT(false);
 	}
 
+	/* Make sure trunk related stats items are updated */
+	mgcp_stat_trunk_update(endp->trunk);
+
 	/* Make sure the endpoint is released when claiming the endpoint fails. */
 	if (rc < 0)
 		mgcp_endp_release(endp);
diff --git a/src/libosmo-mgcp/mgcp_ratectr.c b/src/libosmo-mgcp/mgcp_ratectr.c
index af1526a..fdecc7c 100644
--- a/src/libosmo-mgcp/mgcp_ratectr.c
+++ b/src/libosmo-mgcp/mgcp_ratectr.c
@@ -24,8 +24,11 @@
 
 #include <errno.h>
 #include <osmocom/core/stats.h>
+#include <osmocom/core/stat_item.h>
 #include <osmocom/mgcp/mgcp_conn.h>
 #include <osmocom/mgcp/mgcp_trunk.h>
+#include <osmocom/mgcp/mgcp_protocol.h>
+#include <osmocom/mgcp/mgcp_endp.h>
 #include <osmocom/mgcp/mgcp_ratectr.h>
 
 static const struct rate_ctr_desc mgcp_general_ctr_desc[] = {
@@ -248,3 +251,62 @@
 	}
 	return 0;
 }
+
+const struct osmo_stat_item_desc trunk_stat_desc[] = {
+	[TRUNK_STAT_ENDPOINTS_TOTAL] = { "endpoints:total",
+					"Number of endpoints that exist on the trunk",
+					"", 60, 0 },
+	[TRUNK_STAT_ENDPOINTS_USED] = { "endpoints:used",
+				       "Number of endpoints in use",
+				       "", 60, 0 },
+};
+
+const struct osmo_stat_item_group_desc trunk_statg_desc = {
+	.group_name_prefix = "trunk",
+	.group_description = "mgw trunk",
+	.class_id = OSMO_STATS_CLASS_GLOBAL,
+	.num_items = ARRAY_SIZE(trunk_stat_desc),
+	.item_desc = trunk_stat_desc,
+};
+
+/*! allocate trunk specific stat items
+ *  (called once on trunk initialization).
+ *  \param[in] trunk for which the stat items are allocated.
+ *  \returns 0 on success, -EINVAL on failure. */
+int mgcp_stat_trunk_alloc(struct mgcp_trunk *trunk)
+{
+	struct mgcp_stat_trunk *stats = &trunk->stats;
+	static unsigned int common_stat_index = 0;
+	char stat_name[256];
+
+	stats->common = osmo_stat_item_group_alloc(trunk, &trunk_statg_desc, common_stat_index);
+	if (!stats->common)
+		return -EINVAL;
+	snprintf(stat_name, sizeof(stat_name), "%s-%d:common", mgcp_trunk_type_strs_str(trunk->trunk_type),
+		 trunk->trunk_nr);
+	osmo_stat_item_group_set_name(stats->common, stat_name);
+	common_stat_index++;
+
+	return 0;
+}
+
+
+/*! update trunk specific stat items for a given trunk
+ *  (called after every request that might change the trunk state).
+ *  \param[in] trunk to update.
+ *  \returns 0 on success, -EINVAL on failure. */
+void mgcp_stat_trunk_update(struct mgcp_trunk *trunk)
+{
+	struct mgcp_stat_trunk *stats = &trunk->stats;
+	unsigned int endpoints_in_use = 0;
+	unsigned int i;
+
+	osmo_stat_item_set(osmo_stat_item_group_get_item(stats->common, TRUNK_STAT_ENDPOINTS_TOTAL),
+			   trunk->number_endpoints);
+
+	for (i = 0; i < trunk->number_endpoints; i++) {
+		if (trunk->endpoints[i]->callid)
+			endpoints_in_use++;
+	}
+	osmo_stat_item_set(osmo_stat_item_group_get_item(stats->common, TRUNK_STAT_ENDPOINTS_USED), endpoints_in_use);
+}
diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c
index 08f99b3..b6d93a9 100644
--- a/src/libosmo-mgcp/mgcp_trunk.c
+++ b/src/libosmo-mgcp/mgcp_trunk.c
@@ -64,6 +64,7 @@
 	llist_add_tail(&trunk->entry, &cfg->trunks);
 
 	mgcp_ratectr_trunk_alloc(trunk);
+	mgcp_stat_trunk_alloc(trunk);
 
 	return trunk;
 }
@@ -128,6 +129,8 @@
 	/* make the endpoints we just created available to the MGW code */
 	trunk->number_endpoints = number_endpoints;
 
+	/* inital update of the stats items */
+	mgcp_stat_trunk_update(trunk);
 	return 0;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/24942
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: Ib7b654168dc3512f55e45cc4755dc1f6f423d023
Gerrit-Change-Number: 24942
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210714/1c18b2fb/attachment.htm>


More information about the gerrit-log mailing list