summaryrefslogtreecommitdiff
path: root/apps/app_statsd.c
diff options
context:
space:
mode:
authortcambron <tcambron@digium.com>2015-10-29 15:25:32 -0500
committertcambron <tcambron@digium.com>2015-11-02 09:24:49 -0600
commitc5093b21ad6c43c33186e27c5170f868dfd91465 (patch)
tree2cb1fda9c21557470265ad717d836f0cc56f4b59 /apps/app_statsd.c
parentb522a5e30fa02f56346a228de946e4404e57468f (diff)
StatsD: Send stuff to the StatsD server and test
Added code to allow the StatsD dialplan application to send data to the server specified in statsd.conf. ASTERISK-25419 Change-Id: I400db2f37c6ddf61515ff5a019646e36dcd0f922
Diffstat (limited to 'apps/app_statsd.c')
-rw-r--r--apps/app_statsd.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/apps/app_statsd.c b/apps/app_statsd.c
index 77e511691..176796f37 100644
--- a/apps/app_statsd.c
+++ b/apps/app_statsd.c
@@ -33,6 +33,7 @@ ASTERISK_REGISTER_FILE()
#include "asterisk/app.h"
#include "asterisk/pbx.h"
#include "asterisk/strings.h"
+#include "asterisk/statsd.h"
/*** DOCUMENTATION
<application name="StatsD" language="en_US">
@@ -76,7 +77,7 @@ static int value_in_range(const char *value, const char *metric)
{
double numerical_value = strtod(value, NULL);
- if (!strcmp(metric, "counter")) {
+ if (!strcmp(metric, "c")) {
if (numerical_value < pow(-2, 63) || numerical_value > pow(2, 63)) {
ast_log(AST_LOG_WARNING, "Value %lf out of range!\n", numerical_value);
return 1;
@@ -104,7 +105,7 @@ static int value_in_range(const char *value, const char *metric)
*/
static int validate_metric(const char *metric)
{
- const char *valid_metrics[] = {"gauge","set","timer","counter"};
+ const char *valid_metrics[] = {"g","s","ms","c"};
int i;
if (ast_strlen_zero(metric)) {
@@ -168,7 +169,7 @@ static int validate_value(const char *value, const char *metric)
return 1;
}
- if (!strcmp(metric, "gauge") || !strcmp(metric, "counter")) {
+ if (!strcmp(metric, "g") || !strcmp(metric, "c")) {
if ((value[0] == '+') || (value[0] == '-')) {
actual_value = &value[1];
if (ast_strlen_zero(actual_value)) {
@@ -198,6 +199,7 @@ static int validate_value(const char *value, const char *metric)
static int statsd_exec(struct ast_channel *chan, const char *data)
{
char *stats;
+ double numerical_value;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(metric_type);
@@ -223,6 +225,13 @@ static int statsd_exec(struct ast_channel *chan, const char *data)
return 1;
}
+ /*
+ * Conversion to a double is safe here since the value would have been validated as a
+ * number in validate_value().
+ */
+ numerical_value = strtod(args.value, NULL);
+ ast_statsd_log(args.statistic_name, args.metric_type, numerical_value);
+
return 0;
}