[asterisk-commits] StatsD: Send stuff to the StatsD server and test (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 2 15:11:10 CST 2015


Joshua Colp has submitted this change and it was merged.

Change subject: StatsD: Send stuff to the StatsD server and test
......................................................................


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
---
M apps/app_statsd.c
1 file changed, 12 insertions(+), 3 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/apps/app_statsd.c b/apps/app_statsd.c
index 77e5116..176796f 100644
--- a/apps/app_statsd.c
+++ b/apps/app_statsd.c
@@ -33,6 +33,7 @@
 #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 @@
 {
 	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 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 @@
 		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 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 @@
 		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;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/1542
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I400db2f37c6ddf61515ff5a019646e36dcd0f922
Gerrit-PatchSet: 5
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Tyler Cambron <tcambron at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list