pespin has uploaded this change for review.

View Change

stats: Introduce stats sgsn.iu_peers.{total,active}

Change-Id: I51b5227d92027f1251dc4debbbf59737e7c1a9ba
---
M include/osmocom/sgsn/sgsn.h
M src/sgsn/iu_rnc.c
M src/sgsn/iu_rnc_fsm.c
M src/sgsn/sgsn.c
4 files changed, 53 insertions(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/90/40990/1
diff --git a/include/osmocom/sgsn/sgsn.h b/include/osmocom/sgsn/sgsn.h
index 8fc97b0..8524dd7 100644
--- a/include/osmocom/sgsn/sgsn.h
+++ b/include/osmocom/sgsn/sgsn.h
@@ -5,6 +5,7 @@

#include <osmocom/core/msgb.h>
#include <osmocom/core/select.h>
+#include <osmocom/core/stat_item.h>
#include <osmocom/crypt/gprs_cipher.h>
#include <osmocom/gprs/gprs_ns2.h>
#include <osmocom/gprs/gprs_bssgp.h>
@@ -159,6 +160,7 @@
struct sgsn_ra_global *routing_area;

struct rate_ctr_group *rate_ctrs;
+ struct osmo_stat_item_group *statg;

struct llist_head apn_list; /* list of struct sgsn_apn_ctx */
struct llist_head ggsn_list; /* list of struct sgsn_ggsn_ctx */
@@ -184,6 +186,21 @@
extern struct sgsn_instance *sgsn;
extern void *tall_sgsn_ctx;

+enum {
+ SGSN_STAT_IU_PEERS_TOTAL,
+ SGSN_STAT_IU_PEERS_ACTIVE,
+};
+static inline void sgsn_stat_inc(unsigned int idx, int32_t value)
+{
+ osmo_stat_item_inc(osmo_stat_item_group_get_item(sgsn->statg, idx), value);
+}
+
+static inline void sgsn_stat_dec(unsigned int idx, int32_t value)
+{
+ osmo_stat_item_dec(osmo_stat_item_group_get_item(sgsn->statg, idx), value);
+}
+
+
/*
* ctrl interface related work (sgsn_ctrl.c)
*/
diff --git a/src/sgsn/iu_rnc.c b/src/sgsn/iu_rnc.c
index abe6f61..38cddb5 100644
--- a/src/sgsn/iu_rnc.c
+++ b/src/sgsn/iu_rnc.c
@@ -76,6 +76,7 @@
osmo_rnc_id_name(rnc_id), addr_str);

llist_add(&rnc->entry, &sgsn->rnc_list);
+ sgsn_stat_inc(SGSN_STAT_IU_PEERS_TOTAL, 1);

LOGP(DRANAP, LOGL_NOTICE, "New RNC %s at %s\n",
osmo_rnc_id_name(&rnc->rnc_id), osmo_sccp_addr_dump(rnc_sccp_addr));
diff --git a/src/sgsn/iu_rnc_fsm.c b/src/sgsn/iu_rnc_fsm.c
index 4085586..6f610b4 100644
--- a/src/sgsn/iu_rnc_fsm.c
+++ b/src/sgsn/iu_rnc_fsm.c
@@ -216,6 +216,12 @@
}
}

+static void iu_rnc_st_ready_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
+{
+ if (prev_state != IU_RNC_ST_READY)
+ sgsn_stat_inc(SGSN_STAT_IU_PEERS_ACTIVE, 1);
+}
+
static void iu_rnc_st_ready(struct osmo_fsm_inst *fi, uint32_t event, void *data)
{
struct ranap_iu_rnc *rnc = fi->priv;
@@ -261,6 +267,12 @@
}
}

+static void iu_rnc_st_ready_onleave(struct osmo_fsm_inst *fi, uint32_t next_state)
+{
+ if (next_state != IU_RNC_ST_READY)
+ sgsn_stat_dec(SGSN_STAT_IU_PEERS_ACTIVE, 1);
+}
+
static int iu_rnc_fsm_timer_cb(struct osmo_fsm_inst *fi)
{
struct ranap_iu_rnc *rnc = fi->priv;
@@ -273,6 +285,10 @@
struct ranap_iu_rnc *rnc = fi->priv;

iu_rnc_discard_all_ue_ctx(rnc);
+
+ if (rnc->fi->state == IU_RNC_ST_READY)
+ sgsn_stat_dec(SGSN_STAT_IU_PEERS_ACTIVE, 1);
+ sgsn_stat_dec(SGSN_STAT_IU_PEERS_TOTAL, 1);
}

static const struct osmo_fsm_state iu_rnc_fsm_states[] = {
@@ -314,6 +330,8 @@
[IU_RNC_ST_READY] = {
.name = "READY",
.action = iu_rnc_st_ready,
+ .onenter = iu_rnc_st_ready_onenter,
+ .onleave = iu_rnc_st_ready_onleave,
.in_event_mask = 0
| S(IU_RNC_EV_RX_RESET)
| S(IU_RNC_EV_MSG_UP_CO_INITIAL)
diff --git a/src/sgsn/sgsn.c b/src/sgsn/sgsn.c
index 1b02f76..fe52e6c 100644
--- a/src/sgsn/sgsn.c
+++ b/src/sgsn/sgsn.c
@@ -103,6 +103,20 @@
sgsn_ctr_description,
};

+
+static const struct osmo_stat_item_desc sgsn_stat_item_description[] = {
+ [SGSN_STAT_IU_PEERS_TOTAL] = { "iu_peers:total", "Total Iu peers (RNC, HNBGW) seen since startup", OSMO_STAT_ITEM_NO_UNIT, 4, 0},
+ [SGSN_STAT_IU_PEERS_ACTIVE] = { "iu_peers:active", "Currently active Iu peers (RANAP ready)", OSMO_STAT_ITEM_NO_UNIT, 4, 0},
+};
+
+static const struct osmo_stat_item_group_desc sgsn_statg_desc = {
+ "sgsn",
+ "serving GPRS support node statistics",
+ OSMO_STATS_CLASS_GLOBAL,
+ ARRAY_SIZE(sgsn_stat_item_description),
+ sgsn_stat_item_description,
+};
+
static void sgsn_llme_cleanup_free(struct gprs_llc_llme *llme)
{
struct sgsn_mm_ctx *mmctx = NULL;
@@ -161,6 +175,7 @@
#endif /* #if BUILD_IU */
osmo_timer_del(&sgi->llme_timer);
rate_ctr_group_free(sgi->rate_ctrs);
+ osmo_stat_item_group_free(sgi->statg);
return 0;
}

@@ -185,6 +200,8 @@

inst->rate_ctrs = rate_ctr_group_alloc(inst, &sgsn_ctrg_desc, 0);
OSMO_ASSERT(inst->rate_ctrs);
+ inst->statg = osmo_stat_item_group_alloc(inst, &sgsn_statg_desc, 0);
+ OSMO_ASSERT(inst->statg);

INIT_LLIST_HEAD(&inst->apn_list);
INIT_LLIST_HEAD(&inst->ggsn_list);

To view, visit change 40990. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: I51b5227d92027f1251dc4debbbf59737e7c1a9ba
Gerrit-Change-Number: 40990
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>