Initial metrics support based on Prometheus (#1571)
* Initial metrics support based on Prometheus
This commit introduces initial support for metrics in open5gs.
The metrics code is added as libogsmetrics (lib/metrics/), with a well
defined opaque API to manage different types of metrics, allowing for
different implementations for different technologies to scrap the
metrics (placed as lib/metrics/<impl>/. The implementation is right now
selected at build time, in order to be able to opt-out the related dependencies
for users not interested in the features. 2 implementations are already
provided in this commit to start with:
* void: Default implementation. Empty stubs, acts as a NOOP.
* prometheus: open5gs processes become Prometheus servers, offering
states through an http server to the Prometheus scrappers. Relies on
libprom (prometheus-client-ci [1] project) to track the metrics and format
them during export, and libmicrohttpd to make the export possible through
HTTP.
[1] https://github.com/digitalocean/prometheus-client-c
The prometheus-client-c is not well maintained nowadays in upstream, and
furthermore it uses a quite peculiar mixture of build systems (autolib
on the main dir, cmake for libprom in a subdir). This makes it difficult
to have it widely available in distros, and difficult to find it if it
is installed in the system. Hence, the best is to include it as a
meson subproject like we already do for freeDiameter. An open5gs fork is
requried in order to have an extra patch adding a top-level
CMakeList.txt in order to be able to includ eit from open5gs's meson
build. Furthermore, this allows adding bugfixes to the subproject if any
are found in the future.
* [SMF] Initial metrics support
* [SMF] Add metrics at gtp_node level
* docs: Add tutorial documenting metrics with Prometheus
2022-06-07 20:51:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
|
|
|
|
*
|
|
|
|
* This file is part of Open5GS.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(OGS_METRICS_INSIDE) && !defined(OGS_METRICS_COMPILATION)
|
|
|
|
#error "This header cannot be included directly."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef OGS_METRICS_CONTEXT_H
|
|
|
|
#define OGS_METRICS_CONTEXT_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-11-21 13:06:29 +00:00
|
|
|
typedef struct ogs_metrics_server_s ogs_metrics_server_t;
|
|
|
|
|
Initial metrics support based on Prometheus (#1571)
* Initial metrics support based on Prometheus
This commit introduces initial support for metrics in open5gs.
The metrics code is added as libogsmetrics (lib/metrics/), with a well
defined opaque API to manage different types of metrics, allowing for
different implementations for different technologies to scrap the
metrics (placed as lib/metrics/<impl>/. The implementation is right now
selected at build time, in order to be able to opt-out the related dependencies
for users not interested in the features. 2 implementations are already
provided in this commit to start with:
* void: Default implementation. Empty stubs, acts as a NOOP.
* prometheus: open5gs processes become Prometheus servers, offering
states through an http server to the Prometheus scrappers. Relies on
libprom (prometheus-client-ci [1] project) to track the metrics and format
them during export, and libmicrohttpd to make the export possible through
HTTP.
[1] https://github.com/digitalocean/prometheus-client-c
The prometheus-client-c is not well maintained nowadays in upstream, and
furthermore it uses a quite peculiar mixture of build systems (autolib
on the main dir, cmake for libprom in a subdir). This makes it difficult
to have it widely available in distros, and difficult to find it if it
is installed in the system. Hence, the best is to include it as a
meson subproject like we already do for freeDiameter. An open5gs fork is
requried in order to have an extra patch adding a top-level
CMakeList.txt in order to be able to includ eit from open5gs's meson
build. Furthermore, this allows adding bugfixes to the subproject if any
are found in the future.
* [SMF] Initial metrics support
* [SMF] Add metrics at gtp_node level
* docs: Add tutorial documenting metrics with Prometheus
2022-06-07 20:51:02 +00:00
|
|
|
typedef enum ogs_metrics_metric_type_s {
|
|
|
|
OGS_METRICS_METRIC_TYPE_COUNTER,
|
|
|
|
OGS_METRICS_METRIC_TYPE_GAUGE,
|
|
|
|
} ogs_metrics_metric_type_t;
|
|
|
|
|
|
|
|
typedef struct ogs_metrics_context_s ogs_metrics_context_t;
|
|
|
|
void ogs_metrics_context_init(void);
|
|
|
|
void ogs_metrics_context_open(ogs_metrics_context_t *ctx);
|
|
|
|
void ogs_metrics_context_close(ogs_metrics_context_t *ctx);
|
|
|
|
void ogs_metrics_context_final(void);
|
|
|
|
ogs_metrics_context_t *ogs_metrics_self(void);
|
2022-09-07 05:38:05 +00:00
|
|
|
int ogs_metrics_context_parse_config(const char *local);
|
Initial metrics support based on Prometheus (#1571)
* Initial metrics support based on Prometheus
This commit introduces initial support for metrics in open5gs.
The metrics code is added as libogsmetrics (lib/metrics/), with a well
defined opaque API to manage different types of metrics, allowing for
different implementations for different technologies to scrap the
metrics (placed as lib/metrics/<impl>/. The implementation is right now
selected at build time, in order to be able to opt-out the related dependencies
for users not interested in the features. 2 implementations are already
provided in this commit to start with:
* void: Default implementation. Empty stubs, acts as a NOOP.
* prometheus: open5gs processes become Prometheus servers, offering
states through an http server to the Prometheus scrappers. Relies on
libprom (prometheus-client-ci [1] project) to track the metrics and format
them during export, and libmicrohttpd to make the export possible through
HTTP.
[1] https://github.com/digitalocean/prometheus-client-c
The prometheus-client-c is not well maintained nowadays in upstream, and
furthermore it uses a quite peculiar mixture of build systems (autolib
on the main dir, cmake for libprom in a subdir). This makes it difficult
to have it widely available in distros, and difficult to find it if it
is installed in the system. Hence, the best is to include it as a
meson subproject like we already do for freeDiameter. An open5gs fork is
requried in order to have an extra patch adding a top-level
CMakeList.txt in order to be able to includ eit from open5gs's meson
build. Furthermore, this allows adding bugfixes to the subproject if any
are found in the future.
* [SMF] Initial metrics support
* [SMF] Add metrics at gtp_node level
* docs: Add tutorial documenting metrics with Prometheus
2022-06-07 20:51:02 +00:00
|
|
|
|
2022-11-21 13:06:29 +00:00
|
|
|
ogs_metrics_server_t *ogs_metrics_server_add(
|
|
|
|
ogs_sockaddr_t *addr, ogs_sockopt_t *option);
|
|
|
|
void ogs_metrics_server_remove(ogs_metrics_server_t *server);
|
|
|
|
void ogs_metrics_server_remove_all(void);
|
|
|
|
|
Initial metrics support based on Prometheus (#1571)
* Initial metrics support based on Prometheus
This commit introduces initial support for metrics in open5gs.
The metrics code is added as libogsmetrics (lib/metrics/), with a well
defined opaque API to manage different types of metrics, allowing for
different implementations for different technologies to scrap the
metrics (placed as lib/metrics/<impl>/. The implementation is right now
selected at build time, in order to be able to opt-out the related dependencies
for users not interested in the features. 2 implementations are already
provided in this commit to start with:
* void: Default implementation. Empty stubs, acts as a NOOP.
* prometheus: open5gs processes become Prometheus servers, offering
states through an http server to the Prometheus scrappers. Relies on
libprom (prometheus-client-ci [1] project) to track the metrics and format
them during export, and libmicrohttpd to make the export possible through
HTTP.
[1] https://github.com/digitalocean/prometheus-client-c
The prometheus-client-c is not well maintained nowadays in upstream, and
furthermore it uses a quite peculiar mixture of build systems (autolib
on the main dir, cmake for libprom in a subdir). This makes it difficult
to have it widely available in distros, and difficult to find it if it
is installed in the system. Hence, the best is to include it as a
meson subproject like we already do for freeDiameter. An open5gs fork is
requried in order to have an extra patch adding a top-level
CMakeList.txt in order to be able to includ eit from open5gs's meson
build. Furthermore, this allows adding bugfixes to the subproject if any
are found in the future.
* [SMF] Initial metrics support
* [SMF] Add metrics at gtp_node level
* docs: Add tutorial documenting metrics with Prometheus
2022-06-07 20:51:02 +00:00
|
|
|
typedef struct ogs_metrics_spec_s ogs_metrics_spec_t;
|
|
|
|
ogs_metrics_spec_t *ogs_metrics_spec_new(
|
|
|
|
ogs_metrics_context_t *ctx, ogs_metrics_metric_type_t type,
|
|
|
|
const char *name, const char *description,
|
|
|
|
int initial_val, unsigned int num_labels, const char **labels);
|
|
|
|
void ogs_metrics_spec_free(ogs_metrics_spec_t *spec);
|
|
|
|
|
|
|
|
typedef struct ogs_metrics_inst_s ogs_metrics_inst_t;
|
|
|
|
ogs_metrics_inst_t *ogs_metrics_inst_new(
|
|
|
|
ogs_metrics_spec_t *spec,
|
|
|
|
unsigned int num_labels, const char **label_values);
|
|
|
|
void ogs_metrics_inst_free(ogs_metrics_inst_t *inst);
|
|
|
|
void ogs_metrics_inst_set(ogs_metrics_inst_t *inst, int val);
|
|
|
|
void ogs_metrics_inst_reset(ogs_metrics_inst_t *inst);
|
|
|
|
void ogs_metrics_inst_add(ogs_metrics_inst_t *inst, int val);
|
|
|
|
static inline void ogs_metrics_inst_inc(ogs_metrics_inst_t *inst)
|
|
|
|
{
|
|
|
|
ogs_metrics_inst_add(inst, 1);
|
|
|
|
}
|
|
|
|
static inline void ogs_metrics_inst_dec(ogs_metrics_inst_t *inst)
|
|
|
|
{
|
|
|
|
ogs_metrics_inst_add(inst, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* OGS_METRICS_CONTEXT_H */
|