19 #ifndef RES_PROMETHEUS_H__
20 #define RES_PROMETHEUS_H__
39 #define PROMETHEUS_MAX_LABELS 8
44 #define PROMETHEUS_MAX_NAME_LENGTH 64
49 #define PROMETHEUS_MAX_LABEL_LENGTH 128
54 #define PROMETHEUS_MAX_VALUE_LENGTH 32
281 #define PROMETHEUS_METRIC_STATIC_INITIALIZATION(mtype, n, h, cb) { \
283 .allocation_strategy = PROMETHEUS_METRIC_ALLOCD, \
284 .lock = AST_MUTEX_INIT_VALUE, \
287 .children = AST_LIST_HEAD_NOLOCK_INIT_VALUE, \
288 .get_metric_value = (cb), \
313 #define PROMETHEUS_METRIC_SET_LABEL(metric, label, n, v) do { \
314 ast_assert((label) < PROMETHEUS_MAX_LABELS); \
315 ast_copy_string((metric)->labels[(label)].name, (n), sizeof((metric)->labels[(label)].name)); \
316 ast_copy_string((metric)->labels[(label)].value, (v), sizeof((metric)->labels[(label)].value)); \
412 void (* callback_fn)(
struct ast_str **output);
unsigned int core_metrics_enabled
Whether or not core metrics are enabled.
Asterisk locking-related definitions:
An actual, honest to god, metric.
#define PROMETHEUS_MAX_VALUE_LENGTH
How large of a value we can store.
int prometheus_metric_register(struct prometheus_metric *metric)
void(*const unload_cb)(void)
Unload callback.
Prometheus general configuration.
int prometheus_callback_register(struct prometheus_callback *callback)
#define PROMETHEUS_MAX_NAME_LENGTH
How long a label name can be.
prometheus_metric_allocation_strategy
How the metric was allocated.
A metric whose value always goes up.
const char * name
The name of our callback (always useful for debugging)
enum prometheus_metric_allocation_strategy allocation_strategy
How this metric was allocated.
enum prometheus_metric_type type
What type of metric we are.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
void(* get_metric_value)(struct prometheus_metric *metric)
Callback function to obtain the metric value.
int prometheus_metric_unregister(struct prometheus_metric *metric)
Remove a registered metric.
void prometheus_metric_free(struct prometheus_metric *metric)
Destroy a metric and all its children.
void prometheus_general_config_set(struct prometheus_general_config *config)
Set the configuration for the module.
void prometheus_metric_to_string(struct prometheus_metric *metric, struct ast_str **output)
Convert a metric (and its children) into Prometheus compatible text.
The metric was allocated on the stack.
#define PROMETHEUS_MAX_LABEL_LENGTH
How long a label value can be.
#define PROMETHEUS_MAX_LABELS
How many labels a single metric can have.
struct prometheus_metric::@274 children
A list of children metrics.
#define AST_STRING_FIELD(name)
Declare a string field.
const ast_string_field auth_password
Auth password for Basic Auth.
char name[PROMETHEUS_MAX_NAME_LENGTH]
The name of the label.
A set of macros to manage forward-linked lists.
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
struct prometheus_metric * prometheus_gauge_create(const char *name, const char *help)
Create a malloc'd gauge metric.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
Support for dynamic strings.
struct prometheus_label labels[PROMETHEUS_MAX_LABELS]
The metric's labels.
int(*const reload_cb)(struct prometheus_general_config *config)
Reload callback.
char value[PROMETHEUS_MAX_VALUE_LENGTH]
The current value.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
const char * help
Pointer to a static string defining this metric's help text.
void * prometheus_general_config_alloc(void)
Allocate a new configuration object.
char value[PROMETHEUS_MAX_LABEL_LENGTH]
The value of the label.
void prometheus_callback_unregister(struct prometheus_callback *callback)
Remove a registered callback.
const char * name
Handy name of the provider for debugging purposes.
const ast_string_field auth_realm
Auth realm.
char name[PROMETHEUS_MAX_NAME_LENGTH]
Our metric name.
const ast_string_field uri
The HTTP URI we register ourselves to.
struct prometheus_metric * prometheus_counter_create(const char *name, const char *help)
Create a malloc'd counter metric.
A function table for a metrics provider.
int prometheus_metric_registered_count(void)
ast_mutex_t lock
A lock protecting the metric value.
A label that further defines a metric.
prometheus_metric_type
Prometheus metric type.
A metric whose value can bounce around like a jackrabbit.
The metric was allocated on the heap.
struct prometheus_general_config * prometheus_general_config_get(void)
Retrieve the current configuration of the module.
Defines a callback that will be invoked when the HTTP route is called.
Structure for mutex and tracking information.
const ast_string_field auth_username
Auth username for Basic Auth.
unsigned int enabled
Whether or not the module is enabled.