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);
85 .name =
"asterisk_channels_state",
90 .name =
"asterisk_channels_duration_seconds",
112 "asterisk_calls_sum",
118 "asterisk_calls_count",
119 "Current call count.",
142 "asterisk_channels_count",
143 "Current channel count.",
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) {
198 if (snapshot->
peer) {
219 .
name =
"Channels callback",
struct ast_channel_snapshot_base * base
Asterisk main include file. File version handling, generic pbx functions.
static void get_channel_duration(struct prometheus_metric *metric, struct ast_channel_snapshot *snapshot)
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.
static void get_current_call_count(struct prometheus_metric *metric)
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
int prometheus_callback_register(struct prometheus_callback *callback)
#define ao2_container_clone(orig, flags)
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().
#define CHANNELS_STATE_HELP
void(* get_metric_value)(struct prometheus_metric *metric)
const ast_string_field type
#define PROMETHEUS_METRIC_STATIC_INITIALIZATION(mtype, n, h, cb)
Convenience macro for initializing a metric on the stack.
static void channel_metrics_unload_cb(void)
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)
struct timeval creationtime
static struct channel_usage channels
void prometheus_metrics_provider_register(const struct prometheus_metrics_provider *provider)
Register a metrics provider.
struct ao2_container * ast_channel_cache_all(void)
Core PBX routines and definitions.
struct prometheus_metric::@312 children
A list of children metrics.
static void channels_scrape_cb(struct ast_str **response)
int ast_processed_calls(void)
Retrieve the total number of calls processed through the PBX since last restart.
static void get_channel_state(struct prometheus_metric *metric, struct ast_channel_snapshot *snapshot)
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
int channel_metrics_init(void)
Initialize channel metrics.
#define ao2_iterator_next(iter)
char value[PROMETHEUS_MAX_VALUE_LENGTH]
The current value.
static void get_total_call_count(struct prometheus_metric *metric)
const char * help
Pointer to a static string defining this metric's help text.
#define ast_calloc(num, len)
A wrapper for calloc()
struct prometheus_callback channels_callback
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.
struct ast_eid ast_eid_default
Global EID.
#define CHANNELS_DURATION_HELP
static struct ao2_container * channel_cache
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.
static struct prometheus_metric global_channel_metrics[]
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.
static struct prometheus_metrics_provider provider
const ast_string_field name
const char * name
Name of the metric.