Introduce stats msc.ran_peers.{total,active}

osmo_stats_init() was already being called despite no stats were being
used.

Change-Id: Ib01576036f34ac7f21c5bce0155b50932eb9b72a
This commit is contained in:
Pau Espin Pedrol
2025-07-14 19:40:51 +02:00
parent 576b13fb19
commit 1416f6497f
4 changed files with 55 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ enum smlc_ctrl_node {
_LAST_CTRL_NODE_SMLC
};
/* rate_ctr */
enum {
SMLC_CTR_BSSMAP_LE_RX_UDT_RESET,
SMLC_CTR_BSSMAP_LE_RX_UDT_RESET_ACK,
@@ -58,3 +59,9 @@ enum {
SMLC_CTR_BSSMAP_LE_TX_DT1_PERFORM_LOCATION_RESPONSE,
SMLC_CTR_BSSMAP_LE_TX_DT1_BSSLAP_TA_REQUEST,
};
/* osmo_stat */
enum {
SMLC_STAT_LB_PEERS_TOTAL,
SMLC_STAT_LB_PEERS_ACTIVE,
};

View File

@@ -23,6 +23,7 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/fsm.h>
#include <osmocom/core/stat_item.h>
#include <osmocom/gsm/bssmap_le.h>
#include <osmocom/sigtran/sccp_helpers.h>
@@ -57,6 +58,7 @@ static struct lb_peer *lb_peer_alloc(struct sccp_lb_inst *sli, const struct osmo
fi->priv = lbp;
llist_add(&lbp->entry, &sli->lb_peers);
osmo_stat_item_inc(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_TOTAL), 1);
return lbp;
}
@@ -303,6 +305,12 @@ static void lb_peer_st_wait_rx_reset_ack(struct osmo_fsm_inst *fi, uint32_t even
}
}
static void lb_peer_st_ready_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
{
if (prev_state != LB_PEER_ST_READY)
osmo_stat_item_inc(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_ACTIVE), 1);
}
static void lb_peer_st_ready(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct lb_peer *lbp = fi->priv;
@@ -377,6 +385,12 @@ static void lb_peer_st_ready(struct osmo_fsm_inst *fi, uint32_t event, void *dat
}
}
static void lb_peer_st_ready_onleave(struct osmo_fsm_inst *fi, uint32_t next_state)
{
if (next_state != LB_PEER_ST_READY)
osmo_stat_item_dec(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_ACTIVE), 1);
}
static int lb_peer_fsm_timer_cb(struct osmo_fsm_inst *fi)
{
struct lb_peer *lbp = fi->priv;
@@ -384,10 +398,17 @@ static int lb_peer_fsm_timer_cb(struct osmo_fsm_inst *fi)
return 0;
}
/* struct lb_peer destructor: */
static void lb_peer_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause)
{
struct lb_peer *lbp = fi->priv;
lb_peer_discard_all_conns(lbp);
if (lbp->fi->state == LB_PEER_ST_READY)
osmo_stat_item_dec(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_ACTIVE), 1);
osmo_stat_item_dec(osmo_stat_item_group_get_item(g_smlc->statg, SMLC_STAT_LB_PEERS_TOTAL), 1);
llist_del(&lbp->entry);
}
@@ -446,6 +467,8 @@ static const struct osmo_fsm_state lb_peer_fsm_states[] = {
[LB_PEER_ST_READY] = {
.name = "READY",
.action = lb_peer_st_ready,
.onenter = lb_peer_st_ready_onenter,
.onleave = lb_peer_st_ready_onleave,
.in_event_mask = 0
| S(LB_PEER_EV_RX_RESET)
| S(LB_PEER_EV_MSG_UP_CO_INITIAL)

View File

@@ -54,6 +54,19 @@ static const struct rate_ctr_group_desc smlc_ctrg_desc = {
smlc_ctr_description,
};
static const struct osmo_stat_item_desc smlc_stat_item_description[] = {
[SMLC_STAT_LB_PEERS_TOTAL] = { "lb_peers.total", "Total Lb peers seen since startup", OSMO_STAT_ITEM_NO_UNIT, 4, 0},
[SMLC_STAT_LB_PEERS_ACTIVE] = { "lb_peers.active", "Currently active Lb peers", OSMO_STAT_ITEM_NO_UNIT, 4, 0},
};
static const struct osmo_stat_item_group_desc smlc_statg_desc = {
"smlc",
"serving mobile location center",
OSMO_STATS_CLASS_GLOBAL,
ARRAY_SIZE(smlc_stat_item_description),
smlc_stat_item_description,
};
struct smlc_state *smlc_state_alloc(void *ctx)
{
struct smlc_state *smlc = talloc_zero(ctx, struct smlc_state);
@@ -61,5 +74,14 @@ struct smlc_state *smlc_state_alloc(void *ctx)
INIT_LLIST_HEAD(&smlc->subscribers);
INIT_LLIST_HEAD(&smlc->cell_locations);
smlc->ctrs = rate_ctr_group_alloc(smlc, &smlc_ctrg_desc, 0);
smlc->statg = osmo_stat_item_group_alloc(smlc, &smlc_statg_desc, 0);
if (!smlc->statg)
goto ret_free;
return smlc;
ret_free:
rate_ctr_group_free(smlc->ctrs);
talloc_free(smlc);
return NULL;
}

View File

@@ -23,6 +23,8 @@
#include <osmocom/ctrl/control_vty.h>
#include <osmocom/vty/logging.h>
#include <osmocom/vty/misc.h>
#include <osmocom/vty/stats.h>
#include <osmocom/vty/vty.h>
#include <osmocom/sigtran/osmo_ss7.h>
#include <osmocom/sigtran/sccp_sap.h>
@@ -37,6 +39,7 @@ void smlc_vty_init(struct vty_app_info *vty_app_info)
osmo_talloc_vty_add_cmds();
ctrl_vty_init(vty_app_info->tall_ctx);
osmo_fsm_vty_add_cmds();
osmo_stats_vty_add_cmds();
osmo_ss7_vty_init_asp(vty_app_info->tall_ctx);
osmo_sccp_vty_init();