30 #include "asterisk/stasis_channels.h"
34 #define CHANNELS_STATE_HELP "Individual channel states. 0=down; 1=reserved; 2=offhook; 3=dialing; 4=ring; 5=ringing; 6=up; 7=busy; 8=dialing_offhook; 9=prering."
36 #define CHANNELS_DURATION_HELP "Individual channel durations (in seconds)."
62 snprintf(metric->
value,
sizeof(metric->
value),
"%" PRIu64, duration);
84 .
help = CHANNELS_STATE_HELP,
85 .name =
"asterisk_channels_state",
86 .get_value = get_channel_state,
89 .help = CHANNELS_DURATION_HELP,
90 .name =
"asterisk_channels_duration_seconds",
91 .get_value = get_channel_duration,
112 "asterisk_calls_sum",
114 &get_total_call_count
118 "asterisk_calls_count",
119 "Current call count.",
120 &get_current_call_count
130 static void channels_scrape_cb(
struct ast_str **response)
142 "asterisk_channels_count",
143 "Current channel count.",
149 channel_cache = ast_channel_cache_all();
150 if (!channel_cache) {
164 snprintf(channel_count.
value,
sizeof(channel_count.
value),
"%d", num_channels);
168 for (i = 0; i < ARRAY_LEN(global_channel_metrics); i++) {
174 if (num_channels == 0) {
181 if (!channel_metrics) {
187 for (i = 0; (snapshot = ao2_iterator_next(&it_chans));
ao2_ref(snapshot, -1), i++) {
198 if (snapshot->
peer) {
214 ast_free(channel_metrics);
219 .
name =
"Channels callback",
220 .callback_fn = channels_scrape_cb,
227 static void channel_metrics_unload_cb(
void)
238 .unload_cb = channel_metrics_unload_cb,
struct ast_channel_snapshot_base * base
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.
int ast_active_calls(void)
Retrieve the number of active calls.
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.
int64_t ast_tvdiff_sec(struct timeval end, struct timeval start)
Computes the difference (in seconds) between two struct timeval instances.
A metric whose value always goes up.
Structure representing a snapshot of channel state.
const char * name
The name of our callback (always useful for debugging)
enum prometheus_metric_type type
What type of metric we are.
const ast_string_field uniqueid
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
void(*const get_value)(struct prometheus_metric *metric, struct ast_channel_snapshot *snapshot)
Callback function to generate a metric value for a given channel.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
void(* get_metric_value)(struct prometheus_metric *metric)
Callback function to obtain the metric value.
const ast_string_field type
#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.
struct prometheus_metric::@274 children
A list of children metrics.
struct timeval creationtime
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
Core PBX routines and definitions.
Asterisk Prometheus Metrics.
int ast_processed_calls(void)
Retrieve the total number of calls processed through the PBX since last restart.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Support for dynamic strings.
int channel_metrics_init(void)
Initialize channel metrics.
char value[PROMETHEUS_MAX_VALUE_LENGTH]
The current value.
const char * help
Pointer to a static string defining this metric's help text.
#define ast_calloc(num, len)
A wrapper for calloc()
enum ast_channel_state state
void prometheus_callback_unregister(struct prometheus_callback *callback)
Remove a registered callback.
const char * name
Handy name of the provider for debugging purposes.
char name[PROMETHEUS_MAX_NAME_LENGTH]
Our metric name.
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 ast_channel_snapshot_peer * peer
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.
const ast_string_field name
const char * name
Name of the metric.