From 8c555661ebe1dcc2b766a3fe8430ae0957727074 Mon Sep 17 00:00:00 2001 From: JamesClonk Date: Tue, 4 Oct 2016 13:47:20 +0200 Subject: [PATCH] add overwrite tags for Riemann --- CHANGELOG.md | 2 ++ etc/telegraf.conf | 3 ++- plugins/outputs/riemann/riemann.go | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00112391c..fe5ebc954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features +- [#1845](https://github.com/influxdata/telegraf/pull/1845): Send measurement as Riemann tag, add overwrite tags. - [#1782](https://github.com/influxdata/telegraf/pull/1782): Allow numeric and non-string values for tag_keys. - [#1694](https://github.com/influxdata/telegraf/pull/1694): Adding Gauge and Counter metric types. - [#1606](https://github.com/influxdata/telegraf/pull/1606): Remove carraige returns from exec plugin output on Windows @@ -29,6 +30,7 @@ ### Bugfixes +- [#1501](https://github.com/influxdata/telegraf/issues/1501): Send metric tags as Riemann tags and attributes. - [#1746](https://github.com/influxdata/telegraf/issues/1746): Fix handling of non-string values for JSON keys listed in tag_keys. - [#1628](https://github.com/influxdata/telegraf/issues/1628): Fix mongodb input panic on version 2.2. - [#1733](https://github.com/influxdata/telegraf/issues/1733): Fix statsd scientific notation parsing diff --git a/etc/telegraf.conf b/etc/telegraf.conf index d93002533..3dc5cb183 100644 --- a/etc/telegraf.conf +++ b/etc/telegraf.conf @@ -440,7 +440,8 @@ # separator = " " # ## set measurement name as a Riemann tag instead of prepending it to the Riemann service name # measurement_as_tag = false - +# ## list of Riemann tags, if specified use these instead of any Telegraf tags +# tags = ["telegraf","custom_tag"] ############################################################################### diff --git a/plugins/outputs/riemann/riemann.go b/plugins/outputs/riemann/riemann.go index 5d430bae0..44602705c 100644 --- a/plugins/outputs/riemann/riemann.go +++ b/plugins/outputs/riemann/riemann.go @@ -16,6 +16,7 @@ type Riemann struct { Transport string Separator string MeasurementAsTag bool + Tags []string client *raidman.Client } @@ -29,6 +30,8 @@ var sampleConfig = ` separator = " " ## set measurement name as a Riemann tag instead of prepending it to the Riemann service name measurement_as_tag = false + ## list of Riemann tags, if specified use these instead of any Telegraf tags + tags = ["telegraf","custom_tag"] ` func (r *Riemann) Connect() error { @@ -107,7 +110,7 @@ func (r *Riemann) buildEvents(p telegraf.Metric) []*raidman.Event { Host: host, Service: r.service(p.Name(), fieldName), Tags: r.tags(p.Name(), p.Tags()), - Attributes: p.Tags(), + Attributes: r.attributes(p.Name(), p.Tags()), Time: p.Time().Unix(), } @@ -125,7 +128,18 @@ func (r *Riemann) buildEvents(p telegraf.Metric) []*raidman.Event { return events } +func (r *Riemann) attributes(name string, tags map[string]string) map[string]string { + if r.MeasurementAsTag { + tags["measurement"] = name + } + return tags +} + func (r *Riemann) tags(name string, tags map[string]string) []string { + if len(r.Tags) > 0 { + return r.Tags + } + var tagNames, tagValues []string for tagName := range tags {