/** * Check health of cluster. */ @Override public Health getClusterHealth() { try { ClusterHealthResponse chr = esProvider.getClient().admin() .cluster().health(new ClusterHealthRequest()).get(); return Health.valueOf( chr.getStatus().name() ); } catch ( Exception ex ) { ex.printStackTrace(); logger.error( "Error connecting to ElasticSearch", ex.getMessage() ); } // this is bad, red alert! return Health.RED; }
private void printClusterStatus() { ClusterHealthRequestBuilder healthRequestBuilder = elasticsearchClient.admin().cluster().prepareHealth(); ClusterHealthResponse response = healthRequestBuilder.execute().actionGet(); if (response.getStatus().equals(ClusterHealthStatus.RED)) { LOG.error("Cluster health is RED. Indexing ability will be limited"); } else if (response.getStatus().equals(ClusterHealthStatus.YELLOW)) { LOG.warn("Cluster health is YELLOW."); } else if (response.getStatus().equals(ClusterHealthStatus.GREEN)) { LOG.info("Cluster health is GREEN."); } } }
private void printClusterStatus() { ClusterHealthRequestBuilder healthRequestBuilder = elasticsearchClient.admin().cluster().prepareHealth(); ClusterHealthResponse response = healthRequestBuilder.execute().actionGet(); if (response.getStatus().equals(ClusterHealthStatus.RED)) { LOG.error("Cluster health is RED. Indexing ability will be limited"); } else if (response.getStatus().equals(ClusterHealthStatus.YELLOW)) { LOG.warn("Cluster health is YELLOW."); } else if (response.getStatus().equals(ClusterHealthStatus.GREEN)) { LOG.info("Cluster health is GREEN."); } } }
/** * Check health of this specific index. */ @Override public Health getIndexHealth() { try { String[] indexNames = this.getIndexes(); final ActionFuture<ClusterHealthResponse> future = esProvider.getClient().admin().cluster().health( new ClusterHealthRequest( indexNames ) ); //only wait 2 seconds max ClusterHealthResponse chr = future.actionGet(2000); return Health.valueOf( chr.getStatus().name() ); } catch ( Exception ex ) { logger.error( "Error connecting to ElasticSearch", ex.getMessage() ); } // this is bad, red alert! return Health.RED; }
@Override public String checkStatus() throws Exception { final ClusterHealthResponse healthResponse = esClient .admin().cluster().prepareHealth().execute().actionGet(); if (healthResponse.isTimedOut()) { return EsStatus.TIMEOUT.toString(); } else if (ClusterHealthStatus.RED.equals(healthResponse.getStatus())) { logger.warn("Elastic search health status is reported RED"); return EsStatus.ERROR.toString(); } else if (ClusterHealthStatus.GREEN.equals(healthResponse.getStatus())) { return EsStatus.SUCCESS.toString(); } else { logger.warn("Elastic search health status is unknown"); return EsStatus.UNKNOWN.toString(); } }
protected void checkConnection(Client client) { ClusterHealthResponse health = client.admin().cluster() .prepareHealth().execute().actionGet(); if (health.getNumberOfDataNodes() == 0) throw new RuntimeException("Unable to connect to elasticsearch"); LOG.info(String.format("Connected to %d data node(s) with cluster status %s", health.getNumberOfDataNodes(), health.getStatus().name())); }
if (clusterHealthStatus.name().equalsIgnoreCase("GREEN")) { healthBean.greenorredstatus = 0; healthBean.greenoryellowstatus = 0; else if (clusterHealthStatus.name().equalsIgnoreCase("YELLOW")) { healthBean.greenoryellowstatus = 1; healthBean.greenorredstatus = 0; else if (clusterHealthStatus.name().equalsIgnoreCase("RED")) { healthBean.greenorredstatus = 1; healthBean.greenoryellowstatus = 0;
builder.field(Fields.STATUS, response.getStatus().name().toLowerCase()); builder.field(Fields.TIMED_OUT, response.isTimedOut()); builder.field(Fields.NUMBER_OF_NODES, response.getNumberOfNodes()); builder.startObject(indexHealth.getIndex(), XContentBuilder.FieldCaseConversion.NONE); builder.field(Fields.STATUS, indexHealth.getStatus().name().toLowerCase()); builder.field(Fields.NUMBER_OF_SHARDS, indexHealth.getNumberOfShards()); builder.field(Fields.NUMBER_OF_REPLICAS, indexHealth.getNumberOfReplicas()); builder.startObject(Integer.toString(shardHealth.getId())); builder.field(Fields.STATUS, shardHealth.getStatus().name().toLowerCase()); builder.field(Fields.PRIMARY_ACTIVE, shardHealth.isPrimaryActive()); builder.field(Fields.ACTIVE_SHARDS, shardHealth.getActiveShards());