33 #define ENDPOINTS_STATE_HELP "Individual endpoint states. 0=unknown; 1=offline; 2=online."
35 #define ENDPOINTS_CHANNELS_COUNT_HELP "Count of the number of channels currently existing that are associated with the endpoint."
80 .
help = ENDPOINTS_STATE_HELP,
81 .name =
"asterisk_endpoints_state",
82 .get_value = get_endpoint_state,
85 .help = ENDPOINTS_CHANNELS_COUNT_HELP,
86 .name =
"asterisk_endpoints_channels_count",
87 .get_value = get_endpoint_channel_count,
97 static void endpoints_scrape_cb(
struct ast_str **response)
105 int i, j, num_endpoints;
108 "asterisk_endpoints_count",
109 "Current endpoint count.",
116 if (!endpoint_cache) {
129 snprintf(endpoint_count.
value,
sizeof(endpoint_count.
value),
"%d", num_endpoints);
132 if (num_endpoints == 0) {
138 if (!endpoint_metrics) {
145 for (i = 0; (message = ao2_iterator_next(&it_endpoints));
ao2_ref(message, -1), i++) {
171 ast_free(endpoint_metrics);
176 .
name =
"Endpoints callback",
177 .callback_fn = endpoints_scrape_cb,
184 static void endpoint_metrics_unload_cb(
void)
195 .unload_cb = endpoint_metrics_unload_cb,
Asterisk main include file. File version handling, generic pbx functions.
An actual, honest to god, metric.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
Prometheus Metric Internal API.
int prometheus_callback_register(struct prometheus_callback *callback)
#define ao2_container_clone(orig, flags)
Create a clone/copy of the given container.
struct stasis_message_type * ast_endpoint_snapshot_type(void)
Message type for ast_endpoint_snapshot.
const char * name
The name of our callback (always useful for debugging)
enum prometheus_metric_type type
What type of metric we are.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
int endpoint_metrics_init(void)
Initialize endpoint metrics.
const ast_string_field id
struct ao2_container * stasis_cache_dump(struct stasis_cache *cache, struct stasis_message_type *type)
Dump cached items to a subscription for the ast_eid_default entity.
#define PROMETHEUS_METRIC_STATIC_INITIALIZATION(mtype, n, h, cb)
Convenience macro for initializing a metric on the stack.
void prometheus_metric_to_string(struct prometheus_metric *metric, struct ast_str **output)
Convert a metric (and its children) into Prometheus compatible text.
const char * help
Help text to display.
#define PROMETHEUS_METRIC_SET_LABEL(metric, label, n, v)
Convenience macro for setting a label / value in a metric.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
const ast_string_field resource
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
A snapshot of an endpoint's state.
Asterisk Prometheus Metrics.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Support for dynamic strings.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
const ast_string_field tech
const char * name
Name of the metric.
char value[PROMETHEUS_MAX_VALUE_LENGTH]
The current value.
static struct stasis_rest_handlers endpoints
REST handler for /api-docs/endpoints.json.
const char * help
Pointer to a static string defining this metric's help text.
#define ast_calloc(num, len)
A wrapper for calloc()
void(*const get_value)(struct prometheus_metric *metric, struct ast_endpoint_snapshot *snapshot)
Callback function to generate a metric value for a given endpoint.
void prometheus_callback_unregister(struct prometheus_callback *callback)
Remove a registered callback.
const char * name
Handy name of the provider for debugging purposes.
struct ast_eid ast_eid_default
Global EID.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
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.
A metric whose value can bounce around like a jackrabbit.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
Defines a callback that will be invoked when the HTTP route is called.
enum ast_endpoint_state state
struct stasis_cache * ast_endpoint_cache(void)
Backend cache for ast_endpoint_topic_all_cached().