summaryrefslogtreecommitdiff
path: root/res/res_statsd.c
diff options
context:
space:
mode:
authortcambron <tcambron@digium.com>2015-11-03 14:36:43 -0600
committertcambron <tcambron@digium.com>2015-11-04 14:59:12 -0600
commit379c041038b14b2adb53ad9b16c1268b389357e2 (patch)
tree01dd0b353b13026ad4bba2b270d30e76a1100f55 /res/res_statsd.c
parent40574a2ea31f03d5a4d3914f1e20895a9b49d7f0 (diff)
StatsD: Add res_statsd compatibility
Added a new api to res_statsd.c to allow it to receive a character pointer for the value argument. This allows for a '+' and a '-' to easily be sent with the value. ASTERISK-25419 Reported By: Ashley Sanders Change-Id: Id6bb53600943d27347d2bcae26c0bd5643567611
Diffstat (limited to 'res/res_statsd.c')
-rw-r--r--res/res_statsd.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/res/res_statsd.c b/res/res_statsd.c
index fefe395e8..8bf74db09 100644
--- a/res/res_statsd.c
+++ b/res/res_statsd.c
@@ -97,11 +97,11 @@ static void conf_server(const struct conf *cfg, struct ast_sockaddr *addr)
}
}
-void AST_OPTIONAL_API_NAME(ast_statsd_log_full)(const char *metric_name,
- const char *metric_type, intmax_t value, double sample_rate)
+void AST_OPTIONAL_API_NAME(ast_statsd_log_string)(const char *metric_name,
+ const char *metric_type, const char *value, double sample_rate)
{
- RAII_VAR(struct conf *, cfg, NULL, ao2_cleanup);
- RAII_VAR(struct ast_str *, msg, NULL, ast_free);
+ struct conf *cfg;
+ struct ast_str *msg;
size_t len;
struct ast_sockaddr statsd_server;
@@ -109,9 +109,6 @@ void AST_OPTIONAL_API_NAME(ast_statsd_log_full)(const char *metric_name,
return;
}
- cfg = ao2_global_obj_ref(confs);
- conf_server(cfg, &statsd_server);
-
/* Rates <= 0.0 never get logged.
* Rates >= 1.0 always get logged.
* All others leave it to chance.
@@ -122,9 +119,11 @@ void AST_OPTIONAL_API_NAME(ast_statsd_log_full)(const char *metric_name,
}
cfg = ao2_global_obj_ref(confs);
+ conf_server(cfg, &statsd_server);
msg = ast_str_create(40);
if (!msg) {
+ ao2_cleanup(cfg);
return;
}
@@ -132,7 +131,7 @@ void AST_OPTIONAL_API_NAME(ast_statsd_log_full)(const char *metric_name,
ast_str_append(&msg, 0, "%s.", cfg->global->prefix);
}
- ast_str_append(&msg, 0, "%s:%jd|%s", metric_name, value, metric_type);
+ ast_str_append(&msg, 0, "%s:%s|%s", metric_name, value, metric_type);
if (sample_rate < 1.0) {
ast_str_append(&msg, 0, "|@%.2f", sample_rate);
@@ -144,20 +143,39 @@ void AST_OPTIONAL_API_NAME(ast_statsd_log_full)(const char *metric_name,
len = ast_str_strlen(msg);
- ast_debug(6, "send: %s\n", ast_str_buffer(msg));
+ ast_debug(6, "Sending statistic %s to StatsD server\n", ast_str_buffer(msg));
ast_sendto(socket_fd, ast_str_buffer(msg), len, 0, &statsd_server);
+
+ ao2_cleanup(cfg);
+ ast_free(msg);
+}
+
+void AST_OPTIONAL_API_NAME(ast_statsd_log_full)(const char *metric_name,
+ const char *metric_type, intmax_t value, double sample_rate)
+{
+ char char_value[30];
+ snprintf(char_value, sizeof(char_value), "%jd", value);
+
+ ast_statsd_log_string(metric_name, metric_type, char_value, sample_rate);
+
}
void AST_OPTIONAL_API_NAME(ast_statsd_log)(const char *metric_name,
const char *metric_type, intmax_t value)
{
- ast_statsd_log_full(metric_name, metric_type, value, 1.0);
+ char char_value[30];
+ snprintf(char_value, sizeof(char_value), "%jd", value);
+
+ ast_statsd_log_string(metric_name, metric_type, char_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, AST_STATSD_COUNTER, value,
+ char char_value[30];
+ snprintf(char_value, sizeof(char_value), "%jd", value);
+
+ ast_statsd_log_string(metric_name, AST_STATSD_COUNTER, char_value,
sample_rate);
}