Asterisk - The Open Source Telephony Project GIT-master-97770a9
Functions
prometheus_internal.h File Reference

Prometheus Metric Internal API. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int bridge_metrics_init (void)
 Initialize bridge metrics. More...
 
int channel_metrics_init (void)
 Initialize channel metrics. More...
 
int cli_init (void)
 Initialize CLI command. More...
 
int endpoint_metrics_init (void)
 Initialize endpoint metrics. More...
 
int pjsip_outbound_registration_metrics_init (void)
 Initialize PJSIP outbound registration metrics. More...
 
int64_t prometheus_last_scrape_duration_get (void)
 Retrieve the amount of time it took to perform the last scrape. More...
 
struct timeval prometheus_last_scrape_time_get (void)
 Retrieve the timestamp when the last scrape occurred. More...
 
struct ast_strprometheus_scrape_to_string (void)
 Get the raw output of what a scrape would produce. More...
 

Detailed Description

Prometheus Metric Internal API.

This module provides internal APIs for res_prometheus. It should not be used outsize of that module, and should typically only provide intialization functions for units that want to register metrics / handlers with the core API.

Definition in file prometheus_internal.h.

Function Documentation

◆ bridge_metrics_init()

int bridge_metrics_init ( void  )

Initialize bridge metrics.

Return values
0success
-1error

Definition at line 206 of file bridges.c.

207{
210
211 return 0;
212}
struct prometheus_callback bridges_callback
Definition: bridges.c:183
static struct prometheus_metrics_provider provider
Definition: bridges.c:201
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
int prometheus_callback_register(struct prometheus_callback *callback)

References bridges_callback, prometheus_callback_register(), prometheus_metrics_provider_register(), and provider.

Referenced by load_module().

◆ channel_metrics_init()

int channel_metrics_init ( void  )

Initialize channel metrics.

Return values
0success
-1error

Definition at line 241 of file channels.c.

242{
245
246 return 0;
247}
static struct prometheus_metrics_provider provider
Definition: channels.c:236
struct prometheus_callback channels_callback
Definition: channels.c:218

References channels_callback, prometheus_callback_register(), prometheus_metrics_provider_register(), and provider.

Referenced by load_module().

◆ cli_init()

int cli_init ( void  )

Initialize CLI command.

Return values
0success
-1error

Definition at line 137 of file res/prometheus/cli.c.

138{
141
142 return 0;
143}
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ast_cli_entry cli_prometheus[]
static struct prometheus_metrics_provider provider
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_cli_register_multiple, cli_prometheus, prometheus_metrics_provider_register(), and provider.

Referenced by load_module().

◆ endpoint_metrics_init()

int endpoint_metrics_init ( void  )

Initialize endpoint metrics.

Return values
0success
-1error

Definition at line 198 of file res/prometheus/endpoints.c.

199{
202
203 return 0;
204}
struct prometheus_callback endpoints_callback
static struct prometheus_metrics_provider provider

References endpoints_callback, prometheus_callback_register(), prometheus_metrics_provider_register(), and provider.

Referenced by load_module().

◆ pjsip_outbound_registration_metrics_init()

int pjsip_outbound_registration_metrics_init ( void  )

Initialize PJSIP outbound registration metrics.

Return values
0success
-1error

Definition at line 342 of file pjsip_outbound_registrations.c.

343{
345
346#ifdef HAVE_PJPROJECT
348 if (!router) {
349 goto cleanup;
350 }
351
352 if (stasis_message_router_add(router, ast_system_registry_type(), registry_message_cb, NULL)) {
353 goto cleanup;
354 }
355
357 goto cleanup;
358 }
359
361 goto cleanup;
362 }
363#endif /* HAVE_PJPROJECT */
364 return 0;
365
366#ifdef HAVE_PJPROJECT
367cleanup:
369 router = NULL;
372
373 return -1;
374#endif /* HAVE_PJPROJECT */
375}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
static void * cleanup(void *unused)
Definition: pbx_realtime.c:124
static struct prometheus_metrics_provider provider
static struct stasis_message_router * router
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
static const struct ast_sorcery_instance_observer observer_callbacks_registrations
static const struct ast_sorcery_observer registration_observer
#define NULL
Definition: resample.c:96
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
Definition: sorcery.c:2423
void ast_sorcery_instance_observer_remove(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Remove an observer from a sorcery instance.
Definition: sorcery.c:537
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
Definition: sorcery.c:2391
int ast_sorcery_instance_observer_add(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Add an observer to a sorcery instance.
Definition: sorcery.c:520
#define stasis_message_router_create(topic)
Create a new message router object.
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
struct stasis_message_type * ast_system_registry_type(void)
A stasis_message_type for outbound registration.
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes.

References ao2_cleanup, ast_sip_get_sorcery(), ast_sorcery_instance_observer_add(), ast_sorcery_instance_observer_remove(), ast_sorcery_observer_add(), ast_sorcery_observer_remove(), ast_system_registry_type(), ast_system_topic(), cleanup(), NULL, observer_callbacks_registrations, prometheus_metrics_provider_register(), provider, registration_observer, router, stasis_message_router_add(), and stasis_message_router_create.

Referenced by load_module().

◆ prometheus_last_scrape_duration_get()

int64_t prometheus_last_scrape_duration_get ( void  )

Retrieve the amount of time it took to perform the last scrape.

Time returned is in milliseconds

Return values
Thescrape duration, in milliseconds

Definition at line 701 of file res_prometheus.c.

702{
703 int64_t duration;
704
705 if (sscanf(core_scrape_metric.value, "%" PRIu64, &duration) != 1) {
706 return -1;
707 }
708
709 return duration;
710}
static struct prometheus_metric core_scrape_metric
The scrape duration metric.
char value[PROMETHEUS_MAX_VALUE_LENGTH]
The current value.

References core_scrape_metric, and prometheus_metric::value.

Referenced by prometheus_show_status().

◆ prometheus_last_scrape_time_get()

struct timeval prometheus_last_scrape_time_get ( void  )

Retrieve the timestamp when the last scrape occurred.

Return values
Thetime when the last scrape occurred

Definition at line 712 of file res_prometheus.c.

713{
715
716 return last_scrape;
717}
ast_mutex_t lock
Definition: app_sla.c:331
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:589
static struct timeval last_scrape
static ast_mutex_t scrape_lock
Lock that protects data structures during an HTTP scrape.

References last_scrape, lock, SCOPED_MUTEX, and scrape_lock.

Referenced by prometheus_show_status().

◆ prometheus_scrape_to_string()

struct ast_str * prometheus_scrape_to_string ( void  )

Get the raw output of what a scrape would produce.

It can be useful to dump what a scrape will look like. This function returns the raw string representation of the metrics.

Return values
NULLon error
Malloc'dast_str on success

Definition at line 685 of file res_prometheus.c.

686{
687 struct ast_str *response;
688
689 response = ast_str_create(512);
690 if (!response) {
691 return NULL;
692 }
693
695 scrape_metrics(&response);
697
698 return response;
699}
#define ast_mutex_unlock(a)
Definition: lock.h:190
#define ast_mutex_lock(a)
Definition: lock.h:189
static void scrape_metrics(struct ast_str **response)
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
Support for dynamic strings.
Definition: strings.h:623

References ast_mutex_lock, ast_mutex_unlock, ast_str_create, NULL, scrape_lock, and scrape_metrics().

Referenced by AST_TEST_DEFINE(), and prometheus_show_metrics().