add stat_items for BTS and TRX connection stati

So far we have stat items per BTS. Add stat items summing overall BTS
status.

Add stat items:
- num_bts:oml_connected
- num_bts:all_trx_rsl_connected
- num_bts:total
- num_trx:rsl_connected
- num_trx:total

Related: SYS#5542
Related: Ic1b35b7406547f92818afe399a2383d154576409 (osmo-ttcn3-hacks)
Change-Id: I2057a798e681a169cc03243a09b3d6449734c010
This commit is contained in:
Neels Hofmeyr 2021-08-29 13:31:05 +02:00
parent 3da59936be
commit 08de290aa8
4 changed files with 80 additions and 1 deletions

View File

@ -21,6 +21,7 @@
#include <osmocom/core/rate_ctr.h>
struct osmo_stat_item_group_desc;
struct gsm_network;
/* OsmoBSC rate_ctr indexes */
enum {
@ -87,7 +88,11 @@ extern const struct rate_ctr_group_desc bsc_ctrg_desc;
/* OsmoBSC stat_item indexes */
enum {
BSC_STAT_NUM_BTS_OML_CONNECTED,
BSC_STAT_NUM_BTS_ALL_TRX_RSL_CONNECTED,
BSC_STAT_NUM_BTS_TOTAL,
BSC_STAT_NUM_TRX_RSL_CONNECTED,
BSC_STAT_NUM_TRX_TOTAL,
BSC_STAT_NUM_MSC_CONNECTED,
BSC_STAT_NUM_MSC_TOTAL,
};
@ -98,3 +103,5 @@ enum {
#define BTS_STAT_IDX_UNKNOWN (UINT16_MAX + 1)
extern const struct osmo_stat_item_group_desc bsc_statg_desc;
void bsc_update_connection_stats(struct gsm_network *net);

View File

@ -23,6 +23,9 @@
#include <osmocom/core/stats.h>
#include <osmocom/core/stat_item.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/bts.h>
const struct rate_ctr_desc bsc_ctr_description[] = {
[BSC_CTR_ASSIGNMENT_ATTEMPTED] = {"assignment:attempted", "Assignment attempts"},
[BSC_CTR_ASSIGNMENT_COMPLETED] = {"assignment:completed", "Assignment completed"},
@ -110,7 +113,11 @@ const struct rate_ctr_group_desc bsc_ctrg_desc = {
};
static const struct osmo_stat_item_desc bsc_stat_desc[] = {
[BSC_STAT_NUM_BTS_OML_CONNECTED] = { "num_bts:oml_connected", "Number of BTS for this BSC where OML is up", "", 16, 0 },
[BSC_STAT_NUM_BTS_ALL_TRX_RSL_CONNECTED] = { "num_bts:all_trx_rsl_connected", "Number of BTS for this BSC where RSL is up for all TRX", "", 16, 0 },
[BSC_STAT_NUM_BTS_TOTAL] = { "num_bts:total", "Number of configured BTS for this BSC", "", 16, 0 },
[BSC_STAT_NUM_TRX_RSL_CONNECTED] = { "num_trx:rsl_connected", "Number of TRX where RSL is up, total sum across all BTS", "", 16, 0 },
[BSC_STAT_NUM_TRX_TOTAL] = { "num_trx:total", "Number of configured TRX, total sum across all BTS", "", 1, 0 },
[BSC_STAT_NUM_MSC_CONNECTED] = { "num_msc:connected", "Number of actively connected MSCs", "", 16, 0 },
[BSC_STAT_NUM_MSC_TOTAL] = { "num_msc:total", "Number of configured MSCs, not necessarily connected", "", 1, 0 },
};
@ -122,3 +129,55 @@ const struct osmo_stat_item_group_desc bsc_statg_desc = {
.num_items = ARRAY_SIZE(bsc_stat_desc),
.item_desc = bsc_stat_desc,
};
/* Count all BTS and TRX OML and RSL stati and update stat items */
void bsc_update_connection_stats(struct gsm_network *net)
{
struct gsm_bts *bts;
struct gsm_bts_trx *trx;
/* Nr of configured BTS and total sum of configured TRX across all BTS */
int num_bts = 0;
int num_trx_total = 0;
/* Nr of BTS where OML is up */
int bts_oml_connected = 0;
/* Nr of TRX across all BTS where RSL is up */
int trx_rsl_connected_total = 0;
/* Nr of BTS that have all TRX RSL up */
int bts_rsl_all_trx_connected = 0;
llist_for_each_entry(bts, &net->bts_list, list) {
bool oml_connected = false;
int num_trx = 0;
int trx_rsl_connected = 0;
llist_for_each_entry(trx, &bts->trx_list, list) {
/* If any one trx is usable, it means OML for this BTS is connected */
if (trx_is_usable(trx))
oml_connected = true;
/* Count nr of TRX for this BTS */
num_trx++;
if (trx->ts[0].is_rsl_ready)
trx_rsl_connected++;
}
num_trx_total += num_trx;
trx_rsl_connected_total += trx_rsl_connected;
num_bts++;
if (oml_connected)
bts_oml_connected++;
if (trx_rsl_connected == num_trx)
bts_rsl_all_trx_connected++;
}
osmo_stat_item_set(osmo_stat_item_group_get_item(net->bsc_statg, BSC_STAT_NUM_BTS_OML_CONNECTED),
bts_oml_connected);
osmo_stat_item_set(osmo_stat_item_group_get_item(net->bsc_statg, BSC_STAT_NUM_BTS_ALL_TRX_RSL_CONNECTED),
bts_rsl_all_trx_connected);
osmo_stat_item_set(osmo_stat_item_group_get_item(net->bsc_statg, BSC_STAT_NUM_BTS_TOTAL), num_bts);
osmo_stat_item_set(osmo_stat_item_group_get_item(net->bsc_statg, BSC_STAT_NUM_TRX_RSL_CONNECTED),
trx_rsl_connected_total);
osmo_stat_item_set(osmo_stat_item_group_get_item(net->bsc_statg, BSC_STAT_NUM_TRX_TOTAL), num_trx_total);
}

View File

@ -123,7 +123,6 @@ DEFUN_ATTR(cfg_bts,
/* allocate a new one */
bts = bsc_bts_alloc_register(gsmnet, GSM_BTS_TYPE_UNKNOWN,
HARDCODED_BSIC);
osmo_stat_item_inc(osmo_stat_item_group_get_item(gsmnet->bsc_statg, BSC_STAT_NUM_BTS_TOTAL), 1);
} else
bts = gsm_bts_num(gsmnet, bts_nr);

View File

@ -380,6 +380,18 @@ static void all_ts_dispatch_event(struct gsm_bts_trx *trx, uint32_t event)
}
}
struct osmo_timer_list update_connection_stats_timer;
/* Periodically call bsc_update_connection_stats() to keep stat items updated.
* It would be nicer to trigger this only when OML or RSL state is seen to flip. I tried hard to find all code paths
* that should call this and failed to get accurate results; this trivial timer covers all of them. */
static void update_connection_stats_cb(void *data)
{
bsc_update_connection_stats(bsc_gsmnet);
osmo_timer_setup(&update_connection_stats_timer, update_connection_stats_cb, NULL);
osmo_timer_schedule(&update_connection_stats_timer, 1, 0);
}
/* Callback function to be called every time we receive a signal from INPUT */
static int inp_sig_cb(unsigned int subsys, unsigned int signal,
void *handler_data, void *signal_data)
@ -1058,6 +1070,8 @@ int main(int argc, char **argv)
signal(SIGUSR2, &signal_handler);
osmo_init_ignore_signals();
update_connection_stats_cb(NULL);
if (daemonize) {
rc = osmo_daemonize();
if (rc < 0) {