use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndicesAdapterES6 method getIndexStats.
@Override
public JsonNode getIndexStats(final Collection<String> indices) {
final Stats request = new Stats.Builder().addIndex(indices).docs(true).store(true).build();
final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't check stats of indices " + indices);
return jestResult.getJsonObject().path("indices");
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndicesAdapterES6 method indicesStats.
@Override
public Set<IndexStatistics> indicesStats(Collection<String> indices) {
final ImmutableSet.Builder<IndexStatistics> result = ImmutableSet.builder();
final JsonNode allWithShardLevel = getAllWithShardLevel(indices);
final Iterator<Map.Entry<String, JsonNode>> fields = allWithShardLevel.fields();
while (fields.hasNext()) {
final Map.Entry<String, JsonNode> entry = fields.next();
final String index = entry.getKey();
final JsonNode indexStats = entry.getValue();
if (indexStats.isObject()) {
result.add(buildIndexStatistics(index, indexStats));
}
}
return result.build();
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndicesAdapterES6 method indices.
@Override
public Set<String> indices(String indexWildcard, List<String> status, String indexSetId) {
final Cat catRequest = new Cat.IndicesBuilder().addIndex(indexWildcard).setParameter("h", "index,status").build();
final CatResult result = JestUtils.execute(jestClient, catRequest, () -> "Couldn't get index list for index set <" + indexSetId + ">");
return StreamSupport.stream(result.getJsonObject().path("result").spliterator(), false).filter(cat -> status.isEmpty() || status.contains(cat.path("status").asText())).map(cat -> cat.path("index").asText()).collect(Collectors.toSet());
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndicesAdapterES6 method indexRangeStatsOfIndex.
@Override
public IndexRangeStats indexRangeStatsOfIndex(String index) {
final FilterAggregationBuilder builder = AggregationBuilders.filter("agg", QueryBuilders.existsQuery(Message.FIELD_TIMESTAMP)).subAggregation(AggregationBuilders.min("ts_min").field(Message.FIELD_TIMESTAMP)).subAggregation(AggregationBuilders.max("ts_max").field(Message.FIELD_TIMESTAMP)).subAggregation(AggregationBuilders.terms("streams").size(Integer.MAX_VALUE).field(Message.FIELD_STREAMS));
final String query = searchSource().aggregation(builder).size(0).toString();
final Search request = new Search.Builder(query).addIndex(index).setSearchType(SearchType.DFS_QUERY_THEN_FETCH).ignoreUnavailable(true).build();
if (LOG.isDebugEnabled()) {
String data = "{}";
try {
data = request.getData(objectMapper.copy().enable(SerializationFeature.INDENT_OUTPUT));
} catch (IOException e) {
LOG.debug("Couldn't pretty print request payload", e);
}
LOG.debug("Index range query: _search/{}: {}", index, data);
}
final SearchResult result = JestUtils.execute(jestClient, request, () -> "Couldn't build index range of index " + index);
final FilterAggregation f = result.getAggregations().getFilterAggregation("agg");
if (f == null) {
throw new IndexNotFoundException("Couldn't build index range of index " + index + " because it doesn't exist.");
} else if (f.getCount() == 0L) {
LOG.debug("No documents with attribute \"timestamp\" found in index <{}>", index);
return IndexRangeStats.EMPTY;
}
final MinAggregation minAgg = f.getMinAggregation("ts_min");
final DateTime min = new DateTime(minAgg.getMin().longValue(), DateTimeZone.UTC);
final MaxAggregation maxAgg = f.getMaxAggregation("ts_max");
final DateTime max = new DateTime(maxAgg.getMax().longValue(), DateTimeZone.UTC);
// make sure we return an empty list, so we can differentiate between old indices that don't have this information
// and newer ones that simply have no streams.
final TermsAggregation streams = f.getTermsAggregation("streams");
final List<String> streamIds = streams.getBuckets().stream().map(TermsAggregation.Entry::getKeyAsString).collect(toList());
return IndexRangeStats.create(min, max, streamIds);
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndicesAdapterES6 method indexStats.
private JsonNode indexStats(final String indexName) {
final Stats request = new Stats.Builder().addIndex(indexName).build();
final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't check stats of index " + indexName);
return jestResult.getJsonObject().path("indices").path(indexName);
}
Aggregations