Search in sources :

Example 11 with MemoryUsage

use of java.lang.management.MemoryUsage in project hbase by apache.

the class MemorySizeUtil method getOnheapGlobalMemstoreSize.

/**
   * Returns the onheap global memstore limit based on the config
   * 'hbase.regionserver.global.memstore.size'.
   * @param conf
   * @return the onheap global memstore limt
   */
public static long getOnheapGlobalMemstoreSize(Configuration conf) {
    long max = -1L;
    final MemoryUsage usage = safeGetHeapMemoryUsage();
    if (usage != null) {
        max = usage.getMax();
    }
    float globalMemStorePercent = getGlobalMemStoreHeapPercent(conf, true);
    return ((long) (max * globalMemStorePercent));
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 12 with MemoryUsage

use of java.lang.management.MemoryUsage in project hbase by apache.

the class MemorySizeUtil method getL2BlockCacheHeapPercent.

/**
   * @param conf
   * @return The on heap size for L2 block cache.
   */
public static float getL2BlockCacheHeapPercent(Configuration conf) {
    float l2CachePercent = 0.0F;
    String bucketCacheIOEngineName = conf.get(HConstants.BUCKET_CACHE_IOENGINE_KEY, null);
    // L2 block cache can be on heap when IOEngine is "heap"
    if (bucketCacheIOEngineName != null && bucketCacheIOEngineName.startsWith("heap")) {
        float bucketCachePercentage = conf.getFloat(HConstants.BUCKET_CACHE_SIZE_KEY, 0F);
        long max = -1L;
        final MemoryUsage usage = safeGetHeapMemoryUsage();
        if (usage != null) {
            max = usage.getMax();
        }
        l2CachePercent = bucketCachePercentage < 1 ? bucketCachePercentage : (bucketCachePercentage * 1024 * 1024) / max;
    }
    return l2CachePercent;
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 13 with MemoryUsage

use of java.lang.management.MemoryUsage in project tomcat by apache.

the class StatusTransformer method writeVMState.

/**
     * Write the VM state.
     * @param writer The output writer
     * @param mode Mode <code>0</code> will generate HTML.
     *   Mode <code>1</code> will generate XML.
     * @throws Exception Propagated JMX error
     */
public static void writeVMState(PrintWriter writer, int mode) throws Exception {
    SortedMap<String, MemoryPoolMXBean> memoryPoolMBeans = new TreeMap<>();
    for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) {
        String sortKey = mbean.getType() + ":" + mbean.getName();
        memoryPoolMBeans.put(sortKey, mbean);
    }
    if (mode == 0) {
        writer.print("<h1>JVM</h1>");
        writer.print("<p>");
        writer.print(" Free memory: ");
        writer.print(formatSize(Long.valueOf(Runtime.getRuntime().freeMemory()), true));
        writer.print(" Total memory: ");
        writer.print(formatSize(Long.valueOf(Runtime.getRuntime().totalMemory()), true));
        writer.print(" Max memory: ");
        writer.print(formatSize(Long.valueOf(Runtime.getRuntime().maxMemory()), true));
        writer.print("</p>");
        writer.write("<table border=\"0\"><thead><tr><th>Memory Pool</th><th>Type</th><th>Initial</th><th>Total</th><th>Maximum</th><th>Used</th></tr></thead><tbody>");
        for (MemoryPoolMXBean memoryPoolMBean : memoryPoolMBeans.values()) {
            MemoryUsage usage = memoryPoolMBean.getUsage();
            writer.write("<tr><td>");
            writer.print(memoryPoolMBean.getName());
            writer.write("</td><td>");
            writer.print(memoryPoolMBean.getType());
            writer.write("</td><td>");
            writer.print(formatSize(Long.valueOf(usage.getInit()), true));
            writer.write("</td><td>");
            writer.print(formatSize(Long.valueOf(usage.getCommitted()), true));
            writer.write("</td><td>");
            writer.print(formatSize(Long.valueOf(usage.getMax()), true));
            writer.write("</td><td>");
            writer.print(formatSize(Long.valueOf(usage.getUsed()), true));
            if (usage.getMax() > 0) {
                writer.write(" (" + (usage.getUsed() * 100 / usage.getMax()) + "%)");
            }
            writer.write("</td></tr>");
        }
        writer.write("</tbody></table>");
    } else if (mode == 1) {
        writer.write("<jvm>");
        writer.write("<memory");
        writer.write(" free='" + Runtime.getRuntime().freeMemory() + "'");
        writer.write(" total='" + Runtime.getRuntime().totalMemory() + "'");
        writer.write(" max='" + Runtime.getRuntime().maxMemory() + "'/>");
        for (MemoryPoolMXBean memoryPoolMBean : memoryPoolMBeans.values()) {
            MemoryUsage usage = memoryPoolMBean.getUsage();
            writer.write("<memorypool");
            writer.write(" name='" + memoryPoolMBean.getName() + "'");
            writer.write(" type='" + memoryPoolMBean.getType() + "'");
            writer.write(" usageInit='" + usage.getInit() + "'");
            writer.write(" usageCommitted='" + usage.getCommitted() + "'");
            writer.write(" usageMax='" + usage.getMax() + "'");
            writer.write(" usageUsed='" + usage.getUsed() + "'/>");
        }
        writer.write("</jvm>");
    }
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) TreeMap(java.util.TreeMap) MemoryUsage(java.lang.management.MemoryUsage)

Example 14 with MemoryUsage

use of java.lang.management.MemoryUsage in project hadoop by apache.

the class JvmMetrics method getMemoryUsage.

private void getMemoryUsage(MetricsRecordBuilder rb) {
    MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage();
    MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
    Runtime runtime = Runtime.getRuntime();
    rb.addGauge(MemNonHeapUsedM, memNonHeap.getUsed() / M).addGauge(MemNonHeapCommittedM, memNonHeap.getCommitted() / M).addGauge(MemNonHeapMaxM, calculateMaxMemoryUsage(memNonHeap)).addGauge(MemHeapUsedM, memHeap.getUsed() / M).addGauge(MemHeapCommittedM, memHeap.getCommitted() / M).addGauge(MemHeapMaxM, calculateMaxMemoryUsage(memHeap)).addGauge(MemMaxM, runtime.maxMemory() / M);
}
Also used : MemoryUsage(java.lang.management.MemoryUsage)

Example 15 with MemoryUsage

use of java.lang.management.MemoryUsage in project sonarqube by SonarSource.

the class ProcessStateSystemInfo method toProtobuf.

// Visible for testing
ProtobufSystemInfo.Section toProtobuf(MemoryMXBean memoryBean) {
    ProtobufSystemInfo.Section.Builder builder = ProtobufSystemInfo.Section.newBuilder();
    builder.setName(name);
    MemoryUsage heap = memoryBean.getHeapMemoryUsage();
    addAttributeInMb(builder, "Heap Committed (MB)", heap.getCommitted());
    addAttributeInMb(builder, "Heap Init (MB)", heap.getInit());
    addAttributeInMb(builder, "Heap Max (MB)", heap.getMax());
    addAttributeInMb(builder, "Heap Used (MB)", heap.getUsed());
    MemoryUsage nonHeap = memoryBean.getNonHeapMemoryUsage();
    addAttributeInMb(builder, "Non Heap Committed (MB)", nonHeap.getCommitted());
    addAttributeInMb(builder, "Non Heap Init (MB)", nonHeap.getInit());
    addAttributeInMb(builder, "Non Heap Max (MB)", nonHeap.getMax());
    addAttributeInMb(builder, "Non Heap Used (MB)", nonHeap.getUsed());
    ThreadMXBean thread = ManagementFactory.getThreadMXBean();
    builder.addAttributesBuilder().setKey("Thread Count").setLongValue(thread.getThreadCount()).build();
    return builder.build();
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) MemoryUsage(java.lang.management.MemoryUsage)

Aggregations

MemoryUsage (java.lang.management.MemoryUsage)75 MemoryMXBean (java.lang.management.MemoryMXBean)15 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)15 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)6 RuntimeMXBean (java.lang.management.RuntimeMXBean)6 HashMap (java.util.HashMap)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)5 ThreadMXBean (java.lang.management.ThreadMXBean)4 Map (java.util.Map)4 IOException (java.io.IOException)3 MemoryType (java.lang.management.MemoryType)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)2 GarbageCollectionNotificationInfo (com.sun.management.GarbageCollectionNotificationInfo)2 File (java.io.File)2 BufferPoolMXBean (java.lang.management.BufferPoolMXBean)2 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)2 Date (java.util.Date)2 Properties (java.util.Properties)2