[asterisk-commits] dlee: branch dlee/stasis-demo r386048 - in /team/dlee/stasis-demo: include/as...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 18 23:56:03 CDT 2013


Author: dlee
Date: Thu Apr 18 23:55:59 2013
New Revision: 386048

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386048
Log:
Statsd units are more flexible than I thought.

Modified:
    team/dlee/stasis-demo/include/asterisk/statsd.h
    team/dlee/stasis-demo/res/res_statsd.c

Modified: team/dlee/stasis-demo/include/asterisk/statsd.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-demo/include/asterisk/statsd.h?view=diff&rev=386048&r1=386047&r2=386048
==============================================================================
--- team/dlee/stasis-demo/include/asterisk/statsd.h (original)
+++ team/dlee/stasis-demo/include/asterisk/statsd.h Thu Apr 18 23:55:59 2013
@@ -28,19 +28,16 @@
 
 #include "asterisk/optional_api.h"
 
-/*! Types of measurements */
-enum ast_statsd_type {
-	/*! An instantaneous measurement of a value. */
-	AST_STATSD_GUAGE,
-	/*! A change in a value. */
-	AST_STATSD_COUNTER,
-	/*! Measure of milliseconds. */
-	AST_STATSD_TIMER,
-	/*! Distribution of values over time. */
-	AST_STATSD_HISTOGRAM,
-	/*! Events over time. Sorta like increment-only counters. */
-	AST_STATSD_METER,
-};
+/*! An instantaneous measurement of a value. */
+#define AST_STATSD_GUAGE "g"
+/*! A change in a value. */
+#define AST_STATSD_COUNTER "c"
+/*! Measure of milliseconds. */
+#define AST_STATSD_TIMER "ms"
+/*! Distribution of values over time. */
+#define AST_STATSD_HISTOGRAM "h"
+/*! Events over time. Sorta like increment-only counters. */
+#define AST_STATSD_METER "m"
 
 /*!
  * \brief Send a stat to the configured statsd server.
@@ -56,7 +53,7 @@
  * \since 12
  */
 AST_OPTIONAL_API(void, ast_statsd_log_full, (const char *metric_name,
-	const char *type_str, intmax_t value, double sample_rate), {});
+	const char *metric_type, intmax_t value, double sample_rate), {});
 
 /*!
  * \brief Send a stat to the configured statsd server.
@@ -66,7 +63,7 @@
  * \since 12
  */
 AST_OPTIONAL_API(void, ast_statsd_log, (const char *metric_name,
-	enum ast_statsd_type metric_type, intmax_t value), {});
+	const char *metric_type, intmax_t value), {});
 
 /*!
  * \brief Send a random sampling of a stat to the configured statsd server.

Modified: team/dlee/stasis-demo/res/res_statsd.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-demo/res/res_statsd.c?view=diff&rev=386048&r1=386047&r2=386048
==============================================================================
--- team/dlee/stasis-demo/res/res_statsd.c (original)
+++ team/dlee/stasis-demo/res/res_statsd.c Thu Apr 18 23:55:59 2013
@@ -97,10 +97,8 @@
 	}
 }
 
-static const char *type_to_str(enum ast_statsd_type type);
-
 void AST_OPTIONAL_API_NAME(ast_statsd_log_full)(const char *metric_name,
-	const char *type_str, intmax_t value, double sample_rate)
+	const char *metric_type, intmax_t value, double sample_rate)
 {
 	RAII_VAR(struct conf *, cfg, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_str *, msg, NULL, ast_free);
@@ -134,7 +132,7 @@
 		ast_str_append(&msg, 0, "%s.", cfg->global->prefix);
 	}
 
-	ast_str_append(&msg, 0, "%s:%jd|%s", metric_name, value, type_str);
+	ast_str_append(&msg, 0, "%s:%jd|%s", metric_name, value, metric_type);
 
 	if (sample_rate < 1.0) {
 		ast_str_append(&msg, 0, "|@%.2f", sample_rate);
@@ -151,15 +149,15 @@
 }
 
 void AST_OPTIONAL_API_NAME(ast_statsd_log)(const char *metric_name,
-	enum ast_statsd_type metric_type, intmax_t value)
-{
-	ast_statsd_log_full(metric_name, type_to_str(metric_type), value, 1.0);
+	const char *metric_type, intmax_t value)
+{
+	ast_statsd_log_full(metric_name, metric_type, value, 1.0);
 }
 
 void AST_OPTIONAL_API_NAME(ast_statsd_log_sample)(const char *metric_name,
 	intmax_t value, double sample_rate)
 {
-	ast_statsd_log_full(metric_name, type_to_str(AST_STATSD_COUNTER), value,
+	ast_statsd_log_full(metric_name, AST_STATSD_COUNTER, value,
 		sample_rate);
 }
 
@@ -214,25 +212,6 @@
 {
 	RAII_VAR(struct conf *, cfg, ao2_global_obj_ref(confs), ao2_cleanup);
 	return cfg->global->enabled;
-}
-
-static const char *type_to_str(enum ast_statsd_type type)
-{
-	switch (type) {
-	case AST_STATSD_GUAGE:
-		return "g";
-	case AST_STATSD_COUNTER:
-		return "c";
-	case AST_STATSD_TIMER:
-		return "ms";
-	case AST_STATSD_HISTOGRAM:
-		return "h";
-	case AST_STATSD_METER:
-		return "m";
-	}
-
-	ast_assert(0);
-	return "?";
 }
 
 static int statsd_init(void)




More information about the asterisk-commits mailing list