mgcp_ratectr: add stats items to monitor trunk usage

We are currently counting events in rate counters, but there is
currently no way to get a sample of the current situation of the trunk
usage. In particular how many endpoints are currently in use.

This is a corrected version of:
Ib7b654168dc3512f55e45cc4755dc1f6f423d023

Change-Id: I6d3a74f6087512130d85002348787bffc672de81
Related: SYS#5201
diff --git a/src/libosmo-mgcp/mgcp_trunk.c b/src/libosmo-mgcp/mgcp_trunk.c
index 73de972..a97ad39 100644
--- a/src/libosmo-mgcp/mgcp_trunk.c
+++ b/src/libosmo-mgcp/mgcp_trunk.c
@@ -27,6 +27,7 @@
 #include <osmocom/mgcp/mgcp_trunk.h>
 #include <osmocom/mgcp/mgcp_e1.h>
 #include <osmocom/abis/e1_input.h>
+#include <osmocom/core/stat_item.h>
 
 const struct value_string mgcp_trunk_type_strs[] = {
 	{ MGCP_TRUNK_VIRTUAL,		"virtual" },
@@ -64,6 +65,7 @@
 	llist_add_tail(&trunk->entry, &cfg->trunks);
 
 	mgcp_ratectr_trunk_alloc(trunk);
+	mgcp_stat_trunk_alloc(trunk);
 
 	return trunk;
 }
@@ -127,7 +129,8 @@
 
 	/* make the endpoints we just created available to the MGW code */
 	trunk->number_endpoints = number_endpoints;
-
+	osmo_stat_item_set(osmo_stat_item_group_get_item(trunk->stats.common, TRUNK_STAT_ENDPOINTS_TOTAL),
+			   trunk->number_endpoints);
 	return 0;
 }