From: Pierre-Yves Ritschard Date: Mon, 28 Oct 2013 13:31:16 +0000 (-0700) Subject: Merge pull request #459 from pyr/feature-riemann-attributes X-Git-Tag: collectd-5.5.0~336 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=163fd735366af79a8c1422945e4665fe9ee735b9;hp=a9e54292e518c37f457a1f239c5c7e52d18731cb;p=collectd.git Merge pull request #459 from pyr/feature-riemann-attributes Add support for custom attributes. --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index d4d5a205..4542a4b5 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1177,6 +1177,7 @@ # AlwaysAppendDS false # # Tag "foobar" +# Attribute "foo" "bar" # ############################################################################## diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 691a7494..fe72534e 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -6288,6 +6288,7 @@ Synopsis: TTLFactor 2.0 Tag "foobar" + Attribute "foo" "bar" The following options are understood by the I: @@ -6348,6 +6349,11 @@ default value. Add the given string as an additional tag to the metric being sent to I. +=item B I I + +Consider the two given strings to be the key and value of an additional +attribute for each metric being sent out to I. + =back =head1 THRESHOLD CONFIGURATION diff --git a/src/write_riemann.c b/src/write_riemann.c index 0bd8e3a0..3a7738f6 100644 --- a/src/write_riemann.c +++ b/src/write_riemann.c @@ -57,6 +57,8 @@ struct riemann_host { static char **riemann_tags; static size_t riemann_tags_num; +static char **riemann_attrs; +static size_t riemann_attrs_num; static void riemann_event_protobuf_free (Event *event) /* {{{ */ { @@ -422,6 +424,11 @@ static Msg *riemann_notification_to_protobuf (struct riemann_host *host, /* {{{ riemann_event_add_attribute (event, "type_instance", n->type_instance); + for (i = 0; i < riemann_attrs_num; i += 2) + riemann_event_add_attribute(event, + riemann_attrs[i], + riemann_attrs[i +1]); + for (i = 0; i < riemann_tags_num; i++) riemann_event_add_tag (event, riemann_tags[i]); @@ -511,6 +518,11 @@ static Event *riemann_value_to_protobuf (struct riemann_host const *host, /* {{{ riemann_event_add_attribute (event, "ds_index", ds_index); } + for (i = 0; i < riemann_attrs_num; i += 2) + riemann_event_add_attribute(event, + riemann_attrs[i], + riemann_attrs[i +1]); + for (i = 0; i < riemann_tags_num; i++) riemann_event_add_tag (event, riemann_tags[i]); @@ -845,6 +857,32 @@ riemann_config(oconfig_item_t *ci) if (strcasecmp("Node", child->key) == 0) { riemann_config_node (child); + } else if (strcasecmp(child->key, "attribute") == 0) { + char *key = NULL; + char *val = NULL; + + if (child->values_num != 2) { + WARNING("riemann attributes need both a key and a value."); + return (-1); + } + if (child->values[0].type != OCONFIG_TYPE_STRING || + child->values[1].type != OCONFIG_TYPE_STRING) { + WARNING("riemann attribute needs string arguments."); + return (-1); + } + if ((key = strdup(child->values[0].value.string)) == NULL) { + WARNING("cannot allocate memory for attribute key."); + return (-1); + } + if ((val = strdup(child->values[1].value.string)) == NULL) { + WARNING("cannot allocate memory for attribute value."); + return (-1); + } + strarray_add(&riemann_attrs, &riemann_attrs_num, key); + strarray_add(&riemann_attrs, &riemann_attrs_num, val); + DEBUG("write_riemann: got attr: %s => %s", key, val); + sfree(key); + sfree(val); } else if (strcasecmp(child->key, "tag") == 0) { char *tmp = NULL; status = cf_util_get_string(child, &tmp);