Search in sources :

Example 1 with NodesStats

use of org.graylog2.system.stats.elasticsearch.NodesStats 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);
}
Also used : NodesStats(org.graylog2.system.stats.elasticsearch.NodesStats) IndicesStats(org.graylog2.system.stats.elasticsearch.IndicesStats) ClusterGetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest) GetIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with NodesStats

use of org.graylog2.system.stats.elasticsearch.NodesStats 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);
}
Also used : NodesStats(org.graylog2.system.stats.elasticsearch.NodesStats) IndicesStats(org.graylog2.system.stats.elasticsearch.IndicesStats) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JestResult(io.searchbox.client.JestResult)

Example 3 with NodesStats

use of org.graylog2.system.stats.elasticsearch.NodesStats in project graylog2-server by Graylog2.

the class IndexerClusterCheckerThread method doRun.

@Override
public void doRun() {
    if (!notificationService.isFirst(Notification.Type.ES_OPEN_FILES)) {
        return;
    }
    try {
        cluster.health().getStatus();
    } catch (Exception e) {
        LOG.info("Indexer not fully initialized yet. Skipping periodic cluster check.");
        return;
    }
    boolean allHigher = true;
    final Map<String, NodeInfo> nodesInfos = cluster.getDataNodes();
    final Map<String, NodeStats> nodesStats = cluster.getNodesStats(nodesInfos.keySet().toArray(new String[nodesInfos.size()]));
    for (Map.Entry<String, NodeStats> entry : nodesStats.entrySet()) {
        final String nodeId = entry.getKey();
        final NodeStats nodeStats = entry.getValue();
        final NodeInfo nodeInfo = nodesInfos.get(nodeId);
        final String nodeName = nodeInfo.getNode().getName();
        // Check number of maximum open files.
        final ProcessStats processStats = nodeStats.getProcess();
        if (processStats == null) {
            LOG.debug("Couldn't read process stats of Elasticsearch node {}", nodeName);
            return;
        }
        final long maxFileDescriptors = processStats.getMaxFileDescriptors();
        final JvmInfo jvmInfo = nodeInfo.getJvm();
        if (jvmInfo == null) {
            LOG.debug("Couldn't read JVM info of Elasticsearch node {}", nodeName);
            return;
        }
        final String osName = jvmInfo.getSystemProperties().getOrDefault("os.name", "");
        if (osName.startsWith("Windows")) {
            LOG.debug("Skipping open file limit check for Indexer node <{}> on Windows", nodeName);
        } else if (maxFileDescriptors != -1 && maxFileDescriptors < MINIMUM_OPEN_FILES_LIMIT) {
            // Write notification.
            final Notification notification = notificationService.buildNow().addType(Notification.Type.ES_OPEN_FILES).addSeverity(Notification.Severity.URGENT).addDetail("hostname", nodeInfo.getHostname()).addDetail("max_file_descriptors", maxFileDescriptors);
            if (notificationService.publishIfFirst(notification)) {
                LOG.warn("Indexer node <{}> open file limit is too low: [{}]. Set it to at least {}.", nodeName, maxFileDescriptors, MINIMUM_OPEN_FILES_LIMIT);
            }
            allHigher = false;
        }
    }
    if (allHigher) {
        Notification notification = notificationService.build().addType(Notification.Type.ES_OPEN_FILES);
        notificationService.fixed(notification);
    }
}
Also used : ProcessStats(org.elasticsearch.monitor.process.ProcessStats) JvmInfo(org.elasticsearch.monitor.jvm.JvmInfo) Notification(org.graylog2.notifications.Notification) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) Map(java.util.Map)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 IndicesStats (org.graylog2.system.stats.elasticsearch.IndicesStats)2 NodesStats (org.graylog2.system.stats.elasticsearch.NodesStats)2 JestResult (io.searchbox.client.JestResult)1 Map (java.util.Map)1 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)1 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)1 JvmInfo (org.elasticsearch.monitor.jvm.JvmInfo)1 ProcessStats (org.elasticsearch.monitor.process.ProcessStats)1 ClusterHealthRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)1 ClusterGetSettingsRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest)1 Request (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request)1 GetIndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest)1 Notification (org.graylog2.notifications.Notification)1