Change in osmo-bsc[master]: stats: Add a stats gauge for the MSC links count.

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/.

laforge gerrit-no-reply at lists.osmocom.org
Sat May 9 15:58:19 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/18092 )

Change subject: stats: Add a stats gauge for the MSC links count.
......................................................................

stats: Add a stats gauge for the MSC links count.

Change-Id: Ibe4b29056ba704a27b925cfdba49f343ee34f428
---
M include/osmocom/bsc/bsc_msc_data.h
M src/osmo-bsc/a_reset.c
M src/osmo-bsc/osmo_bsc_msc.c
3 files changed, 78 insertions(+), 6 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve



diff --git a/include/osmocom/bsc/bsc_msc_data.h b/include/osmocom/bsc/bsc_msc_data.h
index b9df4ba..7d797eb 100644
--- a/include/osmocom/bsc/bsc_msc_data.h
+++ b/include/osmocom/bsc/bsc_msc_data.h
@@ -56,6 +56,12 @@
 	MSC_CON_TYPE_LOCAL,
 };
 
+/* Constants for the MSC stats */
+enum {
+	MSC_STAT_MSC_LINKS_ACTIVE,
+	MSC_STAT_MSC_LINKS_TOTAL,
+};
+
 /*! /brief Information on a remote MSC for libbsc.
  */
 struct bsc_msc_data {
@@ -99,6 +105,10 @@
 
 	char *acc_lst_name;
 
+	/* structures for keeping rate counters and gauge stats */
+	struct rate_ctr_group *msc_ctrs;
+	struct osmo_stat_item_group *msc_statg;
+
 	/* Sigtran connection data */
 	struct {
 		uint32_t cs7_instance;
diff --git a/src/osmo-bsc/a_reset.c b/src/osmo-bsc/a_reset.c
index 3f51278..63273e9 100644
--- a/src/osmo-bsc/a_reset.c
+++ b/src/osmo-bsc/a_reset.c
@@ -66,18 +66,28 @@
 	{0, NULL}
 };
 
-/* Disconnected state */
+/* Disconnected state event handler */
 static void fsm_disc_cb(struct osmo_fsm_inst *fi, uint32_t event, void *data)
 {
 	struct reset_ctx *reset_ctx = (struct reset_ctx *)fi->priv;
 	OSMO_ASSERT(reset_ctx);
-	LOGPFSML(fi, LOGL_NOTICE, "SIGTRAN connection succeeded.\n");
 
 	reset_ctx->conn_loss_counter = 0;
 	osmo_fsm_inst_state_chg(fi, ST_CONN, 0, 0);
 }
 
-/* Connected state */
+/* Called when entering Disconnected state */
+static void fsm_disc_onenter_cb(struct osmo_fsm_inst *fi, uint32_t prev_state)
+{
+	struct reset_ctx *reset_ctx = (struct reset_ctx *)fi->priv;
+	struct bsc_msc_data *msc = reset_ctx->priv;
+
+	LOGPFSML(fi, LOGL_NOTICE, "SIGTRAN connection down, reconnecting...\n");
+	if (prev_state != ST_DISC)
+		osmo_stat_item_dec(msc->msc_statg->items[MSC_STAT_MSC_LINKS_ACTIVE], 1);
+}
+
+/* Connected state event handler */
 static void fsm_conn_cb(struct osmo_fsm_inst *fi, uint32_t event, void *data)
 {
 	struct reset_ctx *reset_ctx = (struct reset_ctx *)fi->priv;
@@ -85,10 +95,9 @@
 
 	switch (event) {
 	case EV_N_DISCONNECT:
-		if (reset_ctx->conn_loss_counter >= BAD_CONNECTION_THRESOLD) {
-			LOGPFSML(fi, LOGL_NOTICE, "SIGTRAN connection down, reconnecting...\n");
+		if (reset_ctx->conn_loss_counter >= BAD_CONNECTION_THRESOLD)
 			osmo_fsm_inst_state_chg(fi, ST_DISC, RESET_RESEND_INTERVAL, RESET_RESEND_TIMER_NO);
-		} else
+		else
 			reset_ctx->conn_loss_counter++;
 		break;
 	case EV_N_CONNECT:
@@ -97,6 +106,17 @@
 	}
 }
 
+/* Called when entering Connected state */
+static void fsm_conn_onenter_cb(struct osmo_fsm_inst *fi, uint32_t prev_state)
+{
+	struct reset_ctx *reset_ctx = (struct reset_ctx *)fi->priv;
+	struct bsc_msc_data *msc = reset_ctx->priv;
+
+	LOGPFSML(fi, LOGL_NOTICE, "SIGTRAN connection succeeded.\n");
+	if (prev_state != ST_CONN)
+		osmo_stat_item_inc(msc->msc_statg->items[MSC_STAT_MSC_LINKS_ACTIVE], 1);
+}
+
 /* Timer callback to retransmit the reset signal */
 static int fsm_reset_ack_timeout_cb(struct osmo_fsm_inst *fi)
 {
@@ -117,12 +137,14 @@
 		     .out_state_mask = (1 << ST_DISC) | (1 << ST_CONN),
 		     .name = "DISC",
 		     .action = fsm_disc_cb,
+		     .onenter = fsm_disc_onenter_cb,
 		     },
 	[ST_CONN] = {
 		     .in_event_mask = (1 << EV_N_DISCONNECT) | (1 << EV_N_CONNECT),
 		     .out_state_mask = (1 << ST_DISC) | (1 << ST_CONN),
 		     .name = "CONN",
 		     .action = fsm_conn_cb,
+		     .onenter = fsm_conn_onenter_cb,
 		     },
 };
 
@@ -161,6 +183,9 @@
 
 	/* Immediately (1ms) kick off reset sending mechanism */
 	osmo_fsm_inst_state_chg_ms(reset_fsm, ST_DISC, 1, RESET_RESEND_TIMER_NO);
+
+	/* Count the new MSC link */
+	osmo_stat_item_inc(msc->msc_statg->items[MSC_STAT_MSC_LINKS_TOTAL], 1);
 }
 
 /* Confirm that we successfully received a reset acknowledge message */
diff --git a/src/osmo-bsc/osmo_bsc_msc.c b/src/osmo-bsc/osmo_bsc_msc.c
index 24c8c6d..1704a73 100644
--- a/src/osmo-bsc/osmo_bsc_msc.c
+++ b/src/osmo-bsc/osmo_bsc_msc.c
@@ -43,6 +43,30 @@
 #include <netinet/tcp.h>
 #include <unistd.h>
 
+static const struct rate_ctr_desc msc_ctr_description[] = {
+};
+
+static const struct rate_ctr_group_desc msc_ctrg_desc = {
+	"msc",
+	"mobile switching center",
+	OSMO_STATS_CLASS_GLOBAL,
+	ARRAY_SIZE(msc_ctr_description),
+	msc_ctr_description,
+};
+
+static const struct osmo_stat_item_desc msc_stat_desc[] = {
+	{ "msc_links:active", "Number of active MSC links", "", 16, 0 },
+	{ "msc_links:total", "Number of configured MSC links", "", 16, 0 },
+};
+
+static const struct osmo_stat_item_group_desc msc_statg_desc = {
+	.group_name_prefix = "msc",
+	.group_description = "mobile switching center",
+	.class_id = OSMO_STATS_CLASS_GLOBAL,
+	.num_items = ARRAY_SIZE(msc_stat_desc),
+	.item_desc = msc_stat_desc,
+};
+
 int osmo_bsc_msc_init(struct bsc_msc_data *msc)
 {
 	struct gsm_network *net = msc->network;
@@ -91,6 +115,19 @@
 	if (!msc_data)
 		return NULL;
 
+	/* init statistics */
+	msc_data->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, nr);
+	if (!msc_data->msc_ctrs) {
+		talloc_free(msc_data);
+		return NULL;
+	}
+	msc_data->msc_statg = osmo_stat_item_group_alloc(net, &msc_statg_desc, nr);
+	if (!msc_data->msc_statg) {
+		rate_ctr_group_free(msc_data->msc_ctrs);
+		talloc_free(msc_data);
+		return NULL;
+	}
+
 	llist_add_tail(&msc_data->entry, &net->bsc_data->mscs);
 
 	/* Init back pointer */

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

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: Ibe4b29056ba704a27b925cfdba49f343ee34f428
Gerrit-Change-Number: 18092
Gerrit-PatchSet: 8
Gerrit-Owner: ipse <Alexander.Chemeris at gmail.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: ipse <Alexander.Chemeris at gmail.com>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200509/fc452725/attachment.htm>


More information about the gerrit-log mailing list