Browse Source

statsd: functions exported to kemi interface

Daniel-Constantin Mierla 8 years ago
parent
commit
d4c392fa4b
1 changed files with 76 additions and 0 deletions
  1. 76 0
      src/modules/statsd/statsd.c

+ 76 - 0
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;
+}