119 if (!strcmp(wrapper->
key, key)) {
137 if (!strcasecmp(state,
"Registered")) {
139 }
else if (!strcasecmp(state,
"Rejected")) {
164 ast_debug(1,
"Unable to convert presumed registry object %p to strings; bailing on delete\n", obj);
168 for (it_fields = fields; it_fields; it_fields = it_fields->
next) {
169 if (strcasecmp(it_fields->
name,
"client_uri")) {
176 if (strcmp(wrapper->
key, it_fields->
value)) {
180 ast_debug(1,
"Registration metric '%s' deleted; purging with prejudice\n", wrapper->
key);
222 if (strcmp(object_type,
"registration")) {
230 .
name =
"client_uri",
231 .value = wrapper->
key,
236 ast_debug(1,
"Checking for the existance of registration metric %s\n", wrapper->
key);
239 ast_debug(1,
"Registration metric '%s' not found; purging with prejudice\n", wrapper->
key);
278 "asterisk_pjsip_outbound_registration_status",
279 "Current registration status. 0=Unregistered; 1=Registered; 2=Rejected.",
300 wrapper = create_wrapper(username);
310 *(wrapper->
metric) = metric;
325 #ifdef HAVE_PJPROJECT 338 .
name =
"pjsip_outbound_registration",
346 #ifdef HAVE_PJPROJECT 366 #ifdef HAVE_PJPROJECT struct ast_variable * next
Asterisk main include file. File version handling, generic pbx functions.
An actual, honest to god, metric.
void(* deleted)(const void *object)
Callback for when an object is deleted.
int prometheus_metric_register(struct prometheus_metric *metric)
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
int pjsip_outbound_registration_metrics_init(void)
Initialize PJSIP outbound registration metrics.
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
int ast_sorcery_instance_observer_add(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Add an observer to a sorcery instance.
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.
struct prometheus_metric * metric
The actual metric. Worth noting that we do NOT own the metric, as it is registered with res_prometheu...
void stasis_message_router_unsubscribe_and_join(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic, blocking until the final message has been processed...
static void registry_message_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Structure for variables, used for configurations and for channel variables.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Full structure for sorcery.
#define ast_mutex_lock(a)
int prometheus_metric_unregister(struct prometheus_metric *metric)
Remove a registered metric.
static AST_VECTOR(struct prometheus_metric_wrapper *)
#define PROMETHEUS_METRIC_STATIC_INITIALIZATION(mtype, n, h, cb)
Convenience macro for initializing a metric on the stack.
static void registration_loaded_observer(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
static const struct ast_sorcery_instance_observer observer_callbacks_registrations
#define ast_debug(level,...)
Log a DEBUG message.
#define PROMETHEUS_METRIC_SET_LABEL(metric, label, n, v)
Convenience macro for setting a label / value in a metric.
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
static const struct ast_sorcery_observer registration_observer
Interface for the sorcery instance observer.
#define ao2_ref(o, delta)
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
struct prometheus_metric * prometheus_gauge_create(const char *name, const char *help)
Create a malloc'd gauge metric.
#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.
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.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
Interface for a sorcery object type observer.
struct stasis_message_type * ast_system_registry_type(void)
A stasis_message_type for outbound registration.
char value[PROMETHEUS_MAX_VALUE_LENGTH]
The current value.
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes. ...
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
const char * help
Pointer to a static string defining this metric's help text.
#define ast_calloc(num, len)
A wrapper for calloc()
static int registration_state_to_int(const char *state)
char key[128]
Unique key to look up the metric.
static void registration_deleted_observer(const void *obj)
static void * cleanup(void *unused)
const char * name
Handy name of the provider for debugging purposes.
static struct prometheus_metric_wrapper * get_wrapper(const char *key)
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
char name[PROMETHEUS_MAX_NAME_LENGTH]
Our metric name.
static ast_mutex_t metrics_lock
struct ast_eid ast_eid_default
Global EID.
void(* object_type_loaded)(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
Callback after any object_type is loaded/reloaded.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
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.
static struct ast_sorcery * sorcery
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
A function table for a metrics provider.
ast_mutex_t lock
A lock protecting the metric value.
static const char channel_type[]
struct stasis_forward * sub
Abstract JSON element (object, array, string, int, ...).
static struct prometheus_metrics_provider provider
#define AST_VECTOR_REMOVE(vec, idx, preserve_ordered)
Remove an element from a vector by index.
static void pjsip_outbound_registration_metrics_unload_cb(void)
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_MUTEX_DEFINE_STATIC(mutex)
#define ast_mutex_unlock(a)