Asterisk - The Open Source Telephony Project  21.4.1
Functions
prometheus_internal.h File Reference

Prometheus Metric Internal API. More...

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

int bridge_metrics_init ( void  )

Initialize bridge metrics.

Return values
0success
-1error

Definition at line 206 of file bridges.c.

References prometheus_callback_register(), and prometheus_metrics_provider_register().

207 {
209  prometheus_callback_register(&bridges_callback);
210 
211  return 0;
212 }
int prometheus_callback_register(struct prometheus_callback *callback)
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
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().

242 {
244  prometheus_callback_register(&channels_callback);
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.
int cli_init ( void  )

Initialize CLI command.

Return values
0success
-1error

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

References ast_cli_register_multiple, and prometheus_metrics_provider_register().

138 {
140  ast_cli_register_multiple(cli_prometheus, ARRAY_LEN(cli_prometheus));
141 
142  return 0;
143 }
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
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().

199 {
201  prometheus_callback_register(&endpoints_callback);
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.
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 ast_sorcery_instance_observer_add(), ast_sorcery_instance_observer_remove(), ast_sorcery_observer_add(), ast_sorcery_observer_remove(), ast_system_topic(), cleanup(), prometheus_metrics_provider_register(), and stasis_message_router_add().

343 {
345 
346 #ifdef HAVE_PJPROJECT
347  router = stasis_message_router_create(ast_system_topic());
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 
356  if (ast_sorcery_instance_observer_add(ast_sip_get_sorcery(), &observer_callbacks_registrations)) {
357  goto cleanup;
358  }
359 
360  if (ast_sorcery_observer_add(ast_sip_get_sorcery(), "registration", &registration_observer)) {
361  goto cleanup;
362  }
363 #endif /* HAVE_PJPROJECT */
364  return 0;
365 
366 #ifdef HAVE_PJPROJECT
367 cleanup:
368  ao2_cleanup(router);
369  router = NULL;
370  ast_sorcery_instance_observer_remove(ast_sip_get_sorcery(), &observer_callbacks_registrations);
371  ast_sorcery_observer_remove(ast_sip_get_sorcery(), "registration", &registration_observer);
372 
373  return -1;
374 #endif /* HAVE_PJPROJECT */
375 }
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes. ...
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.
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 void cleanup(void)
Clean up any old apps that we don't need any more.
Definition: res_stasis.c:327
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
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
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
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.

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

713 {
715 
716  return last_scrape;
717 }
ast_mutex_t lock
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:589
static ast_mutex_t scrape_lock
Lock that protects data structures during an HTTP scrape.
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_str_create, and scrape_lock.

686 {
687  struct ast_str *response;
688 
689  response = ast_str_create(512);
690  if (!response) {
691  return NULL;
692  }
693 
694  ast_mutex_lock(&scrape_lock);
695  scrape_metrics(&response);
696  ast_mutex_unlock(&scrape_lock);
697 
698  return response;
699 }
Support for dynamic strings.
Definition: strings.h:623
static ast_mutex_t scrape_lock
Lock that protects data structures during an HTTP scrape.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659