Search in sources :

Example 6 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class IndexerClusterCheckerThread method checkDiskUsage.

@VisibleForTesting()
void checkDiskUsage() {
    final Map<Notification.Type, List<String>> notificationTypePerNodeIdentifier = new HashMap<>();
    try {
        ClusterAllocationDiskSettings settings = cluster.getClusterAllocationDiskSettings();
        if (settings.ThresholdEnabled()) {
            final Set<NodeDiskUsageStats> diskUsageStats = cluster.getDiskUsageStats();
            for (NodeDiskUsageStats nodeDiskUsageStats : diskUsageStats) {
                if (!nodeHoldsData(nodeDiskUsageStats)) {
                    LOG.debug("Ignoring non-data ES node <{}/{}> with roles <{}> for disk usage check.", nodeDiskUsageStats.host(), nodeDiskUsageStats.ip(), nodeDiskUsageStats.roles());
                    continue;
                }
                Notification.Type currentNodeNotificationType = null;
                WatermarkSettings<?> watermarkSettings = settings.watermarkSettings();
                if (watermarkSettings instanceof PercentageWatermarkSettings) {
                    currentNodeNotificationType = getDiskUsageNotificationTypeByPercentage((PercentageWatermarkSettings) watermarkSettings, nodeDiskUsageStats);
                } else if (watermarkSettings instanceof AbsoluteValueWatermarkSettings) {
                    currentNodeNotificationType = getDiskUsageNotificationTypeByAbsoluteValues((AbsoluteValueWatermarkSettings) watermarkSettings, nodeDiskUsageStats);
                }
                if (currentNodeNotificationType != null) {
                    String nodeIdentifier = firstNonNull(nodeDiskUsageStats.host(), nodeDiskUsageStats.ip());
                    notificationTypePerNodeIdentifier.merge(currentNodeNotificationType, Collections.singletonList(nodeIdentifier), (prev, cur) -> ImmutableList.<String>builder().addAll(prev).addAll(cur).build());
                }
            }
            if (notificationTypePerNodeIdentifier.isEmpty()) {
                fixAllDiskUsageNotifications();
            } else {
                publishDiskUsageNotifications(notificationTypePerNodeIdentifier);
            }
        }
    } catch (Exception e) {
        LOG.error("Error while trying to check Elasticsearch disk usage.Details: " + e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) Notification(org.graylog2.notifications.Notification) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) NodeDiskUsageStats(org.graylog2.indexer.cluster.health.NodeDiskUsageStats) ClusterAllocationDiskSettings(org.graylog2.indexer.cluster.health.ClusterAllocationDiskSettings) PercentageWatermarkSettings(org.graylog2.indexer.cluster.health.PercentageWatermarkSettings) AbsoluteValueWatermarkSettings(org.graylog2.indexer.cluster.health.AbsoluteValueWatermarkSettings) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class IndexerClusterCheckerThread method checkOpenFiles.

@VisibleForTesting
void checkOpenFiles() {
    if (notificationExists(Notification.Type.ES_OPEN_FILES)) {
        return;
    }
    boolean allHigher = true;
    final Set<NodeFileDescriptorStats> fileDescriptorStats = cluster.getFileDescriptorStats();
    for (NodeFileDescriptorStats nodeFileDescriptorStats : fileDescriptorStats) {
        final String name = nodeFileDescriptorStats.name();
        final String ip = nodeFileDescriptorStats.ip();
        final String host = nodeFileDescriptorStats.host();
        final long maxFileDescriptors = nodeFileDescriptorStats.fileDescriptorMax().orElse(-1L);
        if (maxFileDescriptors != -1L && maxFileDescriptors < MINIMUM_OPEN_FILES_LIMIT) {
            // Write notification.
            final String ipOrHostName = firstNonNull(host, ip);
            final Notification notification = notificationService.buildNow().addType(Notification.Type.ES_OPEN_FILES).addSeverity(Notification.Severity.URGENT).addDetail("hostname", ipOrHostName).addDetail("max_file_descriptors", maxFileDescriptors);
            if (notificationService.publishIfFirst(notification)) {
                LOG.warn("Indexer node <{}> ({}) open file limit is too low: [{}]. Set it to at least {}.", name, ipOrHostName, maxFileDescriptors, MINIMUM_OPEN_FILES_LIMIT);
            }
            allHigher = false;
        }
    }
    if (allHigher) {
        Notification notification = notificationService.build().addType(Notification.Type.ES_OPEN_FILES);
        notificationService.fixed(notification);
    }
}
Also used : NodeFileDescriptorStats(org.graylog2.indexer.cluster.health.NodeFileDescriptorStats) Notification(org.graylog2.notifications.Notification) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class DecodingProcessor method postProcessMessage.

@Nullable
private Message postProcessMessage(RawMessage raw, Codec codec, String inputIdOnCurrentNode, String baseMetricName, Message message, long decodeTime) {
    if (message == null) {
        metricRegistry.meter(name(baseMetricName, "failures")).mark();
        return null;
    }
    if (!message.isComplete()) {
        metricRegistry.meter(name(baseMetricName, "incomplete")).mark();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Dropping incomplete message {} on input <{}>. Parsed fields: [{}]", raw, inputIdOnCurrentNode, message.getFields());
        }
        return null;
    }
    message.setMessageQueueId(raw.getMessageQueueId());
    message.recordTiming(serverStatus, "parse", decodeTime);
    metricRegistry.timer(name(baseMetricName, "parseTime")).update(decodeTime, TimeUnit.NANOSECONDS);
    for (final RawMessage.SourceNode node : raw.getSourceNodes()) {
        switch(node.type) {
            case SERVER:
                // Always use the last source node.
                if (message.getField(Message.FIELD_GL2_SOURCE_INPUT) != null) {
                    LOG.debug("Multiple server nodes ({} {}) set for message id {}", message.getField(Message.FIELD_GL2_SOURCE_INPUT), node.nodeId, message.getId());
                }
                message.addField(Message.FIELD_GL2_SOURCE_INPUT, node.inputId);
                message.addField(Message.FIELD_GL2_SOURCE_NODE, node.nodeId);
                break;
            // TODO Due to be removed in Graylog 3.x
            case RADIO:
                // Always use the last source node.
                if (message.getField(Message.FIELD_GL2_SOURCE_RADIO_INPUT) != null) {
                    LOG.debug("Multiple radio nodes ({} {}) set for message id {}", message.getField(Message.FIELD_GL2_SOURCE_RADIO_INPUT), node.nodeId, message.getId());
                }
                message.addField(Message.FIELD_GL2_SOURCE_RADIO_INPUT, node.inputId);
                message.addField(Message.FIELD_GL2_SOURCE_RADIO, node.nodeId);
                break;
        }
    }
    if (inputIdOnCurrentNode != null) {
        try {
            message.setSourceInputId(inputIdOnCurrentNode);
        } catch (RuntimeException e) {
            LOG.warn("Unable to find input with id " + inputIdOnCurrentNode + ", not setting input id in this message.", e);
        }
    }
    final ResolvableInetSocketAddress remoteAddress = raw.getRemoteAddress();
    if (remoteAddress != null) {
        final String addrString = InetAddresses.toAddrString(remoteAddress.getAddress());
        message.addField(Message.FIELD_GL2_REMOTE_IP, addrString);
        if (remoteAddress.getPort() > 0) {
            message.addField(Message.FIELD_GL2_REMOTE_PORT, remoteAddress.getPort());
        }
        if (remoteAddress.isReverseLookedUp()) {
            // avoid reverse lookup if the hostname is available
            message.addField(Message.FIELD_GL2_REMOTE_HOSTNAME, remoteAddress.getHostName());
        }
        if (Strings.isNullOrEmpty(message.getSource())) {
            message.setSource(addrString);
        }
    }
    if (codec.getConfiguration() != null && codec.getConfiguration().stringIsSet(Codec.Config.CK_OVERRIDE_SOURCE)) {
        message.setSource(codec.getConfiguration().getString(Codec.Config.CK_OVERRIDE_SOURCE));
    }
    // Make sure that there is a value for the source field.
    if (Strings.isNullOrEmpty(message.getSource())) {
        message.setSource("unknown");
    }
    // The raw message timestamp is the receive time of the message. It has been created before writing the raw
    // message to the journal.
    message.setReceiveTime(raw.getTimestamp());
    metricRegistry.meter(name(baseMetricName, "processedMessages")).mark();
    decodedTrafficCounter.inc(message.getSize());
    return message;
}
Also used : ResolvableInetSocketAddress(org.graylog2.plugin.ResolvableInetSocketAddress) RawMessage(org.graylog2.plugin.journal.RawMessage) Nullable(javax.annotation.Nullable)

Example 9 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class DecodingProcessor method processMessage.

private void processMessage(final MessageEvent event) throws ExecutionException {
    final RawMessage raw = event.getRaw();
    // for backwards compatibility: the last source node should contain the input we use.
    // this means that extractors etc defined on the prior inputs are silently ignored.
    // TODO fix the above
    String inputIdOnCurrentNode;
    try {
        // .inputId checked during raw message decode!
        inputIdOnCurrentNode = Iterables.getLast(raw.getSourceNodes()).inputId;
    } catch (NoSuchElementException e) {
        inputIdOnCurrentNode = null;
    }
    final Codec.Factory<? extends Codec> factory = codecFactory.get(raw.getCodecName());
    if (factory == null) {
        LOG.warn("Couldn't find factory for codec <{}>, skipping message {} on input <{}>.", raw.getCodecName(), raw, inputIdOnCurrentNode);
        return;
    }
    final Codec codec = factory.create(raw.getCodecConfig());
    final String baseMetricName = name(codec.getClass(), inputIdOnCurrentNode);
    Message message = null;
    Collection<Message> messages = null;
    final Timer.Context decodeTimeCtx = parseTime.time();
    final long decodeTime;
    try {
        // TODO The Codec interface should be changed for 2.0 to support collections of messages so we can remove this hack.
        if (codec instanceof MultiMessageCodec) {
            messages = ((MultiMessageCodec) codec).decodeMessages(raw);
        } else {
            message = codec.decode(raw);
        }
    } catch (RuntimeException e) {
        LOG.error("Unable to decode raw message {} on input <{}>.", raw, inputIdOnCurrentNode);
        metricRegistry.meter(name(baseMetricName, "failures")).mark();
        throw e;
    } finally {
        decodeTime = decodeTimeCtx.stop();
    }
    if (message != null) {
        event.setMessage(postProcessMessage(raw, codec, inputIdOnCurrentNode, baseMetricName, message, decodeTime));
    } else if (messages != null && !messages.isEmpty()) {
        final List<Message> processedMessages = Lists.newArrayListWithCapacity(messages.size());
        for (final Message msg : messages) {
            final Message processedMessage = postProcessMessage(raw, codec, inputIdOnCurrentNode, baseMetricName, msg, decodeTime);
            if (processedMessage != null) {
                processedMessages.add(processedMessage);
            }
        }
        event.setMessages(processedMessages);
    }
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) MultiMessageCodec(org.graylog2.plugin.inputs.codecs.MultiMessageCodec) MultiMessageCodec(org.graylog2.plugin.inputs.codecs.MultiMessageCodec) Codec(org.graylog2.plugin.inputs.codecs.Codec) Timer(com.codahale.metrics.Timer) List(java.util.List) RawMessage(org.graylog2.plugin.journal.RawMessage) NoSuchElementException(java.util.NoSuchElementException)

Example 10 with Node

use of org.graylog2.indexer.cluster.Node in project graylog2-server by Graylog2.

the class PeriodicalsService method startPeriodicals.

private synchronized void startPeriodicals(Set<Periodical> periodicalsToStart) {
    final Sets.SetView<Periodical> notYetStartedPeriodicals = Sets.difference(periodicalsToStart, ImmutableSet.copyOf(periodicals.getAll()));
    int numOfPeriodicalsToSkip = periodicalsToStart.size() - notYetStartedPeriodicals.size();
    if (numOfPeriodicalsToSkip > 0) {
        LOG.warn("Skipping start of {} periodicals which have already been started.", numOfPeriodicalsToSkip);
    }
    for (Periodical periodical : notYetStartedPeriodicals) {
        try {
            periodical.initialize();
            if (!periodical.startOnThisNode()) {
                LOG.info("Not starting [{}] periodical. Not configured to run on this node.", periodical.getClass().getCanonicalName());
                continue;
            }
            // Register and start.
            periodicals.registerAndStart(periodical);
        } catch (Exception e) {
            LOG.error("Could not initialize periodical.", e);
        }
    }
}
Also used : Periodical(org.graylog2.plugin.periodical.Periodical) Sets(com.google.common.collect.Sets)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)29 ApiOperation (io.swagger.annotations.ApiOperation)28 MessageInput (org.graylog2.plugin.inputs.MessageInput)23 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)19 Input (org.graylog2.inputs.Input)15 AuditEvent (org.graylog2.audit.jersey.AuditEvent)14 Test (org.junit.Test)14 GET (javax.ws.rs.GET)13 Produces (javax.ws.rs.Produces)12 Node (org.graylog2.cluster.Node)12 Map (java.util.Map)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 PUT (javax.ws.rs.PUT)6 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)6 Notification (org.graylog2.notifications.Notification)6 Activity (org.graylog2.shared.system.activities.Activity)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 EventBus (com.google.common.eventbus.EventBus)5 URI (java.net.URI)5