122#define AST_MODULE_SELF_SYM __internal_res_prometheus_self
158 .category =
"general",
181#define CORE_PROPERTIES_HELP "Asterisk instance properties. The value of this will always be 1."
183#define CORE_UPTIME_HELP "Asterisk instance uptime in seconds."
185#define CORE_LAST_RELOAD_HELP "Time since last Asterisk reload in seconds."
187#define CORE_METRICS_SCRAPE_TIME_HELP "Total time taken to collect metrics, in milliseconds"
194 snprintf(metric->
value,
sizeof(metric->
value),
"%" PRIu64, duration);
202 snprintf(metric->
value,
sizeof(metric->
value),
"%" PRIu64, duration);
217 "asterisk_core_scrape_time_ms",
221#define METRIC_CORE_PROPS_ARRAY_INDEX 0
228 "asterisk_core_properties",
233 "asterisk_core_uptime_seconds",
238 "asterisk_core_last_reload_seconds",
258 if (strcmp(left->
name, right->
name)) {
263 ast_debug(5,
"Comparison: Label %d Names %s == %s\n", i,
269 ast_debug(5,
"Comparison: Label %d Values %s == %s\n", i,
276 ast_debug(5,
"Copmarison: %s (%p) is equal to %s (%p)\n",
277 left->
name, left, right->
name, right);
303 "Refusing registration of existing Prometheus metric: %s\n",
311 "Refusing registration of existing Prometheus metric: %s\n",
317 if (!strcmp(metric->
name, existing->
name)) {
318 ast_debug(3,
"Nesting metric '%s' as child (%p) under existing (%p)\n",
319 metric->
name, metric, existing);
325 ast_debug(3,
"Tracking new root metric '%s'\n", metric->
name);
375 if (!strcmp(existing->
name, metric->
name)) {
489 int labels_exist = 0;
556 if (!strcmp(callback->
name,
entry->name)) {
599 struct timeval start;
603 if (!mod_cfg || !mod_cfg->general->enabled) {
615 if (strcmp(http_auth->
userid, mod_cfg->general->auth_username)) {
616 ast_debug(5,
"Invalid username provided for auth request: %s\n", http_auth->
userid);
621 if (strcmp(http_auth->
password, mod_cfg->general->auth_password)) {
622 ast_debug(5,
"Invalid password provided for auth request: %s\n", http_auth->
password);
642 if (mod_cfg->general->core_metrics_enabled) {
661 struct ast_str *auth_challenge_headers;
664 if (!auth_challenge_headers) {
668 "WWW-Authenticate: Basic realm=\"%s\"\r\n",
669 mod_cfg->general->auth_realm);
747 return mod_cfg->general;
808 if (!
config->general->enabled) {
842 if (mod_cfg->general->core_metrics_enabled) {
1010#ifdef HAVE_PJPROJECT
1012 .
requires =
"res_pjsip",
1013 .optional_modules =
"res_pjsip_outbound_registration",
Asterisk version information.
const char * ast_get_build_opts(void)
const char * ast_get_version(void)
Retrieve the Asterisk version string.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
#define ao2_alloc(data_size, destructor_fn)
static struct prometheus_metrics_provider provider
int bridge_metrics_init(void)
Initialize bridge metrics.
const char * ast_build_os
const char * ast_build_hostname
const char * ast_build_date
const char * ast_build_kernel
static const char config[]
int channel_metrics_init(void)
Initialize channel metrics.
Configuration option-handling.
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
@ ACO_PROCESS_ERROR
Their was an error and no changes were applied.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
void * aco_pending_config(struct aco_info *info)
Get pending config changes.
enum aco_process_status aco_process_config(struct aco_info *info, int reload)
Process a config info via the options registered with an aco_info.
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.
Support for Private Asterisk HTTP Servers.
void ast_http_send(struct ast_tcptls_session_instance *ser, enum ast_http_method method, int status_code, const char *status_title, struct ast_str *http_header, struct ast_str *out, int fd, unsigned int static_content)
Generic function for sending HTTP/1.1 response.
ast_http_method
HTTP Request methods known by Asterisk.
void ast_http_uri_unlink(struct ast_http_uri *urihandler)
Unregister a URI handler.
struct ast_http_auth * ast_http_get_auth(struct ast_variable *headers)
Get HTTP authentication information from headers.
int ast_http_uri_link(struct ast_http_uri *urihandler)
Register a URI handler.
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define ast_mutex_init(pmutex)
#define ast_mutex_unlock(a)
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
#define ast_mutex_destroy(a)
#define ast_mutex_lock(a)
#define AST_MUTEX_DEFINE_STATIC(mutex)
Asterisk module definitions.
@ AST_MODFLAG_GLOBAL_SYMBOLS
int ast_module_check(const char *name)
Check if module with the name given is loaded.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_EXTENDED
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
struct timeval ast_lastreloadtime
struct timeval ast_startuptime
static void * cleanup(void *unused)
int pjsip_outbound_registration_metrics_init(void)
Initialize PJSIP outbound registration metrics.
Prometheus Metric Internal API.
int cli_init(void)
Initialize CLI command.
int endpoint_metrics_init(void)
Initialize endpoint metrics.
#define CORE_LAST_RELOAD_HELP
int prometheus_metric_unregister(struct prometheus_metric *metric)
Remove a registered metric.
struct aco_type * global_options[]
static struct timeval last_scrape
int prometheus_metric_register(struct prometheus_metric *metric)
int prometheus_metric_registered_count(void)
CONFIG_INFO_STANDARD(cfg_info, global_config, module_config_alloc,.files=ACO_FILES(&prometheus_conf),.pre_apply_config=prometheus_config_pre_apply,.post_apply_config=prometheus_config_post_apply,)
Register information about the configs being processed by this module.
void prometheus_general_config_set(struct prometheus_general_config *config)
Set the configuration for the module.
static void prometheus_metric_full_to_string(struct prometheus_metric *metric, struct ast_str **output)
static void get_core_uptime_cb(struct prometheus_metric *metric)
static int http_callback(struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers)
static void prometheus_general_config_dtor(void *obj)
struct ast_str * prometheus_scrape_to_string(void)
Get the raw output of what a scrape would produce.
static void prometheus_config_post_apply(void)
Post-apply callback for the config framework.
static ast_mutex_t scrape_lock
Lock that protects data structures during an HTTP scrape.
static struct prometheus_metric core_metrics[]
Core metrics to scrape.
static AO2_GLOBAL_OBJ_STATIC(global_config)
The module configuration container.
struct timeval prometheus_last_scrape_time_get(void)
Retrieve the timestamp when the last scrape occurred.
struct prometheus_metric * prometheus_gauge_create(const char *name, const char *help)
Create a malloc'd gauge metric.
static int reload_module(void)
void prometheus_callback_unregister(struct prometheus_callback *callback)
Remove a registered callback.
static void get_last_reload_cb(struct prometheus_metric *metric)
static struct prometheus_metric core_scrape_metric
The scrape duration metric.
static int prometheus_metric_cmp(struct prometheus_metric *left, struct prometheus_metric *right)
static const char * prometheus_metric_type_to_string(enum prometheus_metric_type type)
static void module_config_dtor(void *obj)
Configuration object destructor.
void * prometheus_general_config_alloc(void)
Allocate a new configuration object.
int64_t prometheus_last_scrape_duration_get(void)
Retrieve the amount of time it took to perform the last scrape.
static struct ast_http_uri prometheus_uri
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.
static int load_module(void)
struct aco_file prometheus_conf
static int prometheus_config_pre_apply(void)
Pre-apply callback for the config framework.
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
static int unload_module(void)
#define CORE_PROPERTIES_HELP
static void * module_config_alloc(void)
Module config constructor.
#define CORE_METRICS_SCRAPE_TIME_HELP
int prometheus_callback_register(struct prometheus_callback *callback)
struct prometheus_general_config * prometheus_general_config_get(void)
Retrieve the current configuration of the module.
static struct aco_type global_option
static void scrape_metrics(struct ast_str **response)
#define METRIC_CORE_PROPS_ARRAY_INDEX
static struct prometheus_metric * prometheus_metric_create(const char *name, const char *help)
struct prometheus_metric * prometheus_counter_create(const char *name, const char *help)
Create a malloc'd counter metric.
Asterisk Prometheus Metrics.
#define PROMETHEUS_METRIC_SET_LABEL(metric, label, n, v)
Convenience macro for setting a label / value in a metric.
#define PROMETHEUS_METRIC_STATIC_INITIALIZATION(mtype, n, h, cb)
Convenience macro for initializing a metric on the stack.
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.
#define PROMETHEUS_MAX_LABELS
How many labels a single metric can have.
@ PROMETHEUS_METRIC_ALLOCD
The metric was allocated on the stack.
@ PROMETHEUS_METRIC_MALLOCD
The metric was allocated on the heap.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
The representation of a single configuration file to be processed.
Type information about a category-level configurable object.
HTTP authentication information.
Definition of a URI handler.
Support for dynamic strings.
describes a server instance
Structure for variables, used for configurations and for channel variables.
The configuration settings for this module.
struct prometheus_general_config * general
General settings.
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.
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.
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.
int64_t ast_tvdiff_sec(struct timeval end, struct timeval start)
Computes the difference (in seconds) between two struct timeval instances.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
struct ast_eid ast_eid_default
Global EID.
Vector container support.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_INSERT_AT(vec, idx, elem)
Insert an element at a specific position in a vector, growing the vector if needed.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
#define AST_VECTOR_REMOVE(vec, idx, preserve_ordered)
Remove an element from a vector by index.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
#define AST_VECTOR(name, type)
Define a vector structure.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.