use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus in project elasticsearch by elastic.
the class TransportClusterStatsAction method nodeOperation.
@Override
protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeRequest) {
NodeInfo nodeInfo = nodeService.info(true, true, false, true, false, true, false, true, false, false);
NodeStats nodeStats = nodeService.stats(CommonStatsFlags.NONE, true, true, true, false, true, false, false, false, false, false, false);
List<ShardStats> shardsStats = new ArrayList<>();
for (IndexService indexService : indicesService) {
for (IndexShard indexShard : indexService) {
if (indexShard.routingEntry() != null && indexShard.routingEntry().active()) {
// only report on fully started shards
shardsStats.add(new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), new CommonStats(indicesService.getIndicesQueryCache(), indexShard, SHARD_STATS_FLAGS), indexShard.commitStats(), indexShard.seqNoStats()));
}
}
}
ClusterHealthStatus clusterStatus = null;
if (clusterService.state().nodes().isLocalNodeElectedMaster()) {
clusterStatus = new ClusterStateHealth(clusterService.state()).getStatus();
}
return new ClusterStatsNodeResponse(nodeInfo.getNode(), clusterStatus, nodeInfo, nodeStats, shardsStats.toArray(new ShardStats[shardsStats.size()]));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus in project elasticsearch by elastic.
the class RestIndicesAction method buildTable.
// package private for testing
Table buildTable(RestRequest request, Index[] indices, ClusterHealthResponse response, IndicesStatsResponse stats, MetaData indexMetaDatas) {
final String healthParam = request.param("health");
final ClusterHealthStatus status;
if (healthParam != null) {
status = ClusterHealthStatus.fromString(healthParam);
} else {
status = null;
}
Table table = getTableWithHeader(request);
for (final Index index : indices) {
final String indexName = index.getName();
ClusterIndexHealth indexHealth = response.getIndices().get(indexName);
IndexStats indexStats = stats.getIndices().get(indexName);
IndexMetaData indexMetaData = indexMetaDatas.getIndices().get(indexName);
IndexMetaData.State state = indexMetaData.getState();
if (status != null) {
if (state == IndexMetaData.State.CLOSE || (indexHealth == null && !ClusterHealthStatus.RED.equals(status)) || !indexHealth.getStatus().equals(status)) {
continue;
}
}
table.startRow();
table.addCell(state == IndexMetaData.State.OPEN ? (indexHealth == null ? "red*" : indexHealth.getStatus().toString().toLowerCase(Locale.ROOT)) : null);
table.addCell(state.toString().toLowerCase(Locale.ROOT));
table.addCell(indexName);
table.addCell(index.getUUID());
table.addCell(indexHealth == null ? null : indexHealth.getNumberOfShards());
table.addCell(indexHealth == null ? null : indexHealth.getNumberOfReplicas());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getDocs().getCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getDocs().getDeleted());
table.addCell(indexMetaData.getCreationDate());
table.addCell(new DateTime(indexMetaData.getCreationDate(), DateTimeZone.UTC));
table.addCell(indexStats == null ? null : indexStats.getTotal().getStore().size());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getStore().size());
table.addCell(indexStats == null ? null : indexStats.getTotal().getCompletion().getSize());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getCompletion().getSize());
table.addCell(indexStats == null ? null : indexStats.getTotal().getFieldData().getMemorySize());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getFieldData().getMemorySize());
table.addCell(indexStats == null ? null : indexStats.getTotal().getFieldData().getEvictions());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getFieldData().getEvictions());
table.addCell(indexStats == null ? null : indexStats.getTotal().getQueryCache().getMemorySize());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getQueryCache().getMemorySize());
table.addCell(indexStats == null ? null : indexStats.getTotal().getQueryCache().getEvictions());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getQueryCache().getEvictions());
table.addCell(indexStats == null ? null : indexStats.getTotal().getRequestCache().getMemorySize());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getRequestCache().getMemorySize());
table.addCell(indexStats == null ? null : indexStats.getTotal().getRequestCache().getEvictions());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getRequestCache().getEvictions());
table.addCell(indexStats == null ? null : indexStats.getTotal().getRequestCache().getHitCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getRequestCache().getHitCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getRequestCache().getMissCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getRequestCache().getMissCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getFlush().getTotal());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getFlush().getTotal());
table.addCell(indexStats == null ? null : indexStats.getTotal().getFlush().getTotalTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getFlush().getTotalTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getGet().current());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getGet().current());
table.addCell(indexStats == null ? null : indexStats.getTotal().getGet().getTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getGet().getTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getGet().getCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getGet().getCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getGet().getExistsTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getGet().getExistsTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getGet().getExistsCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getGet().getExistsCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getGet().getMissingTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getGet().getMissingTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getGet().getMissingCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getGet().getMissingCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getIndexing().getTotal().getDeleteCurrent());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getIndexing().getTotal().getDeleteCurrent());
table.addCell(indexStats == null ? null : indexStats.getTotal().getIndexing().getTotal().getDeleteTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getIndexing().getTotal().getDeleteTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getIndexing().getTotal().getDeleteCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getIndexing().getTotal().getDeleteCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getIndexing().getTotal().getIndexCurrent());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getIndexing().getTotal().getIndexCurrent());
table.addCell(indexStats == null ? null : indexStats.getTotal().getIndexing().getTotal().getIndexTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getIndexing().getTotal().getIndexTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getIndexing().getTotal().getIndexCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getIndexing().getTotal().getIndexCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getIndexing().getTotal().getIndexFailedCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getIndexing().getTotal().getIndexFailedCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getMerge().getCurrent());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getMerge().getCurrent());
table.addCell(indexStats == null ? null : indexStats.getTotal().getMerge().getCurrentNumDocs());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getMerge().getCurrentNumDocs());
table.addCell(indexStats == null ? null : indexStats.getTotal().getMerge().getCurrentSize());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getMerge().getCurrentSize());
table.addCell(indexStats == null ? null : indexStats.getTotal().getMerge().getTotal());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getMerge().getTotal());
table.addCell(indexStats == null ? null : indexStats.getTotal().getMerge().getTotalNumDocs());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getMerge().getTotalNumDocs());
table.addCell(indexStats == null ? null : indexStats.getTotal().getMerge().getTotalSize());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getMerge().getTotalSize());
table.addCell(indexStats == null ? null : indexStats.getTotal().getMerge().getTotalTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getMerge().getTotalTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getRefresh().getTotal());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getRefresh().getTotal());
table.addCell(indexStats == null ? null : indexStats.getTotal().getRefresh().getTotalTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getRefresh().getTotalTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getRefresh().getListeners());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getRefresh().getListeners());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getFetchCurrent());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getFetchCurrent());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getFetchTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getFetchTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getFetchCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getFetchCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getOpenContexts());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getOpenContexts());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getQueryCurrent());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getQueryCurrent());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getQueryTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getQueryTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getQueryCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getQueryCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getScrollCurrent());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getScrollCurrent());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getScrollTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getScrollTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getScrollCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getScrollCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSegments().getCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSegments().getCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSegments().getMemory());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSegments().getMemory());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSegments().getIndexWriterMemory());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSegments().getIndexWriterMemory());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSegments().getVersionMapMemory());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSegments().getVersionMapMemory());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSegments().getBitsetMemory());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSegments().getBitsetMemory());
table.addCell(indexStats == null ? null : indexStats.getTotal().getWarmer().current());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getWarmer().current());
table.addCell(indexStats == null ? null : indexStats.getTotal().getWarmer().total());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getWarmer().total());
table.addCell(indexStats == null ? null : indexStats.getTotal().getWarmer().totalTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getWarmer().totalTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getSuggestCurrent());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getSuggestCurrent());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getSuggestTime());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getSuggestTime());
table.addCell(indexStats == null ? null : indexStats.getTotal().getSearch().getTotal().getSuggestCount());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getSearch().getTotal().getSuggestCount());
table.addCell(indexStats == null ? null : indexStats.getTotal().getTotalMemory());
table.addCell(indexStats == null ? null : indexStats.getPrimaries().getTotalMemory());
table.endRow();
}
return table;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus in project elasticsearch by elastic.
the class IndicesShardStoresRequest method writeTo.
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArrayNullable(indices);
out.writeVInt(statuses.size());
for (ClusterHealthStatus status : statuses) {
out.writeByte(status.value());
}
indicesOptions.writeIndicesOptions(out);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus in project elasticsearch by elastic.
the class CorruptedFileIT method testCorruptPrimaryNoReplica.
/**
* Tests corruption that happens on a single shard when no replicas are present. We make sure that the primary stays unassigned
* and all other replicas for the healthy shards happens
*/
public void testCorruptPrimaryNoReplica() throws ExecutionException, InterruptedException, IOException {
int numDocs = scaledRandomIntBetween(100, 1000);
internalCluster().ensureAtLeastNumDataNodes(2);
assertAcked(prepareCreate("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, "0").put(MergePolicyConfig.INDEX_MERGE_ENABLED, false).put(MockFSIndexStore.INDEX_CHECK_INDEX_ON_CLOSE_SETTING.getKey(), // no checkindex - we corrupt shards on purpose
false).put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), // no translog based flush - it might change the .liv / segments.N files
new ByteSizeValue(1, ByteSizeUnit.PB))));
ensureGreen();
IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs];
for (int i = 0; i < builders.length; i++) {
builders[i] = client().prepareIndex("test", "type").setSource("field", "value");
}
indexRandom(true, builders);
ensureGreen();
assertAllSuccessful(client().admin().indices().prepareFlush().setForce(true).execute().actionGet());
// we have to flush at least once here since we don't corrupt the translog
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
assertHitCount(countResponse, numDocs);
ShardRouting shardRouting = corruptRandomPrimaryFile();
/*
* we corrupted the primary shard - now lets make sure we never recover from it successfully
*/
Settings build = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, "1").build();
client().admin().indices().prepareUpdateSettings("test").setSettings(build).get();
client().admin().cluster().prepareReroute().get();
boolean didClusterTurnRed = awaitBusy(() -> {
ClusterHealthStatus test = client().admin().cluster().health(Requests.clusterHealthRequest("test")).actionGet().getStatus();
return test == ClusterHealthStatus.RED;
}, 5, // sometimes on slow nodes the replication / recovery is just dead slow
TimeUnit.MINUTES);
final ClusterHealthResponse response = client().admin().cluster().health(Requests.clusterHealthRequest("test")).get();
if (response.getStatus() != ClusterHealthStatus.RED) {
logger.info("Cluster turned red in busy loop: {}", didClusterTurnRed);
logger.info("cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get());
}
assertThat(response.getStatus(), is(ClusterHealthStatus.RED));
ClusterState state = client().admin().cluster().prepareState().get().getState();
GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[] { "test" }, false);
for (ShardIterator iterator : shardIterators) {
ShardRouting routing;
while ((routing = iterator.nextOrNull()) != null) {
if (routing.getId() == shardRouting.getId()) {
assertThat(routing.state(), equalTo(ShardRoutingState.UNASSIGNED));
} else {
assertThat(routing.state(), anyOf(equalTo(ShardRoutingState.RELOCATING), equalTo(ShardRoutingState.STARTED)));
}
}
}
final List<Path> files = listShardFiles(shardRouting);
Path corruptedFile = null;
for (Path file : files) {
if (file.getFileName().toString().startsWith("corrupted_")) {
corruptedFile = file;
break;
}
}
assertThat(corruptedFile, notNullValue());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus in project pancm_project by xuwujing.
the class EsHighLevelCluster method catHealth.
/**
* @return void
* @Author pancm
* @Description 设获取集群的健康情况
* @Date 2020/1/2
* @Param [index]
*/
public static void catHealth() throws IOException {
ClusterHealthRequest request = new ClusterHealthRequest();
ClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT);
String clusterName = response.getClusterName();
ClusterHealthStatus status = response.getStatus();
boolean timedOut = response.isTimedOut();
RestStatus restStatus = response.status();
int numberOfNodes = response.getNumberOfNodes();
int numberOfDataNodes = response.getNumberOfDataNodes();
int activeShards = response.getActiveShards();
int activePrimaryShards = response.getActivePrimaryShards();
int relocatingShards = response.getRelocatingShards();
int initializingShards = response.getInitializingShards();
int unassignedShards = response.getUnassignedShards();
int delayedUnassignedShards = response.getDelayedUnassignedShards();
double activeShardsPercent = response.getActiveShardsPercent();
logger.info("clusterName:{},status:{},timedOut:{},restStatus:{}", clusterName, status, timedOut, restStatus.getStatus());
List<Map<String, Object>> mapList = new ArrayList<>();
response.getIndices().forEach((k, v) -> {
Map<String, Object> map = new HashMap<>();
String index = v.getIndex();
int replicas = v.getNumberOfReplicas();
int allShards = v.getActiveShards();
int shards = v.getActivePrimaryShards();
int status2 = v.getStatus().value();
map.put("index", index);
map.put("replicas", replicas);
map.put("shards", shards);
map.put("status", status2);
System.out.println(map);
});
}
Aggregations