Example usage for java.lang.management MemoryUsage getMax

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

Introduction

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

Prototype

public long getMax() 

Source Link

Document

Returns the maximum amount of memory in bytes that can be used for memory management.

Usage

From source file:org.apache.flink.runtime.taskmanager.TaskManager.java

private String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean) {
    MemoryUsage heap = memoryMXBean.getHeapMemoryUsage();
    MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage();

    int mb = 20;/*from  ww  w  .j  a  v  a2 s. c om*/

    long heapUsed = heap.getUsed() >> mb;
    long heapCommitted = heap.getCommitted() >> mb;
    long heapMax = heap.getMax() >> mb;

    long nonHeapUsed = nonHeap.getUsed() >> mb;
    long nonHeapCommitted = nonHeap.getCommitted() >> mb;
    long nonHeapMax = nonHeap.getMax() >> mb;

    String msg = String.format(
            "Memory usage stats: [HEAP: %d/%d/%d MB, NON HEAP: %d/%d/%d MB (used/comitted/max)]", heapUsed,
            heapCommitted, heapMax, nonHeapUsed, nonHeapCommitted, nonHeapMax);

    return msg;
}

From source file:org.apache.hadoop.hbase.regionserver.HRegionServer.java

ClusterStatusProtos.ServerLoad buildServerLoad(long reportStartTime, long reportEndTime) {
    // We're getting the MetricsRegionServerWrapper here because the wrapper computes requests
    // per second, and other metrics  As long as metrics are part of ServerLoad it's best to use
    // the wrapper to compute those numbers in one place.
    // In the long term most of these should be moved off of ServerLoad and the heart beat.
    // Instead they should be stored in an HBase table so that external visibility into HBase is
    // improved; Additionally the load balancer will be able to take advantage of a more complete
    // history./*ww w  . ja v a  2s  .  c o  m*/
    MetricsRegionServerWrapper regionServerWrapper = this.metricsRegionServer.getRegionServerWrapper();
    Collection<HRegion> regions = getOnlineRegionsLocalContext();
    MemoryUsage memory = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();

    ClusterStatusProtos.ServerLoad.Builder serverLoad = ClusterStatusProtos.ServerLoad.newBuilder();
    serverLoad.setNumberOfRequests((int) regionServerWrapper.getRequestsPerSecond());
    serverLoad.setTotalNumberOfRequests((int) regionServerWrapper.getTotalRequestCount());
    serverLoad.setUsedHeapMB((int) (memory.getUsed() / 1024 / 1024));
    serverLoad.setMaxHeapMB((int) (memory.getMax() / 1024 / 1024));
    Set<String> coprocessors = this.hlog.getCoprocessorHost().getCoprocessors();
    for (String coprocessor : coprocessors) {
        serverLoad.addCoprocessors(Coprocessor.newBuilder().setName(coprocessor).build());
    }
    RegionLoad.Builder regionLoadBldr = RegionLoad.newBuilder();
    RegionSpecifier.Builder regionSpecifier = RegionSpecifier.newBuilder();
    for (HRegion region : regions) {
        serverLoad.addRegionLoads(createRegionLoad(region, regionLoadBldr, regionSpecifier));
    }
    serverLoad.setReportStartTime(reportStartTime);
    serverLoad.setReportEndTime(reportEndTime);
    if (this.infoServer != null) {
        serverLoad.setInfoServerPort(this.infoServer.getPort());
    } else {
        serverLoad.setInfoServerPort(-1);
    }
    return serverLoad.build();
}