From 6082619969f49538877780449f61f02f05ae3d20 Mon Sep 17 00:00:00 2001 From: Braedon Vickers Date: Thu, 26 Mar 2020 16:54:41 +0800 Subject: [PATCH] Add new metrics for the three cluster/index/shard status colours The new metrics are `1` if the cluster/index/shard has that status, or `0` otherwise. Can be aggregated to show the number of clusters/indices/shards with a given status. --- .../cluster_health_parser.py | 3 +++ tests/test_cluster_health_parser.py | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/prometheus_es_exporter/cluster_health_parser.py b/prometheus_es_exporter/cluster_health_parser.py index 2880fa5..00382aa 100644 --- a/prometheus_es_exporter/cluster_health_parser.py +++ b/prometheus_es_exporter/cluster_health_parser.py @@ -29,6 +29,9 @@ def parse_block(block, metric=None, labels=None): elif status == 'red': status_int = 2 metrics.append((metric + ['status'], '', labels, status_int)) + for colour in ['green', 'yellow', 'red']: + metrics.append((metric + ['status', colour], '', labels, + 1 if status == colour else 0)) for key, value in block.items(): if isinstance(value, bool): diff --git a/tests/test_cluster_health_parser.py b/tests/test_cluster_health_parser.py index b5c4ddd..705b40f 100644 --- a/tests/test_cluster_health_parser.py +++ b/tests/test_cluster_health_parser.py @@ -88,6 +88,9 @@ def test_endpoint(self): expected = { 'status': 1, + 'status_green': 0, + 'status_yellow': 1, + 'status_red': 0, 'number_of_nodes': 1, 'number_of_data_nodes': 1, 'active_primary_shards': 5, @@ -101,6 +104,9 @@ def test_endpoint(self): 'task_max_waiting_in_queue_millis': 0, 'active_shards_percent_as_number': 50.0, 'indices_status{index="foo"}': 1, + 'indices_status_green{index="foo"}': 0, + 'indices_status_yellow{index="foo"}': 1, + 'indices_status_red{index="foo"}': 0, 'indices_number_of_shards{index="foo"}': 5, 'indices_number_of_replicas{index="foo"}': 1, 'indices_active_primary_shards{index="foo"}': 5, @@ -109,30 +115,45 @@ def test_endpoint(self): 'indices_initializing_shards{index="foo"}': 0, 'indices_unassigned_shards{index="foo"}': 5, 'indices_shards_status{index="foo",shard="0"}': 1, + 'indices_shards_status_green{index="foo",shard="0"}': 0, + 'indices_shards_status_yellow{index="foo",shard="0"}': 1, + 'indices_shards_status_red{index="foo",shard="0"}': 0, 'indices_shards_primary_active{index="foo",shard="0"}': 1, 'indices_shards_active_shards{index="foo",shard="0"}': 1, 'indices_shards_relocating_shards{index="foo",shard="0"}': 0, 'indices_shards_initializing_shards{index="foo",shard="0"}': 0, 'indices_shards_unassigned_shards{index="foo",shard="0"}': 1, 'indices_shards_status{index="foo",shard="1"}': 1, + 'indices_shards_status_green{index="foo",shard="1"}': 0, + 'indices_shards_status_yellow{index="foo",shard="1"}': 1, + 'indices_shards_status_red{index="foo",shard="1"}': 0, 'indices_shards_primary_active{index="foo",shard="1"}': 1, 'indices_shards_active_shards{index="foo",shard="1"}': 1, 'indices_shards_relocating_shards{index="foo",shard="1"}': 0, 'indices_shards_initializing_shards{index="foo",shard="1"}': 0, 'indices_shards_unassigned_shards{index="foo",shard="1"}': 1, 'indices_shards_status{index="foo",shard="2"}': 1, + 'indices_shards_status_green{index="foo",shard="2"}': 0, + 'indices_shards_status_yellow{index="foo",shard="2"}': 1, + 'indices_shards_status_red{index="foo",shard="2"}': 0, 'indices_shards_primary_active{index="foo",shard="2"}': 1, 'indices_shards_active_shards{index="foo",shard="2"}': 1, 'indices_shards_relocating_shards{index="foo",shard="2"}': 0, 'indices_shards_initializing_shards{index="foo",shard="2"}': 0, 'indices_shards_unassigned_shards{index="foo",shard="2"}': 1, 'indices_shards_status{index="foo",shard="3"}': 1, + 'indices_shards_status_green{index="foo",shard="3"}': 0, + 'indices_shards_status_yellow{index="foo",shard="3"}': 1, + 'indices_shards_status_red{index="foo",shard="3"}': 0, 'indices_shards_primary_active{index="foo",shard="3"}': 1, 'indices_shards_active_shards{index="foo",shard="3"}': 1, 'indices_shards_relocating_shards{index="foo",shard="3"}': 0, 'indices_shards_initializing_shards{index="foo",shard="3"}': 0, 'indices_shards_unassigned_shards{index="foo",shard="3"}': 1, 'indices_shards_status{index="foo",shard="4"}': 1, + 'indices_shards_status_green{index="foo",shard="4"}': 0, + 'indices_shards_status_yellow{index="foo",shard="4"}': 1, + 'indices_shards_status_red{index="foo",shard="4"}': 0, 'indices_shards_primary_active{index="foo",shard="4"}': 1, 'indices_shards_active_shards{index="foo",shard="4"}': 1, 'indices_shards_relocating_shards{index="foo",shard="4"}': 0,