Search in sources :

Example 1 with NodeDiskUsageStats

use of org.graylog2.indexer.cluster.health.NodeDiskUsageStats 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 2 with NodeDiskUsageStats

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

the class ClusterAdapterES6 method diskUsageStats.

@Override
public Set<NodeDiskUsageStats> diskUsageStats() {
    final JsonNode nodes = catNodes("name", "role", "host", "ip", "diskUsed", "diskTotal", "diskUsedPercent");
    final ImmutableSet.Builder<NodeDiskUsageStats> setBuilder = ImmutableSet.builder();
    for (JsonNode jsonElement : nodes) {
        if (jsonElement.isObject()) {
            setBuilder.add(NodeDiskUsageStats.create(jsonElement.path("name").asText(), jsonElement.path("role").asText(), jsonElement.path("ip").asText(), jsonElement.path("host").asText(null), jsonElement.path("diskUsed").asText(), jsonElement.path("diskTotal").asText(), jsonElement.path("diskUsedPercent").asDouble(NodeDiskUsageStats.DEFAULT_DISK_USED_PERCENT)));
        }
    }
    return setBuilder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) JsonNode(com.fasterxml.jackson.databind.JsonNode) NodeDiskUsageStats(org.graylog2.indexer.cluster.health.NodeDiskUsageStats)

Example 3 with NodeDiskUsageStats

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

the class IndexerClusterCheckerThreadTest method mockNodeDiskUsageStats.

private Set<NodeDiskUsageStats> mockNodeDiskUsageStats(EnumSet<NodeRole> roles) {
    Set<NodeDiskUsageStats> nodesDiskUsageStats = new HashSet<>();
    NodeDiskUsageStats nodeDiskUsageStats = mock(NodeDiskUsageStats.class);
    when(nodeDiskUsageStats.ip()).thenReturn("0.0.0.0");
    when(nodeDiskUsageStats.diskTotal()).thenReturn(SIUnitParser.parseBytesSizeValue("100GB"));
    when(nodeDiskUsageStats.diskUsed()).thenReturn(SIUnitParser.parseBytesSizeValue("70GB"));
    when(nodeDiskUsageStats.diskAvailable()).thenReturn(SIUnitParser.parseBytesSizeValue("30GB"));
    when(nodeDiskUsageStats.diskUsedPercent()).thenReturn(70D);
    when(nodeDiskUsageStats.roles()).thenReturn(roles);
    nodesDiskUsageStats.add(nodeDiskUsageStats);
    return nodesDiskUsageStats;
}
Also used : NodeDiskUsageStats(org.graylog2.indexer.cluster.health.NodeDiskUsageStats) HashSet(java.util.HashSet)

Example 4 with NodeDiskUsageStats

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

the class IndexerClusterCheckerThreadTest method ignoresNonDataNodes.

@Test
public void ignoresNonDataNodes() throws Exception {
    final Set<NodeDiskUsageStats> nodeDiskUsageStats = mockNodeDiskUsageStats(EnumSet.of(MASTER_ELIGIBLE, TRANSFORM));
    when(cluster.getDiskUsageStats()).thenReturn(nodeDiskUsageStats);
    when(cluster.getClusterAllocationDiskSettings()).thenReturn(buildThresholdTriggeredClusterAllocationDiskSettings(ES_NODE_DISK_WATERMARK_LOW, WatermarkSettings.SettingsType.ABSOLUTE));
    Notification notification = new NotificationImpl();
    when(notificationService.buildNow()).thenReturn(notification);
    when(notificationService.isFirst(ES_NODE_DISK_WATERMARK_LOW)).thenReturn(true);
    indexerClusterCheckerThread.checkDiskUsage();
    verify(notificationService, never()).publishIfFirst(any());
}
Also used : NotificationImpl(org.graylog2.notifications.NotificationImpl) NodeDiskUsageStats(org.graylog2.indexer.cluster.health.NodeDiskUsageStats) Notification(org.graylog2.notifications.Notification) Test(org.junit.Test)

Example 5 with NodeDiskUsageStats

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

the class IndexerClusterCheckerThreadTest method notificationCreated.

private void notificationCreated(Notification.Type notificationType, WatermarkSettings.SettingsType watermarkSettingsType) throws Exception {
    Set<NodeDiskUsageStats> nodeDiskUsageStats = mockNodeDiskUsageStats();
    when(cluster.getDiskUsageStats()).thenReturn(nodeDiskUsageStats);
    if (watermarkSettingsType == WatermarkSettings.SettingsType.ABSOLUTE) {
        when(cluster.getClusterAllocationDiskSettings()).thenReturn(buildThresholdTriggeredClusterAllocationDiskSettings(notificationType, WatermarkSettings.SettingsType.ABSOLUTE));
    } else {
        when(cluster.getClusterAllocationDiskSettings()).thenReturn(buildThresholdTriggeredClusterAllocationDiskSettings(notificationType, WatermarkSettings.SettingsType.PERCENTAGE));
    }
    when(notificationService.isFirst(notificationType)).thenReturn(true);
    Notification notification = new NotificationImpl();
    when(notificationService.buildNow()).thenReturn(notification);
    indexerClusterCheckerThread.checkDiskUsage();
    ArgumentCaptor<Notification> argument = ArgumentCaptor.forClass(Notification.class);
    verify(notificationService, times(1)).publishIfFirst(argument.capture());
    Notification publishedNotification = argument.getValue();
    assertThat(publishedNotification.getType()).isEqualTo(notificationType);
}
Also used : NotificationImpl(org.graylog2.notifications.NotificationImpl) NodeDiskUsageStats(org.graylog2.indexer.cluster.health.NodeDiskUsageStats) Notification(org.graylog2.notifications.Notification)

Aggregations

NodeDiskUsageStats (org.graylog2.indexer.cluster.health.NodeDiskUsageStats)5 Notification (org.graylog2.notifications.Notification)3 NotificationImpl (org.graylog2.notifications.NotificationImpl)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 AbsoluteValueWatermarkSettings (org.graylog2.indexer.cluster.health.AbsoluteValueWatermarkSettings)1 ClusterAllocationDiskSettings (org.graylog2.indexer.cluster.health.ClusterAllocationDiskSettings)1 PercentageWatermarkSettings (org.graylog2.indexer.cluster.health.PercentageWatermarkSettings)1 Test (org.junit.Test)1