Search in sources :

Example 51 with MemoryMXBean

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>");
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean)

Example 52 with MemoryMXBean

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());
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) Bundle(org.osgi.framework.Bundle)

Example 53 with MemoryMXBean

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())));
    });
}
Also used : RestVerticle(org.folio.rest.RestVerticle) LRUCache(org.folio.rest.tools.utils.LRUCache) AES(org.folio.rest.security.AES) Date(java.util.Date) StatsTracker(org.folio.rest.tools.monitor.StatsTracker) Context(io.vertx.core.Context) BodyPart(javax.mail.BodyPart) PomReader(org.folio.rest.tools.PomReader) MemoryMXBean(java.lang.management.MemoryMXBean) Logger(org.apache.log4j.Logger) ThreadInfo(java.lang.management.ThreadInfo) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) LogUtil(org.folio.rest.tools.utils.LogUtil) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) JsonObject(io.vertx.core.json.JsonObject) ManagementFactory(java.lang.management.ManagementFactory) AsyncResult(io.vertx.core.AsyncResult) MemoryUsage(java.lang.management.MemoryUsage) MimeMultipart(javax.mail.internet.MimeMultipart) DecimalFormat(java.text.DecimalFormat) ThreadMXBean(java.lang.management.ThreadMXBean) Validate(org.folio.rest.annotations.Validate) TenantTool(org.folio.rest.tools.utils.TenantTool) PostgresClient(org.folio.rest.persist.PostgresClient) IOUtils(org.apache.commons.io.IOUtils) OutStream(org.folio.rest.tools.utils.OutStream) Response(javax.ws.rs.core.Response) AdminResource(org.folio.rest.jaxrs.resource.AdminResource) ClientGenerator(org.folio.rest.tools.ClientGenerator) LogManager(org.apache.log4j.LogManager) Handler(io.vertx.core.Handler) InputStream(java.io.InputStream) MemoryMXBean(java.lang.management.MemoryMXBean) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) MemoryUsage(java.lang.management.MemoryUsage) Date(java.util.Date) Validate(org.folio.rest.annotations.Validate)

Example 54 with MemoryMXBean

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);
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) HCatURI(org.apache.oozie.util.HCatURI)

Example 55 with MemoryMXBean

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);
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Aggregations

MemoryMXBean (java.lang.management.MemoryMXBean)84 MemoryUsage (java.lang.management.MemoryUsage)30 RuntimeMXBean (java.lang.management.RuntimeMXBean)18 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)12 IOException (java.io.IOException)11 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)11 ThreadMXBean (java.lang.management.ThreadMXBean)11 NotificationEmitter (javax.management.NotificationEmitter)10 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Map (java.util.Map)7 Test (org.junit.Test)7 Test (org.testng.annotations.Test)7 ObjectName (javax.management.ObjectName)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 Properties (java.util.Properties)5 MalformedObjectNameException (javax.management.MalformedObjectNameException)5 Notification (javax.management.Notification)5 MemoryMXBeanImpl (com.ibm.java.lang.management.internal.MemoryMXBeanImpl)4