use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project graylog2-server by Graylog2.
the class Indices method getAllDocCounts.
public Map<String, IndexStats> getAllDocCounts(final IndexSet indexSet) {
final IndicesStatsRequest request = c.admin().indices().prepareStats(indexSet.getIndexWildcard()).setDocs(true).request();
final IndicesStatsResponse response = c.admin().indices().stats(request).actionGet();
return response.getIndices();
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project sonarqube by SonarSource.
the class EsMonitor method indexAttributes.
private LinkedHashMap<String, LinkedHashMap<String, Object>> indexAttributes() {
LinkedHashMap<String, LinkedHashMap<String, Object>> indices = new LinkedHashMap<>();
IndicesStatsResponse indicesStats = esClient.prepareStats().all().get();
for (Map.Entry<String, IndexStats> indexStats : indicesStats.getIndices().entrySet()) {
LinkedHashMap<String, Object> attributes = new LinkedHashMap<>();
indices.put(indexStats.getKey(), attributes);
attributes.put("Docs", indexStats.getValue().getPrimaries().getDocs().getCount());
attributes.put("Shards", indexStats.getValue().getShards().length);
attributes.put("Store Size", byteCountToDisplaySize(indexStats.getValue().getPrimaries().getStore().getSizeInBytes()));
}
return indices;
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project crate by crate.
the class InternalClusterInfoService method refresh.
/**
* Refreshes the ClusterInfo in a blocking fashion
*/
public final ClusterInfo refresh() {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Performing ClusterInfoUpdateJob");
}
final CountDownLatch nodeLatch = updateNodeStats(new ActionListener<>() {
@Override
public void onResponse(NodesStatsResponse nodesStatsResponse) {
ImmutableOpenMap.Builder<String, DiskUsage> leastAvailableUsagesBuilder = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, DiskUsage> mostAvailableUsagesBuilder = ImmutableOpenMap.builder();
fillDiskUsagePerNode(LOGGER, nodesStatsResponse.getNodes(), leastAvailableUsagesBuilder, mostAvailableUsagesBuilder);
leastAvailableSpaceUsages = leastAvailableUsagesBuilder.build();
mostAvailableSpaceUsages = mostAvailableUsagesBuilder.build();
}
@Override
public void onFailure(Exception e) {
if (e instanceof ReceiveTimeoutTransportException) {
LOGGER.error("NodeStatsAction timed out for ClusterInfoUpdateJob", e);
} else {
if (e instanceof ClusterBlockException) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Failed to execute NodeStatsAction for ClusterInfoUpdateJob", e);
}
} else {
LOGGER.warn("Failed to execute NodeStatsAction for ClusterInfoUpdateJob", e);
}
// we empty the usages list, to be safe - we don't know what's going on.
leastAvailableSpaceUsages = ImmutableOpenMap.of();
mostAvailableSpaceUsages = ImmutableOpenMap.of();
}
}
});
final CountDownLatch indicesLatch = updateIndicesStats(new ActionListener<>() {
@Override
public void onResponse(IndicesStatsResponse indicesStatsResponse) {
ShardStats[] stats = indicesStatsResponse.getShards();
ImmutableOpenMap.Builder<String, Long> newShardSizes = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<ShardRouting, String> newShardRoutingToDataPath = ImmutableOpenMap.builder();
buildShardLevelInfo(LOGGER, stats, newShardSizes, newShardRoutingToDataPath);
shardSizes = newShardSizes.build();
shardRoutingToDataPath = newShardRoutingToDataPath.build();
}
@Override
public void onFailure(Exception e) {
if (e instanceof ReceiveTimeoutTransportException) {
LOGGER.error("IndicesStatsAction timed out for ClusterInfoUpdateJob", e);
} else {
if (e instanceof ClusterBlockException) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Failed to execute IndicesStatsAction for ClusterInfoUpdateJob", e);
}
} else {
LOGGER.warn("Failed to execute IndicesStatsAction for ClusterInfoUpdateJob", e);
}
// we empty the usages list, to be safe - we don't know what's going on.
shardSizes = ImmutableOpenMap.of();
shardRoutingToDataPath = ImmutableOpenMap.of();
}
}
});
try {
nodeLatch.await(fetchTimeout.getMillis(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// restore interrupt status
Thread.currentThread().interrupt();
LOGGER.warn("Failed to update node information for ClusterInfoUpdateJob within {} timeout", fetchTimeout);
}
try {
indicesLatch.await(fetchTimeout.getMillis(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// restore interrupt status
Thread.currentThread().interrupt();
LOGGER.warn("Failed to update shard information for ClusterInfoUpdateJob within {} timeout", fetchTimeout);
}
ClusterInfo clusterInfo = getClusterInfo();
boolean anyListeners = false;
for (final Consumer<ClusterInfo> listener : listeners) {
anyListeners = true;
try {
LOGGER.trace("notifying [{}] of new cluster info", listener);
listener.accept(clusterInfo);
} catch (Exception e) {
LOGGER.info(new ParameterizedMessage("failed to notify [{}] of new cluster info", listener), e);
}
}
assert anyListeners : "expected to notify at least one listener";
return clusterInfo;
}
use of org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse in project crate by crate.
the class MasterDisruptionIT method testMappingNewFieldsTimeoutDoesntAffectCheckpoints.
@Test
public void testMappingNewFieldsTimeoutDoesntAffectCheckpoints() throws Exception {
InternalTestCluster internalCluster = internalCluster();
internalCluster.startNodes(3, Settings.builder().put(MappingUpdatedAction.INDICES_MAPPING_DYNAMIC_TIMEOUT_SETTING.getKey(), "1ms").build());
ensureStableCluster(3);
logger.info("creating table t with 1 shards and 1 replica");
execute("create table t (id int primary key, x object(dynamic)) clustered into 1 shards with " + "(number_of_replicas = 1, \"routing.allocation.exclude._name\" = '" + internalCluster().getMasterName() + "', \"write.wait_for_active_shards\" = 1)");
ensureGreen();
execute("insert into t values (?, ?)", new Object[] { 1, Map.of("first field", "first value") });
ServiceDisruptionScheme disruption = new BlockMasterServiceOnMaster(random());
setDisruptionScheme(disruption);
disruption.startDisrupting();
try {
execute("insert into t values (?, ?), (?, ?), (?, ?)", new Object[] { 2, Map.of("2nd field", "2nd value"), 3, Map.of("3rd field", "3rd value"), 4, Map.of("4th field", "4th value") });
} catch (Exception e) {
// failure is acceptable
}
disruption.stopDisrupting();
String indexName = toIndexName(sqlExecutor.getCurrentSchema(), "t", null);
assertBusy(() -> {
IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().get();
for (ShardStats shardStats : stats.getShards()) {
assertThat(shardStats.getShardRouting().toString(), shardStats.getSeqNoStats().getGlobalCheckpoint(), equalTo(shardStats.getSeqNoStats().getLocalCheckpoint()));
}
}, 1, TimeUnit.MINUTES);
}
Aggregations