예제 #1
0
def get_cluster_health(es_client, level):
    try:
        response = es_client.cluster.health(level=level)

        metrics = cluster_health_parser.parse_response(response, ['es', 'cluster_health'])
    except Exception:
        logging.exception('Error while fetching cluster health.')
    else:
        update_gauges(metrics)
예제 #2
0
    def collect(self):
        try:
            response = self.es_client.cluster.health(level=self.level, request_timeout=self.timeout)

            metrics = cluster_health_parser.parse_response(response, self.metric_name_list)
        except ConnectionTimeout:
            logging.warn('Timeout while fetching %s (timeout %ss).', self.description, self.timeout)
            yield collector_up_gauge(self.metric_name_list, self.description, succeeded=False)
        except Exception:
            logging.exception('Error while fetching %s.', self.description)
            yield collector_up_gauge(self.metric_name_list, self.description, succeeded=False)
        else:
            yield from gauge_generator(metrics)
            yield collector_up_gauge(self.metric_name_list, self.description)
예제 #3
0
    def test_endpoint(self):
        # Endpoint: /_cluster/health?pretty&level=shards
        response = {
            'cluster_name': 'elasticsearch',
            'status': 'yellow',
            'timed_out': False,
            'number_of_nodes': 1,
            'number_of_data_nodes': 1,
            'active_primary_shards': 5,
            'active_shards': 5,
            'relocating_shards': 0,
            'initializing_shards': 0,
            'unassigned_shards': 5,
            'delayed_unassigned_shards': 0,
            'number_of_pending_tasks': 0,
            'number_of_in_flight_fetch': 0,
            'task_max_waiting_in_queue_millis': 0,
            'active_shards_percent_as_number': 50.0,
            'indices': {
                'foo': {
                    'status': 'yellow',
                    'number_of_shards': 5,
                    'number_of_replicas': 1,
                    'active_primary_shards': 5,
                    'active_shards': 5,
                    'relocating_shards': 0,
                    'initializing_shards': 0,
                    'unassigned_shards': 5,
                    'shards': {
                        '0': {
                            'status': 'yellow',
                            'primary_active': True,
                            'active_shards': 1,
                            'relocating_shards': 0,
                            'initializing_shards': 0,
                            'unassigned_shards': 1
                        },
                        '1': {
                            'status': 'yellow',
                            'primary_active': True,
                            'active_shards': 1,
                            'relocating_shards': 0,
                            'initializing_shards': 0,
                            'unassigned_shards': 1
                        },
                        '2': {
                            'status': 'yellow',
                            'primary_active': True,
                            'active_shards': 1,
                            'relocating_shards': 0,
                            'initializing_shards': 0,
                            'unassigned_shards': 1
                        },
                        '3': {
                            'status': 'yellow',
                            'primary_active': True,
                            'active_shards': 1,
                            'relocating_shards': 0,
                            'initializing_shards': 0,
                            'unassigned_shards': 1
                        },
                        '4': {
                            'status': 'yellow',
                            'primary_active': True,
                            'active_shards': 1,
                            'relocating_shards': 0,
                            'initializing_shards': 0,
                            'unassigned_shards': 1
                        }
                    }
                }
            }
        }

        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,
            'active_shards': 5,
            'relocating_shards': 0,
            'initializing_shards': 0,
            'unassigned_shards': 5,
            'delayed_unassigned_shards': 0,
            'number_of_pending_tasks': 0,
            'number_of_in_flight_fetch': 0,
            '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,
            'indices_active_shards{index="foo"}': 5,
            'indices_relocating_shards{index="foo"}': 0,
            '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,
            'indices_shards_initializing_shards{index="foo",shard="4"}': 0,
            'indices_shards_unassigned_shards{index="foo",shard="4"}': 1,
        }
        result = convert_result(parse_response(response))
        self.assertEqual(expected, result)