Asterisk - The Open Source Telephony Project
21.4.1
|
Asterisk Prometheus Metrics. More...
Go to the source code of this file.
Data Structures | |
struct | prometheus_callback |
Defines a callback that will be invoked when the HTTP route is called. More... | |
struct | prometheus_general_config |
Prometheus general configuration. More... | |
struct | prometheus_label |
A label that further defines a metric. More... | |
struct | prometheus_metric |
An actual, honest to god, metric. More... | |
struct | prometheus_metrics_provider |
A function table for a metrics provider. More... | |
Macros | |
#define | PROMETHEUS_MAX_LABEL_LENGTH 128 |
How long a label value can be. | |
#define | PROMETHEUS_MAX_LABELS 8 |
How many labels a single metric can have. | |
#define | PROMETHEUS_MAX_NAME_LENGTH 64 |
How long a label name can be. | |
#define | PROMETHEUS_MAX_VALUE_LENGTH 32 |
How large of a value we can store. | |
#define | PROMETHEUS_METRIC_SET_LABEL(metric, label, n, v) |
Convenience macro for setting a label / value in a metric. More... | |
#define | PROMETHEUS_METRIC_STATIC_INITIALIZATION(mtype, n, h, cb) |
Convenience macro for initializing a metric on the stack. More... | |
Enumerations | |
enum | prometheus_metric_allocation_strategy { PROMETHEUS_METRIC_ALLOCD = 0, PROMETHEUS_METRIC_MALLOCD } |
How the metric was allocated. More... | |
enum | prometheus_metric_type { PROMETHEUS_METRIC_COUNTER = 0, PROMETHEUS_METRIC_GAUGE } |
Prometheus metric type. More... | |
Functions | |
int | prometheus_callback_register (struct prometheus_callback *callback) |
void | prometheus_callback_unregister (struct prometheus_callback *callback) |
Remove a registered callback. More... | |
struct prometheus_metric * | prometheus_counter_create (const char *name, const char *help) |
Create a malloc'd counter metric. More... | |
struct prometheus_metric * | prometheus_gauge_create (const char *name, const char *help) |
Create a malloc'd gauge metric. More... | |
void * | prometheus_general_config_alloc (void) |
Allocate a new configuration object. More... | |
struct prometheus_general_config * | prometheus_general_config_get (void) |
Retrieve the current configuration of the module. More... | |
void | prometheus_general_config_set (struct prometheus_general_config *config) |
Set the configuration for the module. More... | |
void | prometheus_metric_free (struct prometheus_metric *metric) |
Destroy a metric and all its children. More... | |
int | prometheus_metric_register (struct prometheus_metric *metric) |
int | prometheus_metric_registered_count (void) |
void | prometheus_metric_to_string (struct prometheus_metric *metric, struct ast_str **output) |
Convert a metric (and its children) into Prometheus compatible text. More... | |
int | prometheus_metric_unregister (struct prometheus_metric *metric) |
Remove a registered metric. More... | |
void | prometheus_metrics_provider_register (const struct prometheus_metrics_provider *provider) |
Register a metrics provider. More... | |
Asterisk Prometheus Metrics.
This module provides the base APIs and functionality for exposing a metrics route in Asterisk's HTTP server suitable for consumption by a Prometheus server. It does not provide any metrics itself.
Definition in file res_prometheus.h.
#define PROMETHEUS_METRIC_SET_LABEL | ( | metric, | |
label, | |||
n, | |||
v | |||
) |
Convenience macro for setting a label / value in a metric.
When creating nested metrics, it's helpful to set their label after they have been declared but before they have been registered. This macro acts as a convenience function to set the labels properly on a declared metric.
Example Usage:
metric | The metric to set the label on |
label | Position of the label to set |
n | Name of the label |
v | Value of the label |
Definition at line 313 of file res_prometheus.h.
Referenced by prometheus_config_post_apply().
#define PROMETHEUS_METRIC_STATIC_INITIALIZATION | ( | mtype, | |
n, | |||
h, | |||
cb | |||
) |
Convenience macro for initializing a metric on the stack.
When initializing a metric on the stack, various fields have to be provided to initialize the metric correctly. This macro can be used to simplify the process.
Example Usage:
mtype | The metric type. See prometheus_metric_type |
n | Name of the metric |
h | Help text for the metric |
cb | Callback function. Optional; may be NULL |
Definition at line 281 of file res_prometheus.h.
How the metric was allocated.
Enumerator | |
---|---|
PROMETHEUS_METRIC_ALLOCD |
The metric was allocated on the stack. |
PROMETHEUS_METRIC_MALLOCD |
The metric was allocated on the heap. |
Definition at line 138 of file res_prometheus.h.
Prometheus metric type.
Enumerator | |
---|---|
PROMETHEUS_METRIC_COUNTER |
A metric whose value always goes up. |
PROMETHEUS_METRIC_GAUGE |
A metric whose value can bounce around like a jackrabbit. |
Definition at line 122 of file res_prometheus.h.
int prometheus_callback_register | ( | struct prometheus_callback * | callback | ) |
Register a metric callback
callback | The callback to register |
0 | success |
-1 | error |
Definition at line 535 of file res_prometheus.c.
References AST_VECTOR_APPEND, prometheus_callback::callback_fn, lock, prometheus_callback::name, SCOPED_MUTEX, and scrape_lock.
Referenced by bridge_metrics_init(), channel_metrics_init(), and endpoint_metrics_init().
void prometheus_callback_unregister | ( | struct prometheus_callback * | callback | ) |
Remove a registered callback.
callback | The callback to unregister |
Definition at line 548 of file res_prometheus.c.
References AST_VECTOR_GET, AST_VECTOR_REMOVE, AST_VECTOR_SIZE, lock, prometheus_callback::name, SCOPED_MUTEX, and scrape_lock.
struct prometheus_metric* prometheus_counter_create | ( | const char * | name, |
const char * | help | ||
) |
Create a malloc'd counter metric.
name | The name of the metric |
help | Help text for the metric |
prometheus_metric | on success |
NULL | on error |
Definition at line 452 of file res_prometheus.c.
References PROMETHEUS_METRIC_COUNTER, and prometheus_metric::type.
struct prometheus_metric* prometheus_gauge_create | ( | const char * | name, |
const char * | help | ||
) |
Create a malloc'd gauge metric.
name | The name of the metric |
help | Help text for the metric |
prometheus_metric | on success |
NULL | on error |
Definition at line 439 of file res_prometheus.c.
References PROMETHEUS_METRIC_GAUGE, and prometheus_metric::type.
void* prometheus_general_config_alloc | ( | void | ) |
Allocate a new configuration object.
The returned object is an AO2 ref counted object
NULL | on error |
config | on success |
Definition at line 726 of file res_prometheus.c.
References ast_string_field_init.
Referenced by module_config_alloc().
struct prometheus_general_config* prometheus_general_config_get | ( | void | ) |
Retrieve the current configuration of the module.
config is an AO2 ref counted object
NULL | on error |
config | on success |
Definition at line 738 of file res_prometheus.c.
References ao2_bump, ao2_global_obj_ref, and RAII_VAR.
void prometheus_general_config_set | ( | struct prometheus_general_config * | config | ) |
Set the configuration for the module.
This is not a ref-stealing function. The reference count to config
will be incremented as a result of calling this method.
Definition at line 750 of file res_prometheus.c.
References ao2_global_obj_ref, ao2_replace, prometheus_config_post_apply(), and RAII_VAR.
void prometheus_metric_free | ( | struct prometheus_metric * | metric | ) |
Destroy a metric and all its children.
children
list first.metric | The metric to destroy |
Definition at line 393 of file res_prometheus.c.
References prometheus_metric::allocation_strategy, AST_LIST_REMOVE_HEAD, prometheus_metric::children, prometheus_metric::lock, PROMETHEUS_METRIC_ALLOCD, and PROMETHEUS_METRIC_MALLOCD.
Referenced by prometheus_metric_unregister().
int prometheus_metric_register | ( | struct prometheus_metric * | metric | ) |
Register a metric for collection
metric | The metric to register |
0 | success |
-1 | error |
Definition at line 288 of file res_prometheus.c.
References ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, AST_VECTOR_APPEND, AST_VECTOR_GET, AST_VECTOR_SIZE, prometheus_metric::children, lock, prometheus_metric::name, SCOPED_MUTEX, and scrape_lock.
Referenced by prometheus_config_post_apply().
int prometheus_metric_registered_count | ( | void | ) |
The current number of registered metrics
The | current number of registered metrics |
Definition at line 281 of file res_prometheus.c.
References AST_VECTOR_SIZE, lock, SCOPED_MUTEX, and scrape_lock.
void prometheus_metric_to_string | ( | struct prometheus_metric * | metric, |
struct ast_str ** | output | ||
) |
Convert a metric (and its children) into Prometheus compatible text.
metric | The metric to convert to a string | |
[out] | output | The ast_str string to populate with the metric(s) |
Definition at line 521 of file res_prometheus.c.
References AST_LIST_TRAVERSE, ast_str_append(), prometheus_metric::children, prometheus_metric::help, prometheus_metric::name, and prometheus_metric::type.
int prometheus_metric_unregister | ( | struct prometheus_metric * | metric | ) |
Remove a registered metric.
metric | The metric to unregister |
0 | The metric was found, unregistered, and disposed of |
-1 | The metric was not found |
Definition at line 335 of file res_prometheus.c.
References ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_CURRENT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_VECTOR_GET, AST_VECTOR_INSERT_AT, AST_VECTOR_REMOVE, AST_VECTOR_SIZE, prometheus_metric::children, lock, prometheus_metric::name, prometheus_metric_free(), SCOPED_MUTEX, and scrape_lock.
Referenced by prometheus_config_post_apply().
void prometheus_metrics_provider_register | ( | const struct prometheus_metrics_provider * | provider | ) |
Register a metrics provider.
provider | The provider function table to register |
Definition at line 871 of file res_prometheus.c.
References AST_VECTOR_APPEND.
Referenced by bridge_metrics_init(), channel_metrics_init(), cli_init(), endpoint_metrics_init(), and pjsip_outbound_registration_metrics_init().