use of java.lang.management.MemoryPoolMXBean in project OpenOLAT by OpenOLAT.
the class MemoryRenderer method renderDetails.
private void renderDetails(StringOutput sb, long max, MemoryType type) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
long totalUsed = 0l;
List<MemoryPoolMXBean> typedPools = new ArrayList<>(4);
for (MemoryPoolMXBean pool : pools) {
if (pool.getType() == type) {
typedPools.add(pool);
totalUsed += pool.getUsage().getUsed();
}
}
String tooltip;
if (max == -1) {
tooltip = toMB(totalUsed) + "MB";
} else {
tooltip = toMB(totalUsed) + "MB / " + toMB(max) + "MB";
totalUsed = max;
}
sb.append(" title=\"").append(tooltip).append("\">");
int count = 0;
long totalUsedPercent = 0l;
for (MemoryPoolMXBean pool : typedPools) {
String name = pool.getName();
long used = pool.getUsage().getUsed();
long usedMB = toMB(used);
long usedPercent = toPercent(used, totalUsed);
totalUsedPercent += usedPercent;
if (totalUsedPercent > 100l) {
// never more than 100%
usedPercent = usedPercent - (totalUsedPercent - 100l);
}
sb.append("<div class='progress-bar ").append(bars[count++]).append("' role='progressbar' ").append(" aria-valuenow='").append(usedMB).append("'").append(" aria-valuemin='0' style='width:").append(usedPercent).append("%;'><span").append(" title=\"").append(usedMB).append("MB (").append(name).append(")\"").append(">").append(usedMB).append("MB (").append(name).append(")</span></div>");
if (count > bars.length) {
count = 0;
}
}
}
use of java.lang.management.MemoryPoolMXBean in project commons by craftercms.
the class MemoryMonitor method getMemoryStats.
/**
* Query all register MemoryPools to get information and create a {@link MemoryMonitor} Pojo
* @return List with all the memory usage stats.
*/
public static List<MemoryMonitor> getMemoryStats() {
ArrayList<MemoryMonitor> memoryPoolInformation = new ArrayList<>();
MemoryUsage heapMem = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
memoryPoolInformation.add(new MemoryMonitor(HEAP_MEMORY, heapMem));
MemoryUsage nonHeapMen = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
memoryPoolInformation.add(new MemoryMonitor(NON_HEAP_MEMORY, nonHeapMen));
for (MemoryPoolMXBean memMXBean : ManagementFactory.getMemoryPoolMXBeans()) {
memoryPoolInformation.add(new MemoryMonitor(memMXBean.getName(), memMXBean.getUsage()));
}
return Collections.unmodifiableList(memoryPoolInformation);
}
use of java.lang.management.MemoryPoolMXBean in project incubator-heron by apache.
the class JVMMetrics method updateMemoryPoolMetrics.
// Gather metrics for different memory pools in heap, for instance:
// Par Eden Space, Par Survivor Space, CMS Old Gen, CMS Perm Gen
private void updateMemoryPoolMetrics() {
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeanList) {
String normalizedKeyName = memoryPoolMXBean.getName().replaceAll("[^\\w]", "-");
MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
if (peakUsage != null) {
jvmPeakUsagePerMemoryPool.safeScope(normalizedKeyName + "-used").setValue(ByteAmount.fromBytes(peakUsage.getUsed()).asMegabytes());
jvmPeakUsagePerMemoryPool.safeScope(normalizedKeyName + "-committed").setValue(ByteAmount.fromBytes(peakUsage.getCommitted()).asMegabytes());
jvmPeakUsagePerMemoryPool.safeScope(normalizedKeyName + "-max").setValue(ByteAmount.fromBytes(peakUsage.getMax()).asMegabytes());
}
MemoryUsage collectionUsage = memoryPoolMXBean.getCollectionUsage();
if (collectionUsage != null) {
jvmCollectionUsagePerMemoryPool.safeScope(normalizedKeyName + "-used").setValue(ByteAmount.fromBytes(collectionUsage.getUsed()).asMegabytes());
jvmCollectionUsagePerMemoryPool.safeScope(normalizedKeyName + "-committed").setValue(ByteAmount.fromBytes(collectionUsage.getCommitted()).asMegabytes());
jvmCollectionUsagePerMemoryPool.safeScope(normalizedKeyName + "-max").setValue(ByteAmount.fromBytes(collectionUsage.getMax()).asMegabytes());
}
MemoryUsage estimatedUsage = memoryPoolMXBean.getUsage();
if (estimatedUsage != null) {
jvmEstimatedUsagePerMemoryPool.safeScope(normalizedKeyName + "-used").setValue(ByteAmount.fromBytes(estimatedUsage.getUsed()).asMegabytes());
jvmEstimatedUsagePerMemoryPool.safeScope(normalizedKeyName + "-committed").setValue(ByteAmount.fromBytes(estimatedUsage.getCommitted()).asMegabytes());
jvmEstimatedUsagePerMemoryPool.safeScope(normalizedKeyName + "-max").setValue(ByteAmount.fromBytes(estimatedUsage.getMax()).asMegabytes());
}
}
}
use of java.lang.management.MemoryPoolMXBean in project flink by apache.
the class MemoryLogger method getMemoryPoolStatsAsString.
/**
* Gets the memory pool statistics from the JVM.
*
* @param poolBeans The collection of memory pool beans.
* @return A string denoting the names and sizes of the memory pools.
*/
public static String getMemoryPoolStatsAsString(List<MemoryPoolMXBean> poolBeans) {
StringBuilder bld = new StringBuilder("Off-heap pool stats: ");
int count = 0;
for (MemoryPoolMXBean bean : poolBeans) {
if (bean.getType() == MemoryType.NON_HEAP) {
if (count > 0) {
bld.append(", ");
}
count++;
MemoryUsage usage = bean.getUsage();
long used = usage.getUsed() >> 20;
long committed = usage.getCommitted() >> 20;
long max = usage.getMax() >> 20;
bld.append('[').append(bean.getName()).append(": ");
bld.append(used).append('/').append(committed).append('/').append(max);
bld.append(" MB (used/committed/max)]");
}
}
return bld.toString();
}
use of java.lang.management.MemoryPoolMXBean in project pinpoint by naver.
the class DefaultDetailedMemoryMetricTest method testValidMax.
@Test
public void testValidMax() {
// Given
long givenUsed = 50L;
long givenMax = 100L;
double expectedUsage = givenUsed / (double) givenMax;
MemoryPoolMXBean mockMXBean = mock(MemoryPoolMXBean.class);
MemoryUsage mockUsage = mock(MemoryUsage.class);
when(mockMXBean.getUsage()).thenReturn(mockUsage);
when(mockUsage.getUsed()).thenReturn(50L);
when(mockUsage.getMax()).thenReturn(100L);
DetailedMemoryMetric detailedMemoryMetric = new DefaultDetailedMemoryMetric(MemoryPoolType.CMS, mockMXBean, mockMXBean, mockMXBean, mockMXBean, mockMXBean, mockMXBean);
// When
DetailedMemoryMetricSnapshot snapshot = detailedMemoryMetric.getSnapshot();
// Then
Assert.assertEquals(expectedUsage, snapshot.getNewGenUsage(), 0.01);
Assert.assertEquals(expectedUsage, snapshot.getOldGenUsage(), 0.01);
Assert.assertEquals(expectedUsage, snapshot.getSurvivorSpaceUsage(), 0.01);
Assert.assertEquals(expectedUsage, snapshot.getCodeCacheUsage(), 0.01);
Assert.assertEquals(expectedUsage, snapshot.getPermGenUsage(), 0.01);
Assert.assertEquals(expectedUsage, snapshot.getMetaspaceUsage(), 0.01);
}
Aggregations