use of org.graylog2.system.stats.elasticsearch.IndicesStats in project graylog2-server by Graylog2.
the class ClusterAdapterES7 method clusterStats.
@Override
public ClusterStats clusterStats() {
final Request request = new Request("GET", "/_cluster/stats/nodes/*");
final JsonNode clusterStatsResponseJson = jsonApi.perform(request, "Couldn't read Elasticsearch cluster stats");
final String clusterName = clusterStatsResponseJson.path("cluster_name").asText();
String clusterVersion = null;
if (clusterStatsResponseJson.path("nodes").path("versions").isArray()) {
final ArrayNode versions = (ArrayNode) clusterStatsResponseJson.path("nodes").path("versions");
// We just use the first version in the "versions" array. This is not correct if there are different
// versions running in the cluster, but that is not recommended anyway.
final JsonNode versionNode = versions.path(0);
if (versionNode.getNodeType() != JsonNodeType.MISSING) {
clusterVersion = versionNode.asText();
}
}
final JsonNode countStats = clusterStatsResponseJson.path("nodes").path("count");
final NodesStats nodesStats = NodesStats.create(countStats.path("total").asInt(-1), countStats.path("master_only").asInt(-1), countStats.path("data_only").asInt(-1), countStats.path("master_data").asInt(-1), countStats.path("client").asInt(-1));
final JsonNode clusterIndicesStats = clusterStatsResponseJson.path("indices");
final IndicesStats indicesStats = IndicesStats.create(clusterIndicesStats.path("count").asInt(-1), clusterIndicesStats.path("store").path("size_in_bytes").asLong(-1L), clusterIndicesStats.path("fielddata").path("memory_size_in_bytes").asLong(-1L));
return ClusterStats.create(clusterName, clusterVersion, nodesStats, indicesStats);
}
use of org.graylog2.system.stats.elasticsearch.IndicesStats in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method indicesStats.
@Override
public Set<IndexStatistics> indicesStats(Collection<String> indices) {
final ImmutableSet.Builder<IndexStatistics> result = ImmutableSet.builder();
final JsonNode allWithShardLevel = statsApi.indexStatsWithShardLevel(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(IndexStatistics.create(index, indexStats));
}
}
return result.build();
}
use of org.graylog2.system.stats.elasticsearch.IndicesStats in project graylog2-server by Graylog2.
the class ClusterAdapterES6 method clusterStats.
@Override
public ClusterStats clusterStats() {
final JestResult clusterStatsResponse = JestUtils.execute(jestClient, new Stats.Builder().build(), () -> "Couldn't read Elasticsearch cluster stats");
final JsonNode clusterStatsResponseJson = clusterStatsResponse.getJsonObject();
final String clusterName = clusterStatsResponseJson.path("cluster_name").asText();
String clusterVersion = null;
if (clusterStatsResponseJson.path("nodes").path("versions").isArray()) {
final ArrayNode versions = (ArrayNode) clusterStatsResponseJson.path("nodes").path("versions");
// We just use the first version in the "versions" array. This is not correct if there are different
// versions running in the cluster, but that is not recommended anyway.
final JsonNode versionNode = versions.path(0);
if (versionNode.getNodeType() != JsonNodeType.MISSING) {
clusterVersion = versionNode.asText();
}
}
final JsonNode countStats = clusterStatsResponseJson.path("nodes").path("count");
final NodesStats nodesStats = NodesStats.create(countStats.path("total").asInt(-1), countStats.path("master_only").asInt(-1), countStats.path("data_only").asInt(-1), countStats.path("master_data").asInt(-1), countStats.path("client").asInt(-1));
final JsonNode clusterIndicesStats = clusterStatsResponseJson.path("indices");
final IndicesStats indicesStats = IndicesStats.create(clusterIndicesStats.path("count").asInt(-1), clusterIndicesStats.path("store").path("size_in_bytes").asLong(-1L), clusterIndicesStats.path("fielddata").path("memory_size_in_bytes").asLong(-1L));
return ClusterStats.create(clusterName, clusterVersion, nodesStats, indicesStats);
}
use of org.graylog2.system.stats.elasticsearch.IndicesStats 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();
}
Aggregations