39 #include "asterisk/stasis_message_router.h"
40 #include "asterisk/statsd.h"
47 switch (snapshot->
state) {
49 ast_statsd_log_string(
"endpoints.state.unknown", AST_STATSD_GAUGE, delta, 1.0);
52 ast_statsd_log_string(
"endpoints.state.offline", AST_STATSD_GAUGE, delta, 1.0);
55 ast_statsd_log_string(
"endpoints.state.online", AST_STATSD_GAUGE, delta, 1.0);
62 if (!old_snapshot && new_snapshot) {
63 ast_statsd_log_string(
"endpoints.count", AST_STATSD_GAUGE,
"+1", 1.0);
64 update_endpoint_state(new_snapshot,
"+1");
65 }
else if (old_snapshot && !new_snapshot) {
66 ast_statsd_log_string(
"endpoints.count", AST_STATSD_GAUGE,
"-1", 1.0);
67 update_endpoint_state(old_snapshot,
"-1");
69 if (old_snapshot->
state != new_snapshot->
state) {
70 update_endpoint_state(old_snapshot,
"-1");
71 update_endpoint_state(new_snapshot,
"+1");
73 ast_statsd_log_full_va(
"endpoints.%s.%s.channels", AST_STATSD_GAUGE, new_snapshot->
num_channels, 1.0,
92 handle_endpoint_update(old_snapshot, new_snapshot);
95 static int dump_cache_load(
void *obj,
void *arg,
int flags)
100 handle_endpoint_update(NULL, snapshot);
105 static int dump_cache_unload(
void *obj,
void *arg,
int flags)
110 handle_endpoint_update(snapshot, NULL);
115 static int load_module(
void)
134 static int unload_module(
void)
150 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"Endpoint statistics",
151 .support_level = AST_MODULE_SUPPORT_EXTENDED,
153 .unload = unload_module,
154 .requires =
"res_statsd"
Asterisk main include file. File version handling, generic pbx functions.
struct stasis_message * old_snapshot
Old value from the cache.
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.
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
struct stasis_message_type * ast_endpoint_snapshot_type(void)
Message type for ast_endpoint_snapshot.
Assume that the ao2_container is already locked.
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.
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_topic * ast_endpoint_topic_all_cached(void)
Cached topic for all endpoint related messages.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
const ast_string_field resource
struct stasis_message_type * stasis_cache_update_type(void)
Message type for cache update messages.
A snapshot of an endpoint's state.
struct stasis_message * new_snapshot
New value.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
const ast_string_field tech
struct stasis_message_type * type
Convenience reference to snapshot type.
static struct stasis_rest_handlers endpoints
REST handler for /api-docs/endpoints.json.
Module has failed to load, may be in an inconsistent state.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
enum ast_endpoint_state state
struct stasis_cache * ast_endpoint_cache(void)
Backend cache for ast_endpoint_topic_all_cached().