Skip to content

Commit 738cbbd

Browse files
johnrengelmansparrc
authored andcommitted
Add numerical representation of Consul health check state. (#2277)
1 parent 074e6d1 commit 738cbbd

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ It is highly recommended that all users migrate to the new riemann output plugin
1616
- [#2251](https://github.com/influxdata/telegraf/pull/2251): InfluxDB output: use own client for improved through-put and less allocations.
1717
- [#1900](https://github.com/influxdata/telegraf/pull/1900): Riemann plugin rewrite.
1818
- [#1453](https://github.com/influxdata/telegraf/pull/1453): diskio: add support for name templates and udev tags.
19+
- [#2277](https://github.com/influxdata/telegraf/pull/2277): add integer metrics for Consul check health state.
1920

2021
### Bugfixes
2122

plugins/inputs/consul/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,19 @@ Fields:
3535
- check_name
3636
- service_id
3737
- status
38+
- passing
39+
- critical
40+
- warning
41+
42+
`passing`, `critical`, and `warning` are integer representations of the health
43+
check state. A value of `1` represents that the status was the state of the
44+
the health check at this sample.
3845

3946
## Example output
4047

4148
```
4249
$ telegraf --config ./telegraf.conf -input-filter consul -test
4350
* Plugin: consul, Collection 1
44-
> consul_health_checks,host=wolfpit,node=consul-server-node,check_id="serfHealth" check_name="Serf Health Status",service_id="",status="passing" 1464698464486439902
45-
> 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
51+
> consul_health_checks,host=wolfpit,node=consul-server-node,check_id="serfHealth" check_name="Serf Health Status",service_id="",status="passing",passing=1i,critical=0i,warning=0i 1464698464486439902
52+
> 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",passing=0i,critical=1i,warning=0i 1464698464486519036
4653
```

plugins/inputs/consul/consul.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ func (c *Consul) GatherHealthCheck(acc telegraf.Accumulator, checks []*api.Healt
9797

9898
record["check_name"] = check.Name
9999
record["service_id"] = check.ServiceID
100+
100101
record["status"] = check.Status
102+
record["passing"] = 0
103+
record["critical"] = 0
104+
record["warning"] = 0
105+
record[check.Status] = 1
101106

102107
tags["node"] = check.Node
103108
tags["service_name"] = check.ServiceName

plugins/inputs/consul/consul_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func TestGatherHealtCheck(t *testing.T) {
2424
expectedFields := map[string]interface{}{
2525
"check_name": "foo.health",
2626
"status": "passing",
27+
"passing": 1,
28+
"critical": 0,
29+
"warning": 0,
2730
"service_id": "foo.123",
2831
}
2932

0 commit comments

Comments
 (0)