Asterisk - The Open Source Telephony Project  18.5.0
Functions
prometheus_internal.h File Reference
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...
 

Function Documentation

◆ bridge_metrics_init()

int bridge_metrics_init ( void  )

Initialize bridge metrics.

Return values
0success
-1error

Definition at line 183 of file bridges.c.

References prometheus_callback_register(), and prometheus_metrics_provider_register().

Referenced by load_module().

184 {
187 
188  return 0;
189 }
struct prometheus_callback bridges_callback
Definition: bridges.c:160
int prometheus_callback_register(struct prometheus_callback *callback)
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
static struct prometheus_metrics_provider provider
Definition: bridges.c:178

◆ channel_metrics_init()

int channel_metrics_init ( void  )

Initialize channel metrics.

Return values
0success
-1error

Definition at line 241 of file channels.c.

References prometheus_callback_register(), and prometheus_metrics_provider_register().

Referenced by load_module().

242 {
245 
246  return 0;
247 }
int prometheus_callback_register(struct prometheus_callback *callback)
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
struct prometheus_callback channels_callback
Definition: channels.c:218
static struct prometheus_metrics_provider provider
Definition: channels.c:236

◆ cli_init()

int cli_init ( void  )

Initialize CLI command.

Return values
0success
-1error

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

References ARRAY_LEN, ast_cli_register_multiple, and prometheus_metrics_provider_register().

Referenced by load_module().

138 {
141 
142  return 0;
143 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct prometheus_metrics_provider provider
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
static struct ast_cli_entry cli_prometheus[]

◆ 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.

References prometheus_callback_register(), and prometheus_metrics_provider_register().

Referenced by load_module().

199 {
202 
203  return 0;
204 }
int prometheus_callback_register(struct prometheus_callback *callback)
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
static struct prometheus_metrics_provider provider
struct prometheus_callback endpoints_callback

◆ 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.

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, prometheus_metrics_provider_register(), registry_message_cb(), stasis_message_router_add(), and stasis_message_router_create.

Referenced by load_module().

343 {
345 
346 #ifdef HAVE_PJPROJECT
348  if (!router) {
349  goto cleanup;
350  }
351 
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
367 cleanup:
369  router = NULL;
372 
373  return -1;
374 #endif /* HAVE_PJPROJECT */
375 }
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
static struct stasis_message_router * router
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.
static void registry_message_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
#define NULL
Definition: resample.c:96
static const struct ast_sorcery_instance_observer observer_callbacks_registrations
static const struct ast_sorcery_observer registration_observer
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
#define stasis_message_router_create(topic)
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:2386
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. ...
static void * cleanup(void *unused)
Definition: pbx_realtime.c:124
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:2418
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static struct prometheus_metrics_provider provider

◆ 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.

References prometheus_metric::value.

Referenced by prometheus_show_status().

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 }
char value[PROMETHEUS_MAX_VALUE_LENGTH]
The current value.
static struct prometheus_metric core_scrape_metric
The scrape duration metric.

◆ 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.

References lock, SCOPED_MUTEX, and scrape_lock.

Referenced by prometheus_show_status().

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

◆ 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.

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

Referenced by prometheus_show_metrics().

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_lock(a)
Definition: lock.h:187
#define NULL
Definition: resample.c:96
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static ast_mutex_t scrape_lock
Lock that protects data structures during an HTTP scrape.
static void scrape_metrics(struct ast_str **response)
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:620
#define ast_mutex_unlock(a)
Definition: lock.h:188