keep per-BTS stat_items about RACH busy / RACH access percentage

Change-Id: I3ad0cc4866d6210181cbafbab876e8028ad27540
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 68c95e1..82bd238 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -1378,6 +1378,8 @@
 enum {
 	BTS_STAT_CHAN_LOAD_AVERAGE,
 	BTS_STAT_T3122,
+	BTS_STAT_RACH_BUSY,
+	BTS_STAT_RACH_ACCESS,
 };
 
 enum {
diff --git a/src/osmo-bsc/abis_rsl.c b/src/osmo-bsc/abis_rsl.c
index 39fae50..9db2115 100644
--- a/src/osmo-bsc/abis_rsl.c
+++ b/src/osmo-bsc/abis_rsl.c
@@ -1476,9 +1476,17 @@
 		break;
 	case RSL_IE_RACH_LOAD:
 		if (msg->data_len >= 7) {
+			int32_t busy_percent, access_percent;
+			/* build data for signal */
 			sd.rach_slot_count = rslh->data[2] << 8 | rslh->data[3];
 			sd.rach_busy_count = rslh->data[4] << 8 | rslh->data[5];
 			sd.rach_access_count = rslh->data[6] << 8 | rslh->data[7];
+			/* update stats group */
+			busy_percent = (int32_t) sd.rach_busy_count * 100 / (int32_t) sd.rach_slot_count;
+			access_percent = (int32_t) sd.rach_access_count * 100 / (int32_t) sd.rach_slot_count;
+			osmo_stat_item_set(sd.bts->bts_statg->items[BTS_STAT_RACH_BUSY], busy_percent);
+			osmo_stat_item_set(sd.bts->bts_statg->items[BTS_STAT_RACH_ACCESS], access_percent);
+			/* dispatch signal */
 			osmo_signal_dispatch(SS_CCCH, S_CCCH_RACH_LOAD, &sd);
 		}
 		break;
diff --git a/src/osmo-bsc/gsm_data.c b/src/osmo-bsc/gsm_data.c
index 88690a7..5942fba 100644
--- a/src/osmo-bsc/gsm_data.c
+++ b/src/osmo-bsc/gsm_data.c
@@ -380,6 +380,8 @@
 static const struct osmo_stat_item_desc bts_stat_desc[] = {
 	{ "chanloadavg", "Channel load average.", "%", 16, 0 },
 	{ "T3122", "T3122 IMMEDIATE ASSIGNMENT REJECT wait indicator.", "s", 16, GSM_T3122_DEFAULT },
+	{ "rach_busy", "RACH slots with signal above threshold", "%", 16, 0 },
+	{ "rach_access", "RACH slots with access bursts in them", "%", 16, 0 },
 };
 
 static const struct osmo_stat_item_group_desc bts_statg_desc = {