summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2dd0f90)
raw | patch | inline | side by side (parent: 2dd0f90)
author | Florian Forster <octo@collectd.org> | |
Mon, 17 Jun 2013 13:15:55 +0000 (15:15 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 17 Jun 2013 13:16:41 +0000 (15:16 +0200) |
This more closely mimicks Etsy's implementation.
src/statsd.c | patch | blob | history |
diff --git a/src/statsd.c b/src/statsd.c
index 0c6fc8768e8acd853c8b5d540702e250f5592460..5457c33f90d22eea9582947cd95b3836326bf058 100644 (file)
--- a/src/statsd.c
+++ b/src/statsd.c
}
DEBUG ("stats plugin: Adding new metric \"%s\".", name);
- /* FIXME: The keys should have a prefix so counter, gauge and timer with the
- * same name can exist. */
key = strdup (name);
metric = calloc (1, sizeof (*metric));
if ((key == NULL) || (metric == NULL))
char const *value_str,
char const *extra)
{
+ char key[DATA_MAX_NAME_LEN + 2];
value_t value;
value_t scale;
int status;
if (value.derive < 1)
return (-1);
- return (statsd_metric_add (name,
+ ssnprintf (key, sizeof (key), "c:%s", name);
+
+ return (statsd_metric_add (key,
(int64_t) (((gauge_t) value.derive) / scale.gauge),
STATSD_COUNTER));
} /* }}} int statsd_handle_counter */
static int statsd_handle_gauge (char const *name, /* {{{ */
char const *value_str)
{
+ char key[DATA_MAX_NAME_LEN + 2];
value_t value;
int status;
if (status != 0)
return (status);
+ ssnprintf (key, sizeof (key), "g:%s", name);
+
if ((value_str[0] == '+') || (value_str[0] == '-'))
- return (statsd_metric_add (name, (int64_t) value.derive, STATSD_GAUGE));
+ return (statsd_metric_add (key, (int64_t) value.derive, STATSD_GAUGE));
else
- return (statsd_metric_set (name, (int64_t) value.derive, STATSD_GAUGE));
+ return (statsd_metric_set (key, (int64_t) value.derive, STATSD_GAUGE));
} /* }}} int statsd_handle_gauge */
static int statsd_handle_timer (char const *name, /* {{{ */
char const *value_str)
{
+ char key[DATA_MAX_NAME_LEN + 2];
value_t value;
int status;
if (status != 0)
return (status);
- return (statsd_metric_add (name, (int64_t) value.derive, STATSD_TIMER));
+ ssnprintf (key, sizeof (key), "t:%s", name);
+
+ return (statsd_metric_add (key, (int64_t) value.derive, STATSD_TIMER));
} /* }}} int statsd_handle_timer */
static int statsd_handle_set (char const *name __attribute__((unused)), /* {{{ */
continue;
}
- statsd_metric_submit (name, metric);
+ /* Names have a prefix, e.g. "c:", which determines the (statsd) type.
+ * Remove this here. */
+ statsd_metric_submit (name + 2, metric);
metric->updates_num = 0;
}
c_avl_iterator_destroy (iter);