mirror of
https://github.com/apache/nifi.git
synced 2025-02-09 11:35:05 +00:00
NIFI-8642 Select the default Old Gen Memory Pool for Memory Reporting Task
This closes #5115. Signed-off-by: Tamas Palfy <tamas.bertalan.palfy@gmail.com>
This commit is contained in:
parent
5c91143dc2
commit
d7a8d275c9
@ -36,11 +36,11 @@ import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryPoolMXBean;
|
||||
import java.lang.management.MemoryUsage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Reporting task used to monitor usage of memory after Garbage Collection has
|
||||
@ -90,15 +90,23 @@ import java.util.stream.Collectors;
|
||||
+ " that the memory pool is exceeding this threshold.")
|
||||
public class MonitorMemory extends AbstractReportingTask {
|
||||
|
||||
private static final List<String> GC_OLD_GEN_POOLS = Collections.unmodifiableList(Arrays.asList("Tenured Gen", "PS Old Gen", "G1 Old Gen", "CMS Old Gen", "ZHeap"));
|
||||
private static final AllowableValue[] memPoolAllowableValues;
|
||||
private static String defaultMemoryPool;
|
||||
|
||||
static {
|
||||
// Only allow memory pool beans that support usage thresholds, otherwise we wouldn't report anything anyway
|
||||
List<MemoryPoolMXBean> memoryPoolBeans = ManagementFactory.getMemoryPoolMXBeans().stream().filter(MemoryPoolMXBean::isUsageThresholdSupported).collect(Collectors.toList());
|
||||
memPoolAllowableValues = new AllowableValue[memoryPoolBeans.size()];
|
||||
for (int i = 0; i < memPoolAllowableValues.length; i++) {
|
||||
memPoolAllowableValues[i] = new AllowableValue(memoryPoolBeans.get(i).getName());
|
||||
}
|
||||
memPoolAllowableValues = ManagementFactory.getMemoryPoolMXBeans()
|
||||
.stream()
|
||||
.filter(MemoryPoolMXBean::isUsageThresholdSupported)
|
||||
.map(MemoryPoolMXBean::getName)
|
||||
.map(AllowableValue::new)
|
||||
.toArray(AllowableValue[]::new);
|
||||
defaultMemoryPool = Arrays.stream(memPoolAllowableValues)
|
||||
.map(AllowableValue::getValue)
|
||||
.filter(GC_OLD_GEN_POOLS::contains)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static final PropertyDescriptor MEMORY_POOL_PROPERTY = new PropertyDescriptor.Builder()
|
||||
@ -110,6 +118,7 @@ public class MonitorMemory extends AbstractReportingTask {
|
||||
+ " running host platform and JVM")
|
||||
.required(true)
|
||||
.allowableValues(memPoolAllowableValues)
|
||||
.defaultValue(defaultMemoryPool)
|
||||
.build();
|
||||
public static final PropertyDescriptor THRESHOLD_PROPERTY = new PropertyDescriptor.Builder()
|
||||
.name("Usage Threshold")
|
||||
|
Loading…
x
Reference in New Issue
Block a user