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)); \
static struct prometheus_metrics_provider provider
static const char config[]
A set of macros to manage forward-linked lists.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Asterisk locking-related definitions:
int prometheus_metric_unregister(struct prometheus_metric *metric)
Remove a registered metric.
int prometheus_metric_register(struct prometheus_metric *metric)
int prometheus_metric_registered_count(void)
#define PROMETHEUS_MAX_LABEL_LENGTH
How long a label value can be.
void prometheus_general_config_set(struct prometheus_general_config *config)
Set the configuration for the module.
prometheus_metric_type
Prometheus metric type.
@ PROMETHEUS_METRIC_GAUGE
A metric whose value can bounce around like a jackrabbit.
@ PROMETHEUS_METRIC_COUNTER
A metric whose value always goes up.
struct prometheus_metric * prometheus_gauge_create(const char *name, const char *help)
Create a malloc'd gauge metric.
void prometheus_callback_unregister(struct prometheus_callback *callback)
Remove a registered callback.
#define PROMETHEUS_MAX_NAME_LENGTH
How long a label name can be.
void * prometheus_general_config_alloc(void)
Allocate a new configuration object.
#define PROMETHEUS_MAX_LABELS
How many labels a single metric can have.
void prometheus_metric_free(struct prometheus_metric *metric)
Destroy a metric and all its children.
void prometheus_metric_to_string(struct prometheus_metric *metric, struct ast_str **output)
Convert a metric (and its children) into Prometheus compatible text.
#define PROMETHEUS_MAX_VALUE_LENGTH
How large of a value we can store.
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
int prometheus_callback_register(struct prometheus_callback *callback)
struct prometheus_general_config * prometheus_general_config_get(void)
Retrieve the current configuration of the module.
prometheus_metric_allocation_strategy
How the metric was allocated.
@ PROMETHEUS_METRIC_ALLOCD
The metric was allocated on the stack.
@ PROMETHEUS_METRIC_MALLOCD
The metric was allocated on the heap.
struct prometheus_metric * prometheus_counter_create(const char *name, const char *help)
Create a malloc'd counter metric.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
Structure for mutex and tracking information.
Support for dynamic strings.
Defines a callback that will be invoked when the HTTP route is called.
void(* callback_fn)(struct ast_str **output)
The callback function to invoke.
const char * name
The name of our callback (always useful for debugging)
Prometheus general configuration.
const ast_string_field uri
unsigned int enabled
Whether or not the module is enabled.
unsigned int core_metrics_enabled
Whether or not core metrics are enabled.
const ast_string_field auth_password
const ast_string_field auth_realm
const ast_string_field auth_username
A label that further defines a metric.
char name[PROMETHEUS_MAX_NAME_LENGTH]
The name of the label.
char value[PROMETHEUS_MAX_LABEL_LENGTH]
The value of the label.
An actual, honest to god, metric.
char name[PROMETHEUS_MAX_NAME_LENGTH]
Our metric name.
struct prometheus_metric::@270 children
A list of children metrics.
void(* get_metric_value)(struct prometheus_metric *metric)
Callback function to obtain the metric value.
struct prometheus_label labels[PROMETHEUS_MAX_LABELS]
The metric's labels.
struct prometheus_metric::@271 entry
enum prometheus_metric_allocation_strategy allocation_strategy
How this metric was allocated.
const char * help
Pointer to a static string defining this metric's help text.
ast_mutex_t lock
A lock protecting the metric value.
char value[PROMETHEUS_MAX_VALUE_LENGTH]
The current value.
enum prometheus_metric_type type
What type of metric we are.
A function table for a metrics provider.
void(*const unload_cb)(void)
Unload callback.
int(*const reload_cb)(struct prometheus_general_config *config)
Reload callback.
const char * name
Handy name of the provider for debugging purposes.