Example usage for java.lang.management MemoryUsage getUsed

List of usage examples for java.lang.management MemoryUsage getUsed

Introduction

In this page you can find the example usage for java.lang.management MemoryUsage getUsed.

Prototype

public long getUsed() 

Source Link

Document

Returns the amount of used memory in bytes.

Usage

From source file:ch.admin.suis.msghandler.servlet.PingServlet.java

private String calcPermSpace() {
    MemoryUsage nonHeap = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    long max = nonHeap.getMax();
    long used = nonHeap.getUsed();
    int percent = (int) Math.round(100.0 * used / max);
    return used + ":" + max + ":" + percent;
}

From source file:com.attribyte.essem.model.index.IndexStats.java

public String getPercentHeapUsed() {
    MemoryUsage usage = mxBean.getHeapMemoryUsage();
    return asPercent(RatioGauge.Ratio.of(usage.getUsed(), usage.getMax()).getValue());
}

From source file:com.attribyte.essem.model.index.IndexStats.java

public String getPercentNonHeapUsed() {
    MemoryUsage usage = mxBean.getNonHeapMemoryUsage();
    return asPercent(RatioGauge.Ratio.of(usage.getUsed(), usage.getMax()).getValue());
}

From source file:mondrian.util.UtilCompatibleJdk15.java

public Util.MemoryInfo getMemoryInfo() {
    return new Util.MemoryInfo() {
        protected final MemoryPoolMXBean TENURED_POOL = findTenuredGenPool();

        public Util.MemoryInfo.Usage get() {
            final MemoryUsage memoryUsage = TENURED_POOL.getUsage();
            return new Usage() {
                public long getUsed() {
                    return memoryUsage.getUsed();
                }//w w w.  ja va 2 s  .c o m

                public long getCommitted() {
                    return memoryUsage.getCommitted();
                }

                public long getMax() {
                    return memoryUsage.getMax();
                }
            };
        }
    };
}

From source file:org.apache.jxtadoop.metrics.jvm.JvmMetrics.java

private void doMemoryUpdates() {
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage();
    MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
    metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed() / M);
    metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted() / M);
    metrics.setMetric("memHeapUsedM", memHeap.getUsed() / M);
    metrics.setMetric("memHeapCommittedM", memHeap.getCommitted() / M);
}

From source file:org.rhq.enterprise.agent.promptcmd.GCPromptCommand.java

private void printMemoryUsage(PrintWriter out, String name, MemoryType type, MemoryUsage memUsage) {
    long init = memUsage.getInit();
    long max = memUsage.getMax();
    long used = memUsage.getUsed();
    long committed = memUsage.getCommitted();

    String typeStr;/*w  w  w  . j a v a2 s. c o m*/
    switch (type) {
    case HEAP:
        typeStr = "Heap";
        break;
    case NON_HEAP:
        typeStr = "Non-heap";
        break;
    default:
        typeStr = "?";
    }

    double usedPercentage = (used * 100.0) / committed;
    double committedPercentage = (committed * 100.0) / max;
    out.println(MSG.getMsg(AgentI18NResourceKeys.GC_MEM_USAGE, name, typeStr, init, max, used, usedPercentage,
            committed, committedPercentage));
}

From source file:org.vaadin.viritin.FilterableListContainerTest.java

private long reportMemoryUsage() {
    try {/*from  w w w .  j a  va 2s .c  o m*/
        System.gc();
        Thread.sleep(100);
        System.gc();
        Thread.sleep(100);
        System.gc();
        Thread.sleep(100);
        System.gc();
    } catch (InterruptedException ex) {
    }
    MemoryUsage mu = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    System.out.println("Memory used (M):" + mu.getUsed() / 1000000);
    return ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed();
}

From source file:me.doshou.admin.monitor.web.controller.HibernateCacheMonitorController.java

private void setMemoryInfo(Model model) {
    ///* www  .  j  a  v a  2  s .c o m*/
    MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
    long usedSystemMemory = heapMemoryUsage.getUsed();
    long maxSystemMemory = heapMemoryUsage.getMax();
    model.addAttribute("usedSystemMemory", usedSystemMemory);
    model.addAttribute("maxSystemMemory", maxSystemMemory);

    //
    Statistics statistics = (Statistics) model.asMap().get("statistics");
    String[] secondLevelCacheRegionNames = statistics.getSecondLevelCacheRegionNames();

    int totalMemorySize = 0;
    int totalMemoryCount = 0;
    int totalDiskCount = 0;

    for (String secondLevelCacheRegionName : secondLevelCacheRegionNames) {
        SecondLevelCacheStatistics secondLevelCacheStatistics = statistics
                .getSecondLevelCacheStatistics(secondLevelCacheRegionName);
        totalMemorySize += secondLevelCacheStatistics.getSizeInMemory();
        totalMemoryCount += secondLevelCacheStatistics.getElementCountInMemory();
        totalDiskCount += secondLevelCacheStatistics.getElementCountOnDisk();
    }

    model.addAttribute("totalMemorySize", totalMemorySize);
    model.addAttribute("totalMemoryCount", totalMemoryCount);
    model.addAttribute("totalDiskCount", totalDiskCount);
}

From source file:VerboseGC.java

/**
 * Prints the verbose GC log to System.out to list the memory usage of all
 * memory pools as well as the GC statistics.
 *//*from w  w  w. ja va 2s . c om*/
public void printVerboseGc() {
    System.out.print("Uptime: " + formatMillis(rmbean.getUptime()));
    for (GarbageCollectorMXBean gc : gcmbeans) {
        System.out.print(" [" + gc.getName() + ": ");
        System.out.print("Count=" + gc.getCollectionCount());
        System.out.print(" GCTime=" + formatMillis(gc.getCollectionTime()));
        System.out.print("]");
    }
    System.out.println();
    for (MemoryPoolMXBean p : pools) {
        System.out.print("  [" + p.getName() + ":");
        MemoryUsage u = p.getUsage();
        System.out.print(" Used=" + formatBytes(u.getUsed()));
        System.out.print(" Committed=" + formatBytes(u.getCommitted()));
        System.out.println("]");
    }
}

From source file:org.eclipse.gyrex.cloud.internal.NodeMetricsReporter.java

@Override
protected IStatus run(final IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return Status.CANCEL_STATUS;
    }//ww  w .  ja va  2s .c  o m

    try {
        final Properties metrics = new Properties() {
            private static final long serialVersionUID = 1L;

            @Override
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(keySet());
            }

            @Override
            public Set<Object> keySet() {
                return new TreeSet<Object>(super.keySet());
            }
        };
        final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
        metrics.setProperty("os.availableProcessors",
                String.valueOf(operatingSystemMXBean.getAvailableProcessors()));
        metrics.setProperty("os.systemLoadAverage",
                String.valueOf(operatingSystemMXBean.getSystemLoadAverage()));
        metrics.setProperty("os.committedVirtualMemorySize",
                getUsingReflection(operatingSystemMXBean, "getCommittedVirtualMemorySize"));
        metrics.setProperty("os.totalSwapSpaceSize",
                getUsingReflection(operatingSystemMXBean, "getTotalSwapSpaceSize"));
        metrics.setProperty("os.freeSwapSpaceSize",
                getUsingReflection(operatingSystemMXBean, "getFreeSwapSpaceSize"));
        metrics.setProperty("os.processCpuTime",
                getUsingReflection(operatingSystemMXBean, "getProcessCpuTime"));
        metrics.setProperty("os.freePhysicalMemorySize",
                getUsingReflection(operatingSystemMXBean, "getFreePhysicalMemorySize"));
        metrics.setProperty("os.totalPhysicalMemorySize",
                getUsingReflection(operatingSystemMXBean, "getTotalPhysicalMemorySize"));
        metrics.setProperty("os.openFileDescriptorCount",
                getUsingReflection(operatingSystemMXBean, "getOpenFileDescriptorCount"));
        metrics.setProperty("os.maxFileDescriptorCount",
                getUsingReflection(operatingSystemMXBean, "getMaxFileDescriptorCount"));

        final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        final MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
        metrics.setProperty("heap.used", String.valueOf(heapMemoryUsage.getUsed()));
        metrics.setProperty("heap.committed", String.valueOf(heapMemoryUsage.getCommitted()));
        metrics.setProperty("heap.max", String.valueOf(heapMemoryUsage.getMax()));
        metrics.setProperty("heap.init", String.valueOf(heapMemoryUsage.getInit()));
        final MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
        metrics.setProperty("nonHeap.used", String.valueOf(nonHeapMemoryUsage.getUsed()));
        metrics.setProperty("nonHeap.committed", String.valueOf(nonHeapMemoryUsage.getCommitted()));
        metrics.setProperty("nonHeap.max", String.valueOf(nonHeapMemoryUsage.getMax()));
        metrics.setProperty("nonHeap.init", String.valueOf(nonHeapMemoryUsage.getInit()));

        final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        metrics.setProperty("thread.count", String.valueOf(threadMXBean.getThreadCount()));
        metrics.setProperty("thread.peak", String.valueOf(threadMXBean.getPeakThreadCount()));
        metrics.setProperty("thread.totalStarted", String.valueOf(threadMXBean.getTotalStartedThreadCount()));

        final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        metrics.setProperty("uptime", String.valueOf(runtimeMXBean.getUptime()));

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final NodeInfo nodeInfo = CloudState.getNodeInfo();
        metrics.store(out, String.valueOf(nodeInfo));
        ZooKeeperGate.get().writeRecord(IZooKeeperLayout.PATH_NODES_METRICS.append(nodeInfo.getNodeId()),
                CreateMode.PERSISTENT, out.toByteArray());
        if (CloudDebug.nodeMetrics) {
            LOG.debug("Node metrics reported successfully.{}{}", SystemUtils.LINE_SEPARATOR,
                    new String(out.toByteArray(), CharEncoding.ISO_8859_1));
        }
    } catch (final Exception e) {
        LOG.warn("Failed to update node metrics. {}", e.getMessage());
    } finally {
        // reschedule
        schedule(DELAY);
    }

    return Status.OK_STATUS;
}