Module: kamailio Branch: master Commit: d4c392fa4bdf7316a24063df9ae1a615d94c1711 URL: https://github.com/kamailio/kamailio/commit/d4c392fa4bdf7316a24063df9ae1a615...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2017-05-03T08:37:39+02:00
statsd: functions exported to kemi interface
---
Modified: src/modules/statsd/statsd.c
---
Diff: https://github.com/kamailio/kamailio/commit/d4c392fa4bdf7316a24063df9ae1a615... Patch: https://github.com/kamailio/kamailio/commit/d4c392fa4bdf7316a24063df9ae1a615...
---
diff --git a/src/modules/statsd/statsd.c b/src/modules/statsd/statsd.c index c4c56ea..469f390 100644 --- a/src/modules/statsd/statsd.c +++ b/src/modules/statsd/statsd.c @@ -25,6 +25,7 @@ #include "../../core/usr_avp.h" #include "../../core/pvar.h" #include "../../core/lvalue.h" +#include "../../core/kemi.h" #include "lib_statsd.h"
@@ -118,11 +119,21 @@ static int func_gauge(struct sip_msg* msg, char* key, char* val) return statsd_gauge(key, val); }
+static int ki_statsd_gauge(sip_msg_t* msg, str* key, str* val) +{ + return statsd_gauge(key->s, val->s); +} + static int func_set(struct sip_msg* msg, char* key, char* val) { return statsd_set(key, val); }
+static int ki_statsd_set(sip_msg_t* msg, str* key, str* val) +{ + return statsd_set(key->s, val->s); +} + static int func_time_start(struct sip_msg *msg, char *key) { int_str avp_key, avp_val; @@ -141,6 +152,10 @@ static int func_time_start(struct sip_msg *msg, char *key) return 1; }
+static int ki_statsd_start(sip_msg_t *msg, str *key) +{ + return func_time_start(msg, key->s); +}
static int func_time_end(struct sip_msg *msg, char *key) { @@ -182,18 +197,30 @@ static int func_time_end(struct sip_msg *msg, char *key) return statsd_timing(key, result); }
+static int ki_statsd_stop(sip_msg_t *msg, str *key) +{ + return func_time_end(msg, key->s); +}
static int func_incr(struct sip_msg *msg, char *key) { return statsd_count(key, "+1"); }
+static int ki_statsd_incr(sip_msg_t *msg, str *key) +{ + return statsd_count(key->s, "+1"); +}
static int func_decr(struct sip_msg *msg, char *key) { return statsd_count(key, "-1"); }
+static int ki_statsd_decr(sip_msg_t *msg, str *key) +{ + return statsd_count(key->s, "-1"); +}
char* get_milliseconds(char *dst){ struct timeval tv; @@ -204,3 +231,52 @@ char* get_milliseconds(char *dst){ snprintf(dst, 21, "%ld", millis); return dst; } + +/** + * + */ +/* clang-format off */ +static sr_kemi_t sr_kemi_statsd_exports[] = { + { str_init("statsd"), str_init("statsd_gauge"), + SR_KEMIP_INT, ki_statsd_gauge, + { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("statsd"), str_init("statsd_start"), + SR_KEMIP_INT, ki_statsd_start, + { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("statsd"), str_init("statsd_stop"), + SR_KEMIP_INT, ki_statsd_stop, + { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("statsd"), str_init("statsd_incr"), + SR_KEMIP_INT, ki_statsd_incr, + { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("statsd"), str_init("statsd_decr"), + SR_KEMIP_INT, ki_statsd_decr, + { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("statsd"), str_init("statsd_set"), + SR_KEMIP_INT, ki_statsd_set, + { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + + { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } } +}; +/* clang-format on */ + +/** + * + */ +int mod_register(char *path, int *dlflags, void *p1, void *p2) +{ + sr_kemi_modules_add(sr_kemi_statsd_exports); + return 0; +} \ No newline at end of file