Add health status mapping from string to int in elasticsearch input (#3551)
This commit is contained in:
parent
6265a3b06f
commit
1326f61635
|
@ -46,6 +46,17 @@ or [cluster-stats](https://www.elastic.co/guide/en/elasticsearch/reference/curre
|
||||||
# insecure_skip_verify = false
|
# 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:
|
### Measurements & Fields:
|
||||||
|
|
||||||
field data circuit breaker measurement names:
|
field data circuit breaker measurement names:
|
||||||
|
|
|
@ -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.
|
// SampleConfig returns sample configuration for this plugin.
|
||||||
func (e *Elasticsearch) SampleConfig() string {
|
func (e *Elasticsearch) SampleConfig() string {
|
||||||
return sampleConfig
|
return sampleConfig
|
||||||
|
@ -311,6 +324,7 @@ func (e *Elasticsearch) gatherClusterHealth(url string, acc telegraf.Accumulator
|
||||||
measurementTime := time.Now()
|
measurementTime := time.Now()
|
||||||
clusterFields := map[string]interface{}{
|
clusterFields := map[string]interface{}{
|
||||||
"status": healthStats.Status,
|
"status": healthStats.Status,
|
||||||
|
"status_code": mapHealthStatusToCode(healthStats.Status),
|
||||||
"timed_out": healthStats.TimedOut,
|
"timed_out": healthStats.TimedOut,
|
||||||
"number_of_nodes": healthStats.NumberOfNodes,
|
"number_of_nodes": healthStats.NumberOfNodes,
|
||||||
"number_of_data_nodes": healthStats.NumberOfDataNodes,
|
"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 {
|
for name, health := range healthStats.Indices {
|
||||||
indexFields := map[string]interface{}{
|
indexFields := map[string]interface{}{
|
||||||
"status": health.Status,
|
"status": health.Status,
|
||||||
|
"status_code": mapHealthStatusToCode(health.Status),
|
||||||
"number_of_shards": health.NumberOfShards,
|
"number_of_shards": health.NumberOfShards,
|
||||||
"number_of_replicas": health.NumberOfReplicas,
|
"number_of_replicas": health.NumberOfReplicas,
|
||||||
"active_primary_shards": health.ActivePrimaryShards,
|
"active_primary_shards": health.ActivePrimaryShards,
|
||||||
|
|
|
@ -54,6 +54,7 @@ const clusterHealthResponseWithIndices = `
|
||||||
|
|
||||||
var clusterHealthExpected = map[string]interface{}{
|
var clusterHealthExpected = map[string]interface{}{
|
||||||
"status": "green",
|
"status": "green",
|
||||||
|
"status_code": 1,
|
||||||
"timed_out": false,
|
"timed_out": false,
|
||||||
"number_of_nodes": 3,
|
"number_of_nodes": 3,
|
||||||
"number_of_data_nodes": 3,
|
"number_of_data_nodes": 3,
|
||||||
|
@ -66,6 +67,7 @@ var clusterHealthExpected = map[string]interface{}{
|
||||||
|
|
||||||
var v1IndexExpected = map[string]interface{}{
|
var v1IndexExpected = map[string]interface{}{
|
||||||
"status": "green",
|
"status": "green",
|
||||||
|
"status_code": 1,
|
||||||
"number_of_shards": 10,
|
"number_of_shards": 10,
|
||||||
"number_of_replicas": 1,
|
"number_of_replicas": 1,
|
||||||
"active_primary_shards": 10,
|
"active_primary_shards": 10,
|
||||||
|
@ -77,6 +79,7 @@ var v1IndexExpected = map[string]interface{}{
|
||||||
|
|
||||||
var v2IndexExpected = map[string]interface{}{
|
var v2IndexExpected = map[string]interface{}{
|
||||||
"status": "red",
|
"status": "red",
|
||||||
|
"status_code": 3,
|
||||||
"number_of_shards": 10,
|
"number_of_shards": 10,
|
||||||
"number_of_replicas": 1,
|
"number_of_replicas": 1,
|
||||||
"active_primary_shards": 0,
|
"active_primary_shards": 0,
|
||||||
|
|
Loading…
Reference in New Issue