use of cn.myperf4j.base.metric.JvmMemoryMetrics in project MyPerf4J by ThinkpadNC5.
the class JvmMemoryCollector method collectMemoryMetrics.
public static JvmMemoryMetrics collectMemoryMetrics() {
long oldGenUsed = 0L, oldGenMax = 0L;
long permGenUsed = 0L, permGenMax = 0L;
long edenUsed = 0L, edenMax = 0L;
long survivorUsed = 0L, survivorMax = 0L;
long metaspaceUsed = 0L, metaSpaceMax = 0L;
long codeCacheUsed = 0L, codeCacheMax = 0L;
List<MemoryPoolMXBean> mxBeanList = ManagementFactory.getMemoryPoolMXBeans();
for (int i = 0; i < mxBeanList.size(); i++) {
MemoryPoolMXBean memoryPool = mxBeanList.get(i);
MemoryUsage usage = memoryPool.getUsage();
String poolName = memoryPool.getName();
if (poolName.endsWith("Perm Gen")) {
permGenUsed = usage.getUsed() >> 10;
permGenMax = usage.getMax() >> 10;
} else if (poolName.endsWith("Metaspace")) {
metaspaceUsed = usage.getUsed() >> 10;
metaSpaceMax = usage.getMax() >> 10;
} else if (poolName.endsWith("Code Cache")) {
codeCacheUsed = usage.getUsed() >> 10;
codeCacheMax = usage.getMax() >> 10;
} else if (poolName.endsWith("Old Gen")) {
oldGenUsed = usage.getUsed() >> 10;
oldGenMax = usage.getMax() >> 10;
} else if (poolName.endsWith("Eden Space")) {
edenUsed = usage.getUsed() >> 10;
edenMax = usage.getMax() >> 10;
} else if (poolName.endsWith("Survivor Space")) {
survivorUsed = usage.getUsed() >> 10;
survivorMax = usage.getMax() >> 10;
}
}
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
MemoryUsage nonHeapMem = memoryMXBean.getNonHeapMemoryUsage();
long nonHeapUsed = nonHeapMem.getUsed() >> 10;
long nonHeapMax = nonHeapMem.getMax() >> 10;
MemoryUsage heapMem = memoryMXBean.getHeapMemoryUsage();
long heapUsed = heapMem.getUsed() >> 10;
long heapMax = heapMem.getMax() >> 10;
return new JvmMemoryMetrics(heapUsed, heapMax, nonHeapUsed, nonHeapMax, permGenUsed, permGenMax, metaspaceUsed, metaSpaceMax, codeCacheUsed, codeCacheMax, oldGenUsed, oldGenMax, edenUsed, edenMax, survivorUsed, survivorMax);
}
use of cn.myperf4j.base.metric.JvmMemoryMetrics in project MyPerf4J by ThinkpadNC5.
the class InfluxJvmMemoryMetricsFormatter method format.
@Override
public String format(List<JvmMemoryMetrics> metricsList, long startMillis, long stopMillis) {
StringBuilder sb = SB_TL.get();
try {
long startNanos = startMillis * 1000 * 1000L;
for (int i = 0; i < metricsList.size(); ++i) {
JvmMemoryMetrics metrics = metricsList.get(i);
appendLineProtocol(metrics, startNanos, sb);
sb.append('\n');
}
return sb.substring(0, sb.length() - 1);
} finally {
sb.setLength(0);
}
}
use of cn.myperf4j.base.metric.JvmMemoryMetrics in project MyPerf4J by ThinkpadNC5.
the class JvmMetricsScheduler method processMemoryMetrics.
private void processMemoryMetrics(long processId, long startMillis, long stopMillis) {
memoryMetricsProcessor.beforeProcess(processId, startMillis, stopMillis);
try {
JvmMemoryMetrics metrics = JvmMemoryCollector.collectMemoryMetrics();
memoryMetricsProcessor.process(metrics, processId, startMillis, stopMillis);
} catch (Throwable t) {
Logger.error("JvmMetricsScheduler.processMemoryMetrics(" + processId + ", " + startMillis + ", " + stopMillis + ")", t);
} finally {
memoryMetricsProcessor.afterProcess(processId, startMillis, stopMillis);
}
}
use of cn.myperf4j.base.metric.JvmMemoryMetrics in project MyPerf4J by ThinkpadNC5.
the class StdJvmMemoryMetricsFormatter method format.
@Override
public String format(List<JvmMemoryMetrics> metricsList, long startMillis, long stopMillis) {
String dataTitleFormat = "%-14s%21s%12s%17s%12s%19s%12s%17s%13s%19s%13s%20s%15s%22s%15s%22s%n";
StringBuilder sb = new StringBuilder((metricsList.size() + 2) * (9 * 19 + 64));
sb.append("MyPerf4J JVM Memory Metrics [").append(DateFormatUtils.format(startMillis)).append(", ").append(DateFormatUtils.format(stopMillis)).append(']').append(LINE_SEPARATOR);
sb.append(String.format(dataTitleFormat, "SurvivorUsed", "SurvivorUsedPercent", "EdenUsed", "EdenUsedPercent", "OldGenUsed", "OldGenUsedPercent", "HeapUsed", "HeapUsedPercent", "NonHeapUsed", "NoHeapUsedPercent", "PermGenUsed", "PermGenUsedPercent", "MetaspaceUsed", "MetaspaceUsedPercent", "CodeCacheUsed", "CodeCacheUsedPercent"));
if (metricsList.isEmpty()) {
return sb.toString();
}
String dataFormat = "%-14d%21.2f%12d%17.2f%12d%19.2f%12d%17.2f%13d%19.2f%13d%20.2f%15d%22.2f%15d%22.2f%n";
for (int i = 0; i < metricsList.size(); ++i) {
JvmMemoryMetrics metrics = metricsList.get(i);
sb.append(String.format(dataFormat, metrics.getSurvivorUsed(), metrics.getSurvivorUsedPercent(), metrics.getEdenUsed(), metrics.getEdenUsedPercent(), metrics.getOldGenUsed(), metrics.getOldGenUsedPercent(), metrics.getHeapUsed(), metrics.getHeapUsedPercent(), metrics.getNonHeapUsed(), metrics.getNonHeapUsedPercent(), metrics.getPermGenUsed(), metrics.getPermGenUsedPercent(), metrics.getMetaspaceUsed(), metrics.getMetaspaceUsedPercent(), metrics.getCodeCacheUsed(), metrics.getCodeCacheUsedPercent()));
}
return sb.toString();
}
Aggregations