Add health status mapping from string to int in elasticsearch input (#3551)

This commit is contained in:
Arkady Emelyanov 2017-12-07 22:31:03 +03:00 committed by Daniel Nelson
parent 177e7e2c73
commit 4d91162abd
3 changed files with 29 additions and 0 deletions

View File

@ -46,6 +46,17 @@ or [cluster-stats](https://www.elastic.co/guide/en/elasticsearch/reference/curre
# insecure_skip_verify = false
```
### Status mappings
When reporting health (green/yellow/red), additional field `status_code`
is reported. Field contains mapping from status:string to status_code:int
with following rules:
* `green` - 1
* `yellow` - 2
* `red` - 3
* `unknown` - 0
### Measurements & Fields:
field data circuit breaker measurement names:

View File

@ -143,6 +143,19 @@ func NewElasticsearch() *Elasticsearch {
}
}
// perform status mapping
func mapHealthStatusToCode(s string) int {
switch strings.ToLower(s) {
case "green":
return 1
case "yellow":
return 2
case "red":
return 3
}
return 0
}
// SampleConfig returns sample configuration for this plugin.
func (e *Elasticsearch) SampleConfig() string {
return sampleConfig
@ -311,6 +324,7 @@ func (e *Elasticsearch) gatherClusterHealth(url string, acc telegraf.Accumulator
measurementTime := time.Now()
clusterFields := map[string]interface{}{
"status": healthStats.Status,
"status_code": mapHealthStatusToCode(healthStats.Status),
"timed_out": healthStats.TimedOut,
"number_of_nodes": healthStats.NumberOfNodes,
"number_of_data_nodes": healthStats.NumberOfDataNodes,
@ -330,6 +344,7 @@ func (e *Elasticsearch) gatherClusterHealth(url string, acc telegraf.Accumulator
for name, health := range healthStats.Indices {
indexFields := map[string]interface{}{
"status": health.Status,
"status_code": mapHealthStatusToCode(health.Status),
"number_of_shards": health.NumberOfShards,
"number_of_replicas": health.NumberOfReplicas,
"active_primary_shards": health.ActivePrimaryShards,

View File

@ -54,6 +54,7 @@ const clusterHealthResponseWithIndices = `
var clusterHealthExpected = map[string]interface{}{
"status": "green",
"status_code": 1,
"timed_out": false,
"number_of_nodes": 3,
"number_of_data_nodes": 3,
@ -66,6 +67,7 @@ var clusterHealthExpected = map[string]interface{}{
var v1IndexExpected = map[string]interface{}{
"status": "green",
"status_code": 1,
"number_of_shards": 10,
"number_of_replicas": 1,
"active_primary_shards": 10,
@ -77,6 +79,7 @@ var v1IndexExpected = map[string]interface{}{
var v2IndexExpected = map[string]interface{}{
"status": "red",
"status_code": 3,
"number_of_shards": 10,
"number_of_replicas": 1,
"active_primary_shards": 0,