From 68b351ca056365a2e3c8b78a6fc86ea99811e25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Harasimowicz?= Date: Tue, 20 Dec 2016 14:03:31 +0100 Subject: [PATCH] Fixing consul with multiple health checks per service (#1994) * plugins/input/consul: moved check_id from regular fields to tags. When service has more than one check sending data for both would overwrite each other resulting only in one check being written (the last one). Adding check_id as a tag ensures we will get info for all unique checks per service. * plugins/inputs/consul: updated tests --- plugins/inputs/consul/README.md | 6 +++--- plugins/inputs/consul/consul.go | 2 +- plugins/inputs/consul/consul_test.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/consul/README.md b/plugins/inputs/consul/README.md index a2685e2bf..01a39cbf7 100644 --- a/plugins/inputs/consul/README.md +++ b/plugins/inputs/consul/README.md @@ -29,9 +29,9 @@ to query the data. It will not report the [telemetry](https://www.consul.io/docs Tags: - node: on which node check/service is registered on - service_name: name of the service (this is the service name not the service ID) +- check_id Fields: -- check_id - check_name - service_id - status @@ -41,6 +41,6 @@ Fields: ``` $ telegraf --config ./telegraf.conf -input-filter consul -test * Plugin: consul, Collection 1 -> consul_health_checks,host=wolfpit,node=consul-server-node check_id="serfHealth",check_name="Serf Health Status",service_id="",status="passing" 1464698464486439902 -> consul_health_checks,host=wolfpit,node=consul-server-node,service_name=www.example.com check_id="service:www-example-com.test01",check_name="Service 'www.example.com' check",service_id="www-example-com.test01",status="critical" 1464698464486519036 +> consul_health_checks,host=wolfpit,node=consul-server-node,check_id="serfHealth" check_name="Serf Health Status",service_id="",status="passing" 1464698464486439902 +> consul_health_checks,host=wolfpit,node=consul-server-node,service_name=www.example.com,check_id="service:www-example-com.test01" check_name="Service 'www.example.com' check",service_id="www-example-com.test01",status="critical" 1464698464486519036 ``` diff --git a/plugins/inputs/consul/consul.go b/plugins/inputs/consul/consul.go index eaeae73c1..4c28f4d12 100644 --- a/plugins/inputs/consul/consul.go +++ b/plugins/inputs/consul/consul.go @@ -95,13 +95,13 @@ func (c *Consul) GatherHealthCheck(acc telegraf.Accumulator, checks []*api.Healt record := make(map[string]interface{}) tags := make(map[string]string) - record["check_id"] = check.CheckID record["check_name"] = check.Name record["service_id"] = check.ServiceID record["status"] = check.Status tags["node"] = check.Node tags["service_name"] = check.ServiceName + tags["check_id"] = check.CheckID acc.AddFields("consul_health_checks", record, tags) } diff --git a/plugins/inputs/consul/consul_test.go b/plugins/inputs/consul/consul_test.go index 772ccba91..f970d4449 100644 --- a/plugins/inputs/consul/consul_test.go +++ b/plugins/inputs/consul/consul_test.go @@ -22,7 +22,6 @@ var sampleChecks = []*api.HealthCheck{ func TestGatherHealtCheck(t *testing.T) { expectedFields := map[string]interface{}{ - "check_id": "foo.health123", "check_name": "foo.health", "status": "passing", "service_id": "foo.123", @@ -31,6 +30,7 @@ func TestGatherHealtCheck(t *testing.T) { expectedTags := map[string]string{ "node": "localhost", "service_name": "foo", + "check_id": "foo.health123", } var acc testutil.Accumulator