Skip to content

Commit

Permalink
Fixing consul with multiple health checks per service (#1994)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
harnash authored and sparrc committed Dec 20, 2016
1 parent 4e808c5 commit 48ae105
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions plugins/inputs/consul/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
2 changes: 1 addition & 1 deletion plugins/inputs/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/consul/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit 48ae105

Please sign in to comment.