From cc530ae1a0a720a44d7a8297bb87c833e1e31066 Mon Sep 17 00:00:00 2001 From: david birdsong Date: Tue, 8 Mar 2016 18:33:57 +0000 Subject: [PATCH] special case 'value' it usually connotes a single value type metric, appending just clutters --- plugins/outputs/prometheus_client/prometheus_client.go | 7 ++++++- .../outputs/prometheus_client/prometheus_client_test.go | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/outputs/prometheus_client/prometheus_client.go b/plugins/outputs/prometheus_client/prometheus_client.go index 50a9224cd..f13fe726c 100644 --- a/plugins/outputs/prometheus_client/prometheus_client.go +++ b/plugins/outputs/prometheus_client/prometheus_client.go @@ -79,7 +79,12 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error { } for n, val := range point.Fields() { - mname := fmt.Sprintf("%s_%s", key, n) + var mname string + if n == "value" { + mname = key + } else { + mname = fmt.Sprintf("%s_%s", key, n) + } if _, ok := p.metrics[mname]; !ok { p.metrics[mname] = prometheus.NewUntypedVec( prometheus.UntypedOpts{ diff --git a/plugins/outputs/prometheus_client/prometheus_client_test.go b/plugins/outputs/prometheus_client/prometheus_client_test.go index 5793e1569..16414a8e4 100644 --- a/plugins/outputs/prometheus_client/prometheus_client_test.go +++ b/plugins/outputs/prometheus_client/prometheus_client_test.go @@ -46,8 +46,8 @@ func TestPrometheusWritePointEmptyTag(t *testing.T) { value float64 tags map[string]string }{ - {"test_point_1_value", 0.0, tags}, - {"test_point_2_value", 1.0, tags}, + {"test_point_1", 0.0, tags}, + {"test_point_2", 1.0, tags}, } var acc testutil.Accumulator @@ -78,8 +78,8 @@ func TestPrometheusWritePointEmptyTag(t *testing.T) { name string value float64 }{ - {"test_point_3_value", 0.0}, - {"test_point_4_value", 1.0}, + {"test_point_3", 0.0}, + {"test_point_4", 1.0}, } require.NoError(t, p.Gather(&acc))