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());
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
}
Aggregations