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