53struct prometheus_metric_wrapper {
89static struct prometheus_metric_wrapper *create_wrapper(
const char *key)
91 struct prometheus_metric_wrapper *wrapper;
111static struct prometheus_metric_wrapper *get_wrapper(
const char *key)
119 if (!strcmp(wrapper->key, key)) {
135static int registration_state_to_int(
const char *
state)
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.",
282 struct prometheus_metric_wrapper *wrapper;
291 snprintf(metric.
value,
sizeof(metric.
value),
"%d", registration_state_to_int(status_str));
293 wrapper = get_wrapper(username);
297 strcpy(wrapper->metric->value, metric.
value);
300 wrapper = create_wrapper(username);
306 if (!wrapper->metric) {
310 *(wrapper->metric) = metric;
338 .
name =
"pjsip_outbound_registration",
Asterisk main include file. File version handling, generic pbx functions.
#define ast_calloc(num, len)
A wrapper for calloc()
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
static const char channel_type[]
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
#define ast_debug(level,...)
Log a DEBUG message.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
#define ast_mutex_unlock(a)
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
#define ast_mutex_lock(a)
#define AST_MUTEX_DEFINE_STATIC(mutex)
static void * cleanup(void *unused)
int pjsip_outbound_registration_metrics_init(void)
Initialize PJSIP outbound registration metrics.
static struct prometheus_metrics_provider provider
static void pjsip_outbound_registration_metrics_unload_cb(void)
Prometheus Metric Internal API.
static struct stasis_message_router * router
struct stasis_forward * sub
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 void registration_deleted_observer(const void *obj)
static const struct ast_sorcery_observer registration_observer
static void registration_loaded_observer(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
static struct ast_sorcery * sorcery
Asterisk Prometheus Metrics.
int prometheus_metric_unregister(struct prometheus_metric *metric)
Remove a registered metric.
#define PROMETHEUS_METRIC_SET_LABEL(metric, label, n, v)
Convenience macro for setting a label / value in a metric.
int prometheus_metric_register(struct prometheus_metric *metric)
#define PROMETHEUS_METRIC_STATIC_INITIALIZATION(mtype, n, h, cb)
Convenience macro for initializing a metric on the stack.
@ PROMETHEUS_METRIC_GAUGE
A metric whose value can bounce around like a jackrabbit.
struct prometheus_metric * prometheus_gauge_create(const char *name, const char *help)
Create a malloc'd gauge metric.
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
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.
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
void ast_sorcery_instance_observer_remove(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Remove an observer from a sorcery instance.
@ AST_RETRIEVE_FLAG_DEFAULT
Default retrieval flags.
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.
int ast_sorcery_instance_observer_add(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Add an observer to a sorcery instance.
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.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#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.
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.
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.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Abstract JSON element (object, array, string, int, ...).
Interface for the sorcery instance observer.
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.
Interface for a sorcery object type observer.
void(* deleted)(const void *object)
Callback for when an object is deleted.
Full structure for sorcery.
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
An actual, honest to god, metric.
char name[PROMETHEUS_MAX_NAME_LENGTH]
Our metric name.
const char * help
Pointer to a static string defining this metric's help text.
char value[PROMETHEUS_MAX_VALUE_LENGTH]
The current value.
A function table for a metrics provider.
const char * name
Handy name of the provider for debugging purposes.
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
struct ast_eid ast_eid_default
Global EID.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_REMOVE(vec, idx, preserve_ordered)
Remove an element from a vector by index.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
#define AST_VECTOR(name, type)
Define a vector structure.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.