org.elasticsearch.cluster.health.ClusterIndexHealth Java Examples
The following examples show how to use
org.elasticsearch.cluster.health.ClusterIndexHealth.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrometheusMetricsCollector.java From elasticsearch-prometheus-exporter with Apache License 2.0 | 6 votes |
private void updatePerIndexMetrics(ClusterHealthResponse chr, IndicesStatsResponse isr) { if (chr != null && isr != null) { for (Map.Entry<String, IndexStats> entry : isr.getIndices().entrySet()) { String indexName = entry.getKey(); ClusterIndexHealth cih = chr.getIndices().get(indexName); catalog.setClusterGauge("index_status", cih.getStatus().value(), indexName); catalog.setClusterGauge("index_replicas_number", cih.getNumberOfReplicas(), indexName); catalog.setClusterGauge("index_shards_number", cih.getActiveShards(), "active", indexName); catalog.setClusterGauge("index_shards_number", cih.getNumberOfShards(), "shards", indexName); catalog.setClusterGauge("index_shards_number", cih.getActivePrimaryShards(), "active_primary", indexName); catalog.setClusterGauge("index_shards_number", cih.getInitializingShards(), "initializing", indexName); catalog.setClusterGauge("index_shards_number", cih.getRelocatingShards(), "relocating", indexName); catalog.setClusterGauge("index_shards_number", cih.getUnassignedShards(), "unassigned", indexName); IndexStats indexStats = entry.getValue(); updatePerIndexContextMetrics(indexName, "total", indexStats.getTotal()); updatePerIndexContextMetrics(indexName, "primaries", indexStats.getPrimaries()); } } }
Example #2
Source File: IndexUtils.java From anomaly-detection with Apache License 2.0 | 5 votes |
/** * Gets the cluster index health for a particular index or the index an alias points to * * If an alias is passed in, it will only return the health status of an index it points to if it only points to a * single index. If it points to multiple indices, it will throw an exception. * * @param indexOrAliasName String of the index or alias name to get health of. * @return String represents the status of the index: "red", "yellow" or "green" * @throws IllegalArgumentException Thrown when an alias is passed in that points to more than one index */ public String getIndexHealthStatus(String indexOrAliasName) throws IllegalArgumentException { if (!clusterService.state().getRoutingTable().hasIndex(indexOrAliasName)) { // Check if the index is actually an alias if (clusterService.state().metadata().hasAlias(indexOrAliasName)) { // List of all indices the alias refers to List<IndexMetadata> indexMetaDataList = clusterService .state() .metadata() .getIndicesLookup() .get(indexOrAliasName) .getIndices(); if (indexMetaDataList.size() == 0) { return ALIAS_EXISTS_NO_INDICES_STATUS; } else if (indexMetaDataList.size() > 1) { throw new IllegalArgumentException("Cannot get health for alias that points to multiple indices"); } else { indexOrAliasName = indexMetaDataList.get(0).getIndex().getName(); } } else { return NONEXISTENT_INDEX_STATUS; } } ClusterIndexHealth indexHealth = new ClusterIndexHealth( clusterService.state().metadata().index(indexOrAliasName), clusterService.state().getRoutingTable().index(indexOrAliasName) ); return indexHealth.getStatus().name().toLowerCase(); }
Example #3
Source File: ClusterHealthResponse.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeString(clusterName); out.writeVInt(clusterStateHealth.getActivePrimaryShards()); out.writeVInt(clusterStateHealth.getActiveShards()); out.writeVInt(clusterStateHealth.getRelocatingShards()); out.writeVInt(clusterStateHealth.getInitializingShards()); out.writeVInt(clusterStateHealth.getUnassignedShards()); out.writeVInt(clusterStateHealth.getNumberOfNodes()); out.writeVInt(clusterStateHealth.getNumberOfDataNodes()); out.writeInt(numberOfPendingTasks); out.writeByte(clusterStateHealth.getStatus().value()); out.writeVInt(clusterStateHealth.getIndices().size()); for (ClusterIndexHealth indexHealth : clusterStateHealth) { indexHealth.writeTo(out); } out.writeBoolean(timedOut); out.writeVInt(clusterStateHealth.getValidationFailures().size()); for (String failure : clusterStateHealth.getValidationFailures()) { out.writeString(failure); } out.writeInt(numberOfInFlightFetch); if (out.getVersion().onOrAfter(Version.V_1_7_0)) { out.writeInt(delayedUnassignedShards); } out.writeDouble(clusterStateHealth.getActiveShardsPercent()); taskMaxWaitingTime.writeTo(out); }
Example #4
Source File: ClusterHealthResponse.java From Elasticsearch with Apache License 2.0 | 4 votes |
public Map<String, ClusterIndexHealth> getIndices() { return clusterStateHealth.getIndices(); }
Example #5
Source File: ClusterHealthResponse.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); clusterName = in.readString(); // read in a wire-compatible format for 2.x int activePrimaryShards = in.readVInt(); int activeShards = in.readVInt(); int relocatingShards = in.readVInt(); int initializingShards = in.readVInt(); int unassignedShards = in.readVInt(); int numberOfNodes = in.readVInt(); int numberOfDataNodes = in.readVInt(); numberOfPendingTasks = in.readInt(); ClusterHealthStatus status = ClusterHealthStatus.fromValue(in.readByte()); int size = in.readVInt(); Map<String, ClusterIndexHealth> indices = new HashMap<>(); for (int i = 0; i < size; i++) { ClusterIndexHealth indexHealth = ClusterIndexHealth.readClusterIndexHealth(in); indices.put(indexHealth.getIndex(), indexHealth); } timedOut = in.readBoolean(); size = in.readVInt(); List<String> validationFailures; if (size == 0) { validationFailures = Collections.emptyList(); } else { validationFailures = new ArrayList<>(size); for (int i = 0; i < size; i++) { validationFailures.add(in.readString()); } } numberOfInFlightFetch = in.readInt(); if (in.getVersion().onOrAfter(Version.V_1_7_0)) { delayedUnassignedShards= in.readInt(); } double activeShardsPercent = in.readDouble(); taskMaxWaitingTime = TimeValue.readTimeValue(in); clusterStateHealth = new ClusterStateHealth(numberOfNodes, numberOfDataNodes, activeShards, relocatingShards, activePrimaryShards, initializingShards, unassignedShards, activeShardsPercent, status, validationFailures, indices); }
Example #6
Source File: ClusterHealthResponse.java From crate with Apache License 2.0 | 4 votes |
public Map<String, ClusterIndexHealth> getIndices() { return clusterStateHealth.getIndices(); }