use of java.lang.management.MemoryMXBean in project OpenOLAT by OpenOLAT.
the class MemoryRenderer method render.
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
MemoryComponent cmp = (MemoryComponent) source;
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
sb.append("<div class='progress' ");
if (!cmp.isDomReplacementWrapperRequired()) {
sb.append(" id='o_c").append(cmp.getDispatchID()).append("'");
}
if (cmp.getMemoryType() == MemoryType.HEAP) {
renderDetails(sb, memoryBean.getHeapMemoryUsage().getMax(), MemoryType.HEAP);
} else if (cmp.getMemoryType() == MemoryType.NON_HEAP) {
renderDetails(sb, memoryBean.getNonHeapMemoryUsage().getMax(), MemoryType.NON_HEAP);
}
sb.append("</div>");
}
use of java.lang.management.MemoryMXBean in project adeptj-runtime by AdeptJ.
the class ToolsServlet method doGet.
/**
* Renders tools page.
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
Bundle[] bundles = BundleContextHolder.INSTANCE.getBundleContext().getBundles();
long startTime = ManagementFactory.getRuntimeMXBean().getStartTime();
MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
TemplateEngines.getDefault().render(TemplateContext.builder().request(req).response(resp).template(TOOLS_TEMPLATE).locale(req.getLocale()).contextObject(ContextObject.newContextObject().put("username", req.getRemoteUser()).put("sysProps", System.getProperties().entrySet()).put("totalBundles", bundles.length).put("bundles", bundles).put("runtime", JAVA_RUNTIME_NAME + "(build " + JAVA_RUNTIME_VERSION + ")").put("jvm", JAVA_VM_NAME + "(build " + JAVA_VM_VERSION + ", " + JAVA_VM_INFO + ")").put("startTime", Date.from(Instant.ofEpochMilli(startTime))).put("upTime", Times.format(startTime)).put("maxMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getMax())).put("usedMemory", FileUtils.byteCountToDisplaySize(memoryMXBean.getHeapMemoryUsage().getUsed())).put("processors", Runtime.getRuntime().availableProcessors())).build());
}
use of java.lang.management.MemoryMXBean in project raml-module-builder by folio-org.
the class AdminAPI method getAdminMemory.
@Validate
@Override
public void getAdminMemory(boolean history, java.util.Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
final StringBuilder dump = new StringBuilder();
vertxContext.owner().executeBlocking(code -> {
try {
dump.append("<br><table>");
for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
MemoryUsage mem = pool.getCollectionUsage();
MemoryUsage curMem = pool.getUsage();
MemoryUsage peakMem = pool.getPeakUsage();
long usageAfterGC = -1;
long currentUsage = -1;
double usageAfterGCPercent = -1;
double currentUsagePercent = -1;
long peakUsage = -1;
if (mem != null) {
usageAfterGC = mem.getUsed() / 1024 / 1024;
// Mimic jstat behavior
usageAfterGCPercent = (double) mem.getUsed() / (double) mem.getCommitted() * 100;
}
if (curMem != null) {
currentUsage = curMem.getUsed() / 1024 / 1024;
if (curMem.getMax() > 0) {
currentUsagePercent = (double) curMem.getUsed() / (double) curMem.getCommitted() * // Mimic jstat behavior
100;
}
}
if (peakMem != null) {
peakUsage = peakMem.getUsed() / 1024 / 1024;
}
dump.append("<tr><td>name: ").append(pool.getName()).append(" </td>").append("<td>memory usage after latest gc: <b>").append(usageAfterGC).append("</b>MB. </td>").append("<td>type: ").append(pool.getType()).append(" </td>").append("<td>estimate of memory usage: <b>").append(currentUsage).append("</b>MB. </td>").append("<td>peak usage: ").append(peakUsage).append("MB. </td>").append("<td> % used memory after GC: <b>").append(DECFORMAT.format(usageAfterGCPercent)).append("</b> </td>").append("<td> % used memory current: <b>").append(DECFORMAT.format(currentUsagePercent)).append("</b> </td></tr>");
}
dump.append("</table><br><br>");
final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
final MemoryUsage memInfo = memoryMXBean.getHeapMemoryUsage();
long memCommittedToJVMByOS = memInfo.getCommitted();
long memUsedByJVM = memInfo.getUsed();
dump.append("<b>Total: </b> Memory used/available(MB): ").append((memUsedByJVM / 1024 / 1024)).append("/").append(memCommittedToJVMByOS / 1024 / 1024).append("<br>");
if (history) {
StringBuilder historyMem = new StringBuilder();
jvmMemoryHistory.put(new Date(), dump.toString());
BiConsumer<Date, String> biConsumer = (key, value) -> historyMem.append(key.toInstant().toString() + "<br>" + value);
jvmMemoryHistory.forEach(biConsumer);
code.complete(historyMem);
} else {
jvmMemoryHistory.clear();
code.complete(dump);
}
} catch (Exception e) {
log.error(e);
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminMemoryResponse.withPlainInternalServerError("ERROR" + e.getMessage())));
}
}, result -> {
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminMemoryResponse.withHtmlOK(result.result().toString())));
});
}
use of java.lang.management.MemoryMXBean in project oozie by apache.
the class EhcacheHCatDependencyCacheExtended method assertSpeedAndMemory.
protected void assertSpeedAndMemory(int numItems, int insertTimeinMillis, int retrievalTimeinMillis, long memIncreaseAfterInsert, long memIncreaseAfterInsertAndGC) throws Exception {
PartitionDependencyManagerService pdms = Services.get().get(PartitionDependencyManagerService.class);
System.gc();
MemoryMXBean mb = ManagementFactory.getMemoryMXBean();
long usedMemBeforeInsert = mb.getHeapMemoryUsage().getUsed();
long startTime = System.currentTimeMillis();
for (int i = 0; i < numItems; i++) {
HCatURI dep = new HCatURI("hcat://hcat.server.com:5080/mydb/mytbl/id=" + i);
pdms.addMissingDependency(dep, "" + i);
}
long usedMemAfterInsert = mb.getHeapMemoryUsage().getUsed();
long endTime = System.currentTimeMillis();
LOG.info("Time taken to insert " + numItems + " items is " + (endTime - startTime));
assertTrue((endTime - startTime) < insertTimeinMillis);
LOG.info("Memory before and after insert: " + usedMemBeforeInsert + "," + usedMemAfterInsert);
verifyWaitingAction(pdms, numItems);
LOG.info("Time taken to retrieve " + numItems + " items is " + (System.currentTimeMillis() - endTime));
assertTrue((System.currentTimeMillis() - endTime) < retrievalTimeinMillis);
long usedMemAfterRetrieval = mb.getHeapMemoryUsage().getUsed();
System.gc();
long usedMemAfterGC = mb.getHeapMemoryUsage().getUsed();
LOG.info("Memory before insert = " + usedMemBeforeInsert);
LOG.info("Memory after insert = " + usedMemAfterInsert);
LOG.info("Memory after retrieval = " + usedMemAfterRetrieval);
LOG.info("Memory after GC = " + usedMemAfterGC);
// Commenting out as memory assertion is not reliable when running the full suite of tests.
// assertTrue((usedMemAfterInsert - usedMemBeforeInsert) < memIncreaseAfterInsert);
// assertTrue((usedMemAfterGC - usedMemBeforeInsert) < memIncreaseAfterInsertAndGC);
}
use of java.lang.management.MemoryMXBean in project sidewinder by srotya.
the class ResourceMonitor method memAndCPUMonitor.
public void memAndCPUMonitor() {
monitorGc();
MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
MemoryUsage heap = mem.getHeapMemoryUsage();
MemoryUsage nonheap = mem.getNonHeapMemoryUsage();
validateCPUUsage();
validateMemoryUsage("heap", heap, 10_485_760);
validateMemoryUsage("nonheap", nonheap, 1_073_741_824);
}
Aggregations