#include "asterisk.h"
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
#include "asterisk/module.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_message_router.h"
* \param message The message itself.
*/
static void statsmaker(void *data, struct stasis_subscription *sub,
- struct stasis_topic *topic, struct stasis_message *message)
+ struct stasis_message *message)
{
RAII_VAR(struct ast_str *, metric, NULL, ast_free);
* \param message The message itself.
*/
static void updates(void *data, struct stasis_subscription *sub,
- struct stasis_topic *topic, struct stasis_message *message)
+ struct stasis_message *message)
{
/* Since this came from a message router, we know the type of the
* message. We can cast the data without checking its type.
if (!update->old_snapshot && update->new_snapshot) {
/* Initial cache entry; count a channel creation */
- ast_statsd_log("channels.count", AST_STATSD_COUNTER, 1);
+ ast_statsd_log_string("channels.count", AST_STATSD_GAUGE, "+1", 1.0);
} else if (update->old_snapshot && !update->new_snapshot) {
/* Cache entry removed. Compute the age of the channel and post
* that, as well as decrementing the channel count.
ast_statsd_log("channels.calltime", AST_STATSD_TIMER, age);
/* And decrement the channel count */
- ast_statsd_log("channels.count", AST_STATSD_COUNTER, -1);
+ ast_statsd_log_string("channels.count", AST_STATSD_GAUGE, "-1", 1.0);
}
}
* \param message The message itself.
*/
static void default_route(void *data, struct stasis_subscription *sub,
- struct stasis_topic *topic, struct stasis_message *message)
+ struct stasis_message *message)
{
if (stasis_subscription_final_message(sub, message)) {
/* Much like with the regular subscription, you may need to
}
}
+static int unload_module(void)
+{
+ stasis_unsubscribe_and_join(sub);
+ sub = NULL;
+ stasis_message_router_unsubscribe_and_join(router);
+ router = NULL;
+ return 0;
+}
+
static int load_module(void)
{
/* You can create a message router to route messages by type */
router = stasis_message_router_create(
- stasis_caching_get_topic(ast_channel_topic_all_cached()));
+ ast_channel_topic_all_cached());
if (!router) {
- return AST_MODULE_LOAD_FAILURE;
+ return AST_MODULE_LOAD_DECLINE;
}
stasis_message_router_add(router, stasis_cache_update_type(),
updates, NULL);
/* Or a subscription to receive all of the messages from a topic */
sub = stasis_subscribe(ast_channel_topic_all(), statsmaker, NULL);
if (!sub) {
- return AST_MODULE_LOAD_FAILURE;
+ unload_module();
+ return AST_MODULE_LOAD_DECLINE;
}
return AST_MODULE_LOAD_SUCCESS;
}
-static int unload_module(void)
-{
- stasis_unsubscribe(sub);
- sub = NULL;
- stasis_message_router_unsubscribe(router);
- router = NULL;
- return 0;
-}
-
-AST_MODULE_INFO(ASTERISK_GPL_KEY,
- AST_MODFLAG_DEFAULT,
- "Example of how to use Stasis",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Example of how to use Stasis",
+ .support_level = AST_MODULE_SUPPORT_EXTENDED,
.load = load_module,
.unload = unload_module,
.nonoptreq = "res_statsd"
- );
+);