From 738cbbdbb6ff9bb9fa1a561270ed4e60e5d7127c Mon Sep 17 00:00:00 2001
From: John Engelman <john.r.engelman@gmail.com>
Date: Sat, 28 Jan 2017 18:47:25 -0600
Subject: [PATCH] Add numerical representation of Consul health check state.
 (#2277)

---
 CHANGELOG.md                         |  1 +
 plugins/inputs/consul/README.md      | 11 +++++++++--
 plugins/inputs/consul/consul.go      |  5 +++++
 plugins/inputs/consul/consul_test.go |  3 +++
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 777eefbd..f3e0626d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ It is highly recommended that all users migrate to the new riemann output plugin
 - [#2251](https://github.com/influxdata/telegraf/pull/2251): InfluxDB output: use own client for improved through-put and less allocations.
 - [#1900](https://github.com/influxdata/telegraf/pull/1900): Riemann plugin rewrite.
 - [#1453](https://github.com/influxdata/telegraf/pull/1453): diskio: add support for name templates and udev tags.
+- [#2277](https://github.com/influxdata/telegraf/pull/2277): add integer metrics for Consul check health state.
 
 ### Bugfixes
 
diff --git a/plugins/inputs/consul/README.md b/plugins/inputs/consul/README.md
index 01a39cbf..dbb57642 100644
--- a/plugins/inputs/consul/README.md
+++ b/plugins/inputs/consul/README.md
@@ -35,12 +35,19 @@ Fields:
 - check_name
 - service_id
 - status
+- passing
+- critical
+- warning
+
+`passing`, `critical`, and `warning` are integer representations of the health
+check state. A value of `1` represents that the status was the state of the
+the health check at this sample.
 
 ## Example output
 
 ```
 $ 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",passing=1i,critical=0i,warning=0i 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",passing=0i,critical=1i,warning=0i 1464698464486519036
 ```
diff --git a/plugins/inputs/consul/consul.go b/plugins/inputs/consul/consul.go
index 4c28f4d1..0eaa2560 100644
--- a/plugins/inputs/consul/consul.go
+++ b/plugins/inputs/consul/consul.go
@@ -97,7 +97,12 @@ func (c *Consul) GatherHealthCheck(acc telegraf.Accumulator, checks []*api.Healt
 
 		record["check_name"] = check.Name
 		record["service_id"] = check.ServiceID
+
 		record["status"] = check.Status
+		record["passing"] = 0
+		record["critical"] = 0
+		record["warning"] = 0
+		record[check.Status] = 1
 
 		tags["node"] = check.Node
 		tags["service_name"] = check.ServiceName
diff --git a/plugins/inputs/consul/consul_test.go b/plugins/inputs/consul/consul_test.go
index f970d444..d0595508 100644
--- a/plugins/inputs/consul/consul_test.go
+++ b/plugins/inputs/consul/consul_test.go
@@ -24,6 +24,9 @@ func TestGatherHealtCheck(t *testing.T) {
 	expectedFields := map[string]interface{}{
 		"check_name": "foo.health",
 		"status":     "passing",
+		"passing":    1,
+		"critical":   0,
+		"warning":    0,
 		"service_id": "foo.123",
 	}
 
-- 
GitLab