Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
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. More... | |
#define | PROMETHEUS_MAX_LABELS 8 |
How many labels a single metric can have. More... | |
#define | PROMETHEUS_MAX_NAME_LENGTH 64 |
How long a label name can be. More... | |
#define | PROMETHEUS_MAX_VALUE_LENGTH 32 |
How large of a value we can store. More... | |
#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_MAX_LABEL_LENGTH 128 |
How long a label value can be.
Definition at line 49 of file res_prometheus.h.
#define PROMETHEUS_MAX_LABELS 8 |
How many labels a single metric can have.
Definition at line 39 of file res_prometheus.h.
#define PROMETHEUS_MAX_NAME_LENGTH 64 |
How long a label name can be.
Definition at line 44 of file res_prometheus.h.
#define PROMETHEUS_MAX_VALUE_LENGTH 32 |
How large of a value we can store.
Definition at line 54 of 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.
#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_strlen_zero(), AST_VECTOR_APPEND, prometheus_callback::callback_fn, callbacks, lock, prometheus_callback::name, SCOPED_MUTEX, and scrape_lock.
Referenced by AST_TEST_DEFINE(), 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, callbacks, lock, prometheus_callback::name, SCOPED_MUTEX, and scrape_lock.
Referenced by AST_TEST_DEFINE(), bridge_metrics_unload_cb(), channel_metrics_unload_cb(), and endpoint_metrics_unload_cb().
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::help, name, NULL, PROMETHEUS_METRIC_COUNTER, prometheus_metric_create(), and prometheus_metric::type.
Referenced by AST_TEST_DEFINE().
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::help, name, NULL, prometheus_metric_create(), PROMETHEUS_METRIC_GAUGE, and prometheus_metric::type.
Referenced by AST_TEST_DEFINE().
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 ao2_alloc, ast_string_field_init, config, NULL, and prometheus_general_config_dtor().
Referenced by config_alloc(), and 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_cleanup, ao2_global_obj_ref, NULL, and RAII_VAR.
Referenced by prometheus_show_status(), reload_module(), and test_init_cb().
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_cleanup, ao2_global_obj_ref, ao2_replace, config, prometheus_config_post_apply(), and RAII_VAR.
Referenced by AST_TEST_DEFINE(), test_cleanup_cb(), and test_init_cb().
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_free, AST_LIST_REMOVE_HEAD, ast_mutex_destroy, prometheus_metric::children, prometheus_metric::lock, PROMETHEUS_METRIC_ALLOCD, prometheus_metric_free(), and PROMETHEUS_METRIC_MALLOCD.
Referenced by AST_TEST_DEFINE(), prometheus_metric_free(), prometheus_metric_free_wrapper(), prometheus_metric_unregister(), and unload_module().
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_log, AST_LOG_NOTICE, AST_LOG_WARNING, AST_VECTOR_APPEND, AST_VECTOR_GET, AST_VECTOR_SIZE, prometheus_metric::children, lock, metrics, prometheus_metric::name, prometheus_metric_cmp(), SCOPED_MUTEX, and scrape_lock.
Referenced by AST_TEST_DEFINE(), and 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, metrics, SCOPED_MUTEX, and scrape_lock.
Referenced by AST_TEST_DEFINE().
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, prometheus_metric_full_to_string(), prometheus_metric_type_to_string(), and prometheus_metric::type.
Referenced by AST_TEST_DEFINE(), bridges_scrape_cb(), channels_scrape_cb(), endpoints_scrape_cb(), http_callback(), prometheus_metric_callback(), and scrape_metrics().
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, metrics, prometheus_metric::name, prometheus_metric_cmp(), prometheus_metric_free(), SCOPED_MUTEX, and scrape_lock.
Referenced by AST_TEST_DEFINE(), prometheus_config_post_apply(), and prometheus_metric_free_wrapper().
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, provider, and providers.
Referenced by bridge_metrics_init(), channel_metrics_init(), cli_init(), endpoint_metrics_init(), and pjsip_outbound_registration_metrics_init().