本文整理汇总了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();
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
示例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();
}
示例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);
}
示例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;
}
}
示例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;
}