Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Functions | Variables
pjsip_outbound_registrations.c File Reference

Prometheus PJSIP Outbound Registration Metrics. More...

#include "asterisk.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/stasis_system.h"
#include "asterisk/res_prometheus.h"
#include "asterisk/res_pjsip.h"
#include "prometheus_internal.h"

Go to the source code of this file.

Data Structures

struct  prometheus_metric_wrapper
 

Functions

static struct prometheus_metric_wrappercreate_wrapper (const char *key)
 
static struct prometheus_metric_wrapperget_wrapper (const char *key)
 
int pjsip_outbound_registration_metrics_init (void)
 Initialize PJSIP outbound registration metrics. More...
 
static void pjsip_outbound_registration_metrics_unload_cb (void)
 
static void registration_deleted_observer (const void *obj)
 
static void registration_loaded_observer (const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
 
static int registration_state_to_int (const char *state)
 
static void registry_message_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 

Variables

struct {
   size_t   current
 
   struct prometheus_metric_wrapper **   elems
 
   size_t   max
 
metrics
 
static ast_mutex_t metrics_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static const struct ast_sorcery_instance_observer observer_callbacks_registrations
 
static struct prometheus_metrics_provider provider
 
static const struct ast_sorcery_observer registration_observer
 
static struct stasis_message_routerrouter
 

Detailed Description

Prometheus PJSIP Outbound Registration Metrics.

Author
Matt Jordan mjord.nosp@m.an@d.nosp@m.igium.nosp@m..com

Definition in file pjsip_outbound_registrations.c.

Function Documentation

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

Variable Documentation

const struct ast_sorcery_instance_observer observer_callbacks_registrations
static
Initial value:
= {
.object_type_loaded = registration_loaded_observer,
}

Definition at line 251 of file pjsip_outbound_registrations.c.

struct prometheus_metrics_provider provider
static
Initial value:
= {
.name = "pjsip_outbound_registration",
.unload_cb = pjsip_outbound_registration_metrics_unload_cb,
}

Definition at line 337 of file pjsip_outbound_registrations.c.

const struct ast_sorcery_observer registration_observer
static
Initial value:
= {
.deleted = registration_deleted_observer,
}

Definition at line 191 of file pjsip_outbound_registrations.c.