forked from acouzens/open5gs
AMF metrics initial support (#1585)
This commit is contained in:
parent
28e40a0f1b
commit
816575dc8d
|
@ -358,3 +358,17 @@ usrsctp:
|
|||
# handover:
|
||||
# duration: 500
|
||||
time:
|
||||
|
||||
#
|
||||
# metrics:
|
||||
#
|
||||
# <Metrics Server>
|
||||
#
|
||||
# o Metrics Server(http://<any address>:9090)
|
||||
# metrics:
|
||||
# addr: 0.0.0.0
|
||||
# port: 9090
|
||||
#
|
||||
metrics:
|
||||
addr: 0.0.0.0
|
||||
port: 9090
|
||||
|
|
|
@ -872,6 +872,7 @@ amf_gnb_t *amf_gnb_add(ogs_sock_t *sock, ogs_sockaddr_t *addr)
|
|||
ogs_fsm_init(&gnb->sm, &e);
|
||||
|
||||
ogs_list_add(&self.gnb_list, gnb);
|
||||
amf_metrics_inst_global_inc(AMF_METR_GLOB_GAUGE_GNB);
|
||||
|
||||
ogs_info("[Added] Number of gNBs is now %d",
|
||||
ogs_list_count(&self.gnb_list));
|
||||
|
@ -900,7 +901,7 @@ void amf_gnb_remove(amf_gnb_t *gnb)
|
|||
ogs_sctp_flush_and_destroy(&gnb->sctp);
|
||||
|
||||
ogs_pool_free(&amf_gnb_pool, gnb);
|
||||
|
||||
amf_metrics_inst_global_dec(AMF_METR_GLOB_GAUGE_GNB);
|
||||
ogs_info("[Removed] Number of gNBs is now %d",
|
||||
ogs_list_count(&self.gnb_list));
|
||||
}
|
||||
|
@ -2068,24 +2069,28 @@ void amf_clear_subscribed_info(amf_ue_t *amf_ue)
|
|||
|
||||
static void stats_add_ran_ue(void)
|
||||
{
|
||||
amf_metrics_inst_global_inc(AMF_METR_GLOB_GAUGE_RAN_UE);
|
||||
num_of_ran_ue = num_of_ran_ue + 1;
|
||||
ogs_info("[Added] Number of gNB-UEs is now %d", num_of_ran_ue);
|
||||
}
|
||||
|
||||
static void stats_remove_ran_ue(void)
|
||||
{
|
||||
amf_metrics_inst_global_dec(AMF_METR_GLOB_GAUGE_RAN_UE);
|
||||
num_of_ran_ue = num_of_ran_ue - 1;
|
||||
ogs_info("[Removed] Number of gNB-UEs is now %d", num_of_ran_ue);
|
||||
}
|
||||
|
||||
static void stats_add_amf_session(void)
|
||||
{
|
||||
amf_metrics_inst_global_inc(AMF_METR_GLOB_GAUGE_AMF_SESS);
|
||||
num_of_amf_sess = num_of_amf_sess + 1;
|
||||
ogs_info("[Added] Number of AMF-Sessions is now %d", num_of_amf_sess);
|
||||
}
|
||||
|
||||
static void stats_remove_amf_session(void)
|
||||
{
|
||||
amf_metrics_inst_global_dec(AMF_METR_GLOB_GAUGE_AMF_SESS);
|
||||
num_of_amf_sess = num_of_amf_sess - 1;
|
||||
ogs_info("[Removed] Number of AMF-Sessions is now %d", num_of_amf_sess);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "amf-sm.h"
|
||||
#include "timer.h"
|
||||
#include "metrics.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "sbi-path.h"
|
||||
#include "ngap-path.h"
|
||||
#include "metrics.h"
|
||||
|
||||
static ogs_thread_t *thread;
|
||||
static void amf_main(void *data);
|
||||
|
@ -28,6 +29,7 @@ int amf_initialize()
|
|||
{
|
||||
int rv;
|
||||
|
||||
ogs_metrics_context_init();
|
||||
amf_context_init();
|
||||
amf_event_init();
|
||||
ogs_sbi_context_init();
|
||||
|
@ -35,12 +37,18 @@ int amf_initialize()
|
|||
rv = ogs_sbi_context_parse_config("amf", "nrf");
|
||||
if (rv != OGS_OK) return rv;
|
||||
|
||||
rv = ogs_metrics_context_parse_config();
|
||||
if (rv != OGS_OK) return rv;
|
||||
|
||||
rv = amf_context_parse_config();
|
||||
if (rv != OGS_OK) return rv;
|
||||
|
||||
rv = amf_m_tmsi_pool_generate();
|
||||
if (rv != OGS_OK) return rv;
|
||||
|
||||
rv = amf_metrics_open();
|
||||
if (rv != 0) return OGS_ERROR;
|
||||
|
||||
rv = ogs_log_config_domain(
|
||||
ogs_app()->logger.domain, ogs_app()->logger.level);
|
||||
if (rv != OGS_OK) return rv;
|
||||
|
@ -91,9 +99,11 @@ void amf_terminate(void)
|
|||
|
||||
ngap_close();
|
||||
amf_sbi_close();
|
||||
amf_metrics_close();
|
||||
|
||||
amf_context_final();
|
||||
ogs_sbi_context_final();
|
||||
ogs_metrics_context_final();
|
||||
|
||||
amf_event_final(); /* Destroy event */
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
libamf_sources = files('''
|
||||
metrics.h
|
||||
|
||||
context.c
|
||||
event.c
|
||||
timer.c
|
||||
|
@ -59,11 +61,13 @@ libamf_sources = files('''
|
|||
amf-sm.c
|
||||
|
||||
init.c
|
||||
metrics.c
|
||||
'''.split())
|
||||
|
||||
libamf = static_library('amf',
|
||||
sources : libamf_sources,
|
||||
dependencies : [libapp_dep,
|
||||
libmetrics_dep,
|
||||
libsctp_dep,
|
||||
libngap_dep,
|
||||
libnas_5gs_dep,
|
||||
|
@ -73,6 +77,7 @@ libamf = static_library('amf',
|
|||
libamf_dep = declare_dependency(
|
||||
link_with : libamf,
|
||||
dependencies : [libapp_dep,
|
||||
libmetrics_dep,
|
||||
libsctp_dep,
|
||||
libngap_dep,
|
||||
libnas_5gs_dep,
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
#include "ogs-app.h"
|
||||
#include "context.h"
|
||||
|
||||
#include "metrics.h"
|
||||
|
||||
typedef struct amf_metrics_spec_def_s {
|
||||
unsigned int type;
|
||||
const char *name;
|
||||
const char *description;
|
||||
int initial_val;
|
||||
unsigned int num_labels;
|
||||
const char **labels;
|
||||
} amf_metrics_spec_def_t;
|
||||
|
||||
ogs_metrics_spec_t *amf_metrics_spec_global[_AMF_METR_GLOB_MAX];
|
||||
ogs_metrics_inst_t *amf_metrics_inst_global[_AMF_METR_GLOB_MAX];
|
||||
amf_metrics_spec_def_t amf_metrics_spec_def_global[_AMF_METR_GLOB_MAX] = {
|
||||
[AMF_METR_GLOB_GAUGE_RAN_UE] = {
|
||||
.type = OGS_METRICS_METRIC_TYPE_GAUGE,
|
||||
.name = "ran_ue",
|
||||
.description = "RAN UEs",
|
||||
.initial_val = 0,
|
||||
.num_labels = 0,
|
||||
.labels = NULL,
|
||||
},
|
||||
[AMF_METR_GLOB_GAUGE_AMF_SESS] = {
|
||||
.type = OGS_METRICS_METRIC_TYPE_GAUGE,
|
||||
.name = "amf_session",
|
||||
.description = "AMF Sessions",
|
||||
.initial_val = 0,
|
||||
.num_labels = 0,
|
||||
.labels = NULL,
|
||||
},
|
||||
[AMF_METR_GLOB_GAUGE_GNB] = {
|
||||
.type = OGS_METRICS_METRIC_TYPE_GAUGE,
|
||||
.name = "gnb",
|
||||
.description = "gNodeBs",
|
||||
.initial_val = 0,
|
||||
.num_labels = 0,
|
||||
.labels = NULL,
|
||||
},
|
||||
};
|
||||
|
||||
static int amf_metrics_init_spec(ogs_metrics_context_t *ctx,
|
||||
ogs_metrics_spec_t **dst, amf_metrics_spec_def_t *src, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
dst[i] = ogs_metrics_spec_new(ctx, src[i].type,
|
||||
src[i].name, src[i].description,
|
||||
src[i].initial_val, src[i].num_labels, src[i].labels);
|
||||
}
|
||||
return OGS_OK;
|
||||
}
|
||||
|
||||
|
||||
static int amf_metrics_init_inst_global(ogs_metrics_inst_t **inst, ogs_metrics_spec_t **specs, unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < len; i++)
|
||||
inst[i] = ogs_metrics_inst_new(specs[i], 0, NULL);
|
||||
return OGS_OK;
|
||||
}
|
||||
|
||||
int amf_metrics_open(void)
|
||||
{
|
||||
ogs_metrics_context_t *ctx = ogs_metrics_self();
|
||||
ogs_metrics_context_open(ctx);
|
||||
|
||||
amf_metrics_init_spec(ctx, amf_metrics_spec_global, amf_metrics_spec_def_global,
|
||||
_AMF_METR_GLOB_MAX);
|
||||
|
||||
amf_metrics_init_inst_global(amf_metrics_inst_global, amf_metrics_spec_global,
|
||||
_AMF_METR_GLOB_MAX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int amf_metrics_close(void)
|
||||
{
|
||||
ogs_metrics_context_t *ctx = ogs_metrics_self();
|
||||
ogs_metrics_context_close(ctx);
|
||||
return OGS_OK;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef AMF_METRICS_H
|
||||
#define AMF_METRICS_H
|
||||
|
||||
#include "ogs-metrics.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum amf_metric_type_global_s {
|
||||
AMF_METR_GLOB_GAUGE_RAN_UE,
|
||||
AMF_METR_GLOB_GAUGE_AMF_SESS,
|
||||
AMF_METR_GLOB_GAUGE_GNB,
|
||||
_AMF_METR_GLOB_MAX,
|
||||
} amf_metric_type_global_t;
|
||||
extern ogs_metrics_inst_t *amf_metrics_inst_global[_AMF_METR_GLOB_MAX];
|
||||
|
||||
static inline void amf_metrics_inst_global_set(amf_metric_type_global_t t, int val)
|
||||
{
|
||||
ogs_metrics_inst_set(amf_metrics_inst_global[t], val);
|
||||
}
|
||||
static inline void amf_metrics_inst_global_add(amf_metric_type_global_t t, int val)
|
||||
{
|
||||
ogs_metrics_inst_add(amf_metrics_inst_global[t], val);
|
||||
}
|
||||
static inline void amf_metrics_inst_global_inc(amf_metric_type_global_t t)
|
||||
{
|
||||
ogs_metrics_inst_inc(amf_metrics_inst_global[t]);
|
||||
}
|
||||
static inline void amf_metrics_inst_global_dec(amf_metric_type_global_t t)
|
||||
{
|
||||
ogs_metrics_inst_dec(amf_metrics_inst_global[t]);
|
||||
}
|
||||
|
||||
int amf_metrics_open(void);
|
||||
int amf_metrics_close(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AMF_METRICS_H */
|
Loading…
Reference in New Issue