当前位置: 首页>>代码示例>>Java>>正文


Java MemoryMXBean.getHeapMemoryUsage方法代码示例

本文整理汇总了Java中java.lang.management.MemoryMXBean.getHeapMemoryUsage方法的典型用法代码示例。如果您正苦于以下问题:Java MemoryMXBean.getHeapMemoryUsage方法的具体用法?Java MemoryMXBean.getHeapMemoryUsage怎么用?Java MemoryMXBean.getHeapMemoryUsage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.MemoryMXBean的用法示例。


在下文中一共展示了MemoryMXBean.getHeapMemoryUsage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: call

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
@Override
public String call() {
  Map<String, String> memoryMap = new HashMap<>();
  OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
  double cpu = osMxBean.getSystemLoadAverage();
  memoryMap.put("cpuLoad", String.format(doubleStringFormatter, round(cpu, doubleRoundPlaces)));

  ThreadMXBean threadmxBean = ManagementFactory.getThreadMXBean();
  int threadCount = threadmxBean.getThreadCount();
  memoryMap.put("cpuRunningThreads", String.valueOf(threadCount));

  MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
  MemoryUsage memHeapUsage = memBean.getHeapMemoryUsage();
  MemoryUsage nonHeapUsage = memBean.getNonHeapMemoryUsage();
  memoryMap.put("heapInit", String.valueOf(memHeapUsage.getInit()));
  memoryMap.put("heapMax", String.valueOf(memHeapUsage.getMax()));
  memoryMap.put("heapCommit", String.valueOf(memHeapUsage.getCommitted()));
  memoryMap.put("heapUsed", String.valueOf(memHeapUsage.getUsed()));
  memoryMap.put("nonHeapInit", String.valueOf(nonHeapUsage.getInit()));
  memoryMap.put("nonHeapMax", String.valueOf(nonHeapUsage.getMax()));
  memoryMap.put("nonHeapCommit", String.valueOf(nonHeapUsage.getCommitted()));
  memoryMap.put("nonHeapUsed", String.valueOf(nonHeapUsage.getUsed()));
  return memoryMap.toString();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:25,代码来源:MetricsServoRegistry.java

示例2: envi

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
@Override
public String envi() {
    Map<String, String> result = new HashMap<String, String>();
    // 系统信息
    result.put(RegistryMonitorConstants.OSNAME, System.getProperty(RegistryMonitorConstants.OSNAME, "not specified"));
    result.put(RegistryMonitorConstants.JAVA_VERSION, System.getProperty(RegistryMonitorConstants.JAVA_VERSION, "not specified"));
    result.put(RegistryMonitorConstants.JDK_PATH, System.getProperty(RegistryMonitorConstants.JDK_PATH, "not specified"));
    result.put(RegistryMonitorConstants.APP_PATH, System.getProperty(RegistryMonitorConstants.APP_PATH, "not specified"));

    // jvm信息
    MemoryMXBean memorymbean = ManagementFactory.getMemoryMXBean();
    MemoryUsage usage = memorymbean.getHeapMemoryUsage();
    result.put(RegistryMonitorConstants.JVM_INIT, String.valueOf(usage.getInit()));
    result.put(RegistryMonitorConstants.JVM_MAX, String.valueOf(usage.getMax()));
    result.put(RegistryMonitorConstants.JVM_USED, String.valueOf(usage.getUsed()));
    
    //线程信息
    ThreadMXBean tm = (ThreadMXBean) ManagementFactory.getThreadMXBean();
    result.put(RegistryMonitorConstants.JVM_THREAD_COUNT, String.valueOf(tm.getThreadCount()));
    result.put(RegistryMonitorConstants.JVM_PEAKTHREAD_COUNT, String.valueOf(tm.getPeakThreadCount()));
    result.put(RegistryMonitorConstants.JVM_CURRENTTHREAD_CPUTIME, String.valueOf(tm.getCurrentThreadCpuTime()));
    result.put(RegistryMonitorConstants.JVM_CURRENTTHREAD_USERTIME, String.valueOf(tm.getCurrentThreadUserTime()));
    return JSON.toJSONString(result);
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:25,代码来源:RegistryStatusServiceImpl.java

示例3: getMaxMemory

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
private static long getMaxMemory()
{
  try {
    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = null;
    
    if (memoryBean != null) {
      heap = memoryBean.getHeapMemoryUsage();
    }
    
    if (heap != null) {
      return Math.max(heap.getMax(), heap.getCommitted());
    }
    else {
      Runtime runtime = Runtime.getRuntime();
      
      return Math.max(runtime.maxMemory(), runtime.totalMemory());
    }
  } catch (Exception e) {
    e.printStackTrace();
  }

  return Runtime.getRuntime().maxMemory();
}
 
开发者ID:baratine,项目名称:baratine,代码行数:25,代码来源:KelpManagerBuilder.java

示例4: monitorMemory

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
public String monitorMemory() {
	StringBuilder sb = new StringBuilder("Memory:");
	MemoryMXBean mmbean = ManagementFactory.getMemoryMXBean();
	MemoryUsage hmu = mmbean.getHeapMemoryUsage();
	sb.append("[HeapMemoryUsage:");
	sb.append(" Used=" + formatBytes(hmu.getUsed() * 8));
	sb.append(" Committed=" + formatBytes(hmu.getCommitted() * 8));
	sb.append("]");

	MemoryUsage nhmu = mmbean.getNonHeapMemoryUsage();
	sb.append("[NonHeapMemoryUsage:");
	sb.append(" Used=" + formatBytes(nhmu.getUsed() * 8));
	sb.append(" Committed=" + formatBytes(nhmu.getCommitted() * 8));
	sb.append("]");
	return sb.toString();
}
 
开发者ID:blusechen,项目名称:venus,代码行数:17,代码来源:VMMonitor.java

示例5: getMemoryUsageStatsAsString

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
/**
 * Gets the memory footprint of the JVM in a string representation.
 *
 * @return A string describing how much heap memory and direct memory are allocated and used.
 */
public static String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean) {
	MemoryUsage heap = memoryMXBean.getHeapMemoryUsage();
	MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage();

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

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

	return String.format("Memory usage stats: [HEAP: %d/%d/%d MB, " +
			"NON HEAP: %d/%d/%d MB (used/committed/max)]",
			heapUsed, heapCommitted, heapMax, nonHeapUsed, nonHeapCommitted, nonHeapMax);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:22,代码来源:MemoryLogger.java

示例6: ClusterStatus

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
/**
 * @param numDecommissionedNodes number of decommission trackers
 */
ClusterStatus(int trackers, int blacklists, long ttExpiryInterval, 
              int maps, int reduces, int maxMaps, int maxReduces, 
              JobTracker.State state, int numDecommissionedNodes) {
  numActiveTrackers = trackers;
  numBlacklistedTrackers = blacklists;
  this.numExcludedNodes = numDecommissionedNodes;
  this.ttExpiryInterval = ttExpiryInterval;
  map_tasks = maps;
  reduce_tasks = reduces;
  max_map_tasks = maxMaps;
  max_reduce_tasks = maxReduces;
  this.state = state;

  MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
  MemoryUsage status = memoryMXBean.getHeapMemoryUsage();
  used_memory = status.getUsed();
  max_memory = status.getMax();
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:22,代码来源:ClusterStatus.java

示例7: memoryUsage

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
private MemoryUsage memoryUsage() {
    MemoryUsage usage = new MemoryUsage();
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    java.lang.management.MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
    usage.heapInit = heapMemoryUsage.getInit();
    usage.heapUsed = heapMemoryUsage.getUsed();
    usage.heapCommitted = heapMemoryUsage.getCommitted();
    usage.heapMax = heapMemoryUsage.getMax();

    java.lang.management.MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
    usage.nonHeapInit = nonHeapMemoryUsage.getInit();
    usage.nonHeapUsed = nonHeapMemoryUsage.getUsed();
    usage.nonHeapCommitted = nonHeapMemoryUsage.getCommitted();
    usage.nonHeapMax = nonHeapMemoryUsage.getMax();

    return usage;
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:18,代码来源:MemoryUsageController.java

示例8: getMetrics

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
@Override
public Map<String, Metric> getMetrics() {
    Map<String, Metric> metrics = super.getMetrics();
    MemoryMXBean memMxBean = ManagementFactory.getMemoryMXBean();

    registerGauge(metrics, MEMORY_OBJ_PENDING_FINALIZATION_COUNT_METRIC_NAME, memMxBean.getObjectPendingFinalizationCount());

    MemoryUsage heapMemUsage = memMxBean.getHeapMemoryUsage(), nonHeapMemUsage = memMxBean.getNonHeapMemoryUsage();

    registerMemoryUsageMetrics(metrics, MEMORY_HEAP_METRIC_NAME_PREFIX, heapMemUsage);
    registerMemoryUsageMetrics(metrics, MEMORY_NON_HEAP_METRIC_NAME_PREFIX, nonHeapMemUsage);
    registerMemoryUsageMetrics(metrics, MEMORY_TOTAL_METRIC_NAME_PREFIX, (heapMemUsage.getCommitted() + nonHeapMemUsage.getCommitted()),
        (heapMemUsage.getInit() + nonHeapMemUsage.getInit()), -1, (heapMemUsage.getUsed() + nonHeapMemUsage.getUsed()),
        (heapMemUsage.getMax() + nonHeapMemUsage.getMax()));

    ManagementFactory.getMemoryPoolMXBeans().stream().filter(MemoryPoolMXBean::isValid)
        .forEach(memPoolMxBean -> registerMemoryPoolMetrics(metrics, memPoolMxBean));

    ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class).stream().forEach(bufferPoolMxBean -> registerBufferPoolMetrics(metrics, bufferPoolMxBean));

    return metrics;
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:23,代码来源:MemoryMetricSet.java

示例9: getMemoryUsageStatsAsString

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
private String getMemoryUsageStatsAsString(MemoryMXBean memoryMXBean) {
	MemoryUsage heap = memoryMXBean.getHeapMemoryUsage();
	MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage();

	int mb = 1 << 20;

	int heapUsed = (int) (heap.getUsed() / mb);
	int heapCommitted = (int) (heap.getCommitted() / mb);
	int heapMax = (int) (heap.getMax() / mb);

	int nonHeapUsed = (int) (nonHeap.getUsed() / mb);
	int nonHeapCommitted = (int) (nonHeap.getCommitted() / mb);
	int nonHeapMax = (int) (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;
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:20,代码来源:TaskManager.java

示例10: checkStatus

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
@Override
public ICheckResult checkStatus(Locale locale) {
	MemoryMXBean memory = ManagementFactory.getMemoryMXBean();
	MemoryUsage heap = memory.getHeapMemoryUsage();
	long heapRatio = heap.getUsed() * 100 / heap.getMax();
	CheckResultBuilder result = result(this).messageBundle("net.sf.appstatus.core.check.impl.JvmCheck_msg", locale);
	if (heapRatio > limitError) {
		result.code(ICheckResult.ERROR).fatal().resolutionSteps("resolutionSteps.fatal", new Object[] {});
	} else if (heapRatio > limitWarn) {
		result.code(ICheckResult.ERROR).resolutionSteps("resolutionSteps.warn", new Object[] {});
	} else {
		result.code(ICheckResult.OK);
	}
	result.description("description", new Object[] { heapRatio });
	return result.build();
}
 
开发者ID:appstatus,项目名称:appstatus,代码行数:17,代码来源:JvmCheck.java

示例11: reportHeapUsage

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
private void reportHeapUsage(MemoryMXBean memoryMxBean, MetricRecorder.Context metricContext) {
    MemoryUsage usage = memoryMxBean.getHeapMemoryUsage();

    long used = usage.getUsed();
    metricContext.record(HEAP, used / M, Unit.MEGABYTE);

    long max = usage.getMax();
    if (max >= 0) {
        metricContext.record(HEAP_MAX, max / M, Unit.MEGABYTE);

        double used_percent = 100.0 * ((double)used/(double)max);
        metricContext.record(HEAP_USED, used_percent, Unit.PERCENT);
    }
}
 
开发者ID:awslabs,项目名称:swage,代码行数:15,代码来源:MemorySensor.java

示例12: Datum

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
/**
 * Constructor accepts some system values and generates some Java values.
 *
 * @param rss Resident set size.
 */
Datum(long rss) {
    MemoryMXBean mmxb = ManagementFactory.getMemoryMXBean();
    MemoryUsage muheap = mmxb.getHeapMemoryUsage();
    MemoryUsage musys = mmxb.getNonHeapMemoryUsage();

    timestamp = System.currentTimeMillis();
    this.rss = rss;
    javatotalheapmem = muheap.getCommitted();
    javausedheapmem = muheap.getUsed();
    javatotalsysmem = musys.getCommitted();
    javausedsysmem = musys.getUsed();
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:18,代码来源:SystemStatsCollector.java

示例13: doMemoryUpdates

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
private void doMemoryUpdates() {
    MemoryMXBean memoryMXBean =
           ManagementFactory.getMemoryMXBean();
    MemoryUsage memNonHeap =
            memoryMXBean.getNonHeapMemoryUsage();
    MemoryUsage memHeap =
            memoryMXBean.getHeapMemoryUsage();
    Runtime runtime = Runtime.getRuntime();

    metrics.setMetric("memNonHeapUsedM", memNonHeap.getUsed()/M);
    metrics.setMetric("memNonHeapCommittedM", memNonHeap.getCommitted()/M);
    metrics.setMetric("memHeapUsedM", memHeap.getUsed()/M);
    metrics.setMetric("memHeapCommittedM", memHeap.getCommitted()/M);
    metrics.setMetric("maxMemoryM", runtime.maxMemory()/M);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:16,代码来源:JvmMetrics.java

示例14: getJVMUsage

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
public Long getJVMUsage() {
    MemoryMXBean memBean = null;
    try {
        memBean = ManagementFactory.newPlatformMXBeanProxy
                (mbsconnector, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
        MemoryUsage heap = memBean.getHeapMemoryUsage();
        return heap.getUsed();
    } catch (IOException e) {
        logger.error("", e);
        return 0L;
    }
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:13,代码来源:JMXClient.java

示例15: run

import java.lang.management.MemoryMXBean; //导入方法依赖的package包/类
public void run() {
	bContinue = true;
	
	try {
		while (bContinue) {
	        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
	        MemoryUsage memoryUsageHeap = memoryMXBean.getHeapMemoryUsage(); 
	        MemoryUsage memoryUsageNonHeap = memoryMXBean.getNonHeapMemoryUsage();
	        
	        setUsageCounter("[Memory] Heap memory usage", memoryUsageHeap);
	        setUsageCounter("[Memory] Non heap memory usage", memoryUsageNonHeap);
	        setUsageCounter("[Memory] Total used", (memoryUsageHeap.getUsed() + memoryUsageNonHeap.getUsed()) / 1024 + "K");
	        
			synchronized (usageCounters) {
				List<String> ls = new ArrayList<String>();
				ls.addAll(usageCounters.keySet());
				Collections.sort(ls);
				for (String counter : ls) {
					Engine.logUsageMonitor.info(counter + ": " + usageCounters.get(counter));
				}
			}
		
			Thread.sleep(30000);
		}
	} catch (NullPointerException npe) {
		if (Engine.theApp == null) {
			// Engine.theApp == null probably means the engine is getting stopped
			// so gracefully ignore and exit thread
			return;
		}
		else {
			npe.printStackTrace();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}

	usageCounters = null;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:40,代码来源:UsageMonitor.java


注:本文中的java.lang.management.MemoryMXBean.getHeapMemoryUsage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。