use of java.lang.management.MemoryPoolMXBean in project hive by apache.
the class HeapMemoryMonitor method getTenuredGenPool.
private static MemoryPoolMXBean getTenuredGenPool() {
for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
final String vendor = System.getProperty("java.vendor");
final boolean isTenured = isTenured(pool);
if (!isTenured) {
continue;
}
final boolean isCollectionUsageThresholdSupported = pool.isCollectionUsageThresholdSupported();
if (isCollectionUsageThresholdSupported) {
return pool;
} else {
final boolean isUsageThresholdSupported = pool.isUsageThresholdSupported();
if (isUsageThresholdSupported) {
return pool;
} else {
LOG.error("{} vendor does not support isCollectionUsageThresholdSupported() and isUsageThresholdSupported()" + " for tenured memory pool '{}'.", vendor, pool.getName());
}
}
}
return null;
}
use of java.lang.management.MemoryPoolMXBean in project DataX by alibaba.
the class VMInfo method getDelta.
public synchronized void getDelta(boolean print) {
try {
if (VMInfo.isSunOsMBean(osMXBean)) {
long curUptime = runtimeMXBean.getUptime();
long curProcessTime = getLongFromOperatingSystem(osMXBean, "getProcessCpuTime");
// 百分比, uptime是ms,processTime是nano
if ((curUptime > lastUpTime) && (curProcessTime >= lastProcessCpuTime)) {
float curDeltaCpu = (float) (curProcessTime - lastProcessCpuTime) / ((curUptime - lastUpTime) * totalProcessorCount * 10000);
processCpuStatus.setMaxMinCpu(curDeltaCpu);
processCpuStatus.averageCpu = (float) curProcessTime / (curUptime * totalProcessorCount * 10000);
lastUpTime = curUptime;
lastProcessCpuTime = curProcessTime;
}
}
for (GarbageCollectorMXBean garbage : garbageCollectorMXBeanList) {
GCStatus gcStatus = processGCStatus.gcStatusMap.get(garbage.getName());
if (gcStatus == null) {
gcStatus = new GCStatus();
gcStatus.name = garbage.getName();
processGCStatus.gcStatusMap.put(garbage.getName(), gcStatus);
}
long curTotalGcCount = garbage.getCollectionCount();
gcStatus.setCurTotalGcCount(curTotalGcCount);
long curtotalGcTime = garbage.getCollectionTime();
gcStatus.setCurTotalGcTime(curtotalGcTime);
}
if (memoryPoolMXBeanList != null && !memoryPoolMXBeanList.isEmpty()) {
for (MemoryPoolMXBean pool : memoryPoolMXBeanList) {
MemoryStatus memoryStatus = processMomoryStatus.memoryStatusMap.get(pool.getName());
if (memoryStatus == null) {
memoryStatus = new MemoryStatus();
memoryStatus.name = pool.getName();
processMomoryStatus.memoryStatusMap.put(pool.getName(), memoryStatus);
}
memoryStatus.commitedSize = pool.getUsage().getCommitted();
memoryStatus.setMaxMinUsedSize(pool.getUsage().getUsed());
long maxMemory = memoryStatus.commitedSize > 0 ? memoryStatus.commitedSize : memoryStatus.maxSize;
memoryStatus.setMaxMinPercent(maxMemory > 0 ? (float) 100 * memoryStatus.usedSize / maxMemory : -1);
}
}
if (print) {
LOG.info(processCpuStatus.getDeltaString() + processMomoryStatus.getDeltaString() + processGCStatus.getDeltaString());
}
} catch (Exception e) {
LOG.warn("no need care, the fail is ignored : vmInfo getDelta failed " + e.getMessage(), e);
}
}
use of java.lang.management.MemoryPoolMXBean in project heron by twitter.
the class JVMMetrics method updateMemoryPoolMetrics.
// Gather metrics for different memory pools in heap, for instance:
// Par Eden Space, Par Survivor Space, CMS Old Gen, CMS Perm Gen
private void updateMemoryPoolMetrics() {
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeanList) {
String normalizedKeyName = memoryPoolMXBean.getName().replaceAll("[^\\w]", "-");
MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
if (peakUsage != null) {
jvmPeakUsagePerMemoryPool.safeScope(normalizedKeyName + "-used").setValue(ByteAmount.fromBytes(peakUsage.getUsed()).asMegabytes());
jvmPeakUsagePerMemoryPool.safeScope(normalizedKeyName + "-committed").setValue(ByteAmount.fromBytes(peakUsage.getCommitted()).asMegabytes());
jvmPeakUsagePerMemoryPool.safeScope(normalizedKeyName + "-max").setValue(ByteAmount.fromBytes(peakUsage.getMax()).asMegabytes());
}
MemoryUsage collectionUsage = memoryPoolMXBean.getCollectionUsage();
if (collectionUsage != null) {
jvmCollectionUsagePerMemoryPool.safeScope(normalizedKeyName + "-used").setValue(ByteAmount.fromBytes(collectionUsage.getUsed()).asMegabytes());
jvmCollectionUsagePerMemoryPool.safeScope(normalizedKeyName + "-committed").setValue(ByteAmount.fromBytes(collectionUsage.getCommitted()).asMegabytes());
jvmCollectionUsagePerMemoryPool.safeScope(normalizedKeyName + "-max").setValue(ByteAmount.fromBytes(collectionUsage.getMax()).asMegabytes());
}
MemoryUsage estimatedUsage = memoryPoolMXBean.getUsage();
if (estimatedUsage != null) {
jvmEstimatedUsagePerMemoryPool.safeScope(normalizedKeyName + "-used").setValue(ByteAmount.fromBytes(estimatedUsage.getUsed()).asMegabytes());
jvmEstimatedUsagePerMemoryPool.safeScope(normalizedKeyName + "-committed").setValue(ByteAmount.fromBytes(estimatedUsage.getCommitted()).asMegabytes());
jvmEstimatedUsagePerMemoryPool.safeScope(normalizedKeyName + "-max").setValue(ByteAmount.fromBytes(estimatedUsage.getMax()).asMegabytes());
}
}
}
use of java.lang.management.MemoryPoolMXBean in project Payara by payara.
the class MemoryReporter method init.
private void init() throws RuntimeException {
try {
this.rmbean = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
this.mmbean = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
ObjectName poolName = new ObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*");
;
ObjectName gcName = new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*");
Set mbeans = mbsc.queryNames(poolName, null);
if (mbeans != null) {
pools = new ArrayList<MemoryPoolMXBean>();
Iterator iterator = mbeans.iterator();
MemoryPoolMXBean p = null;
while (iterator.hasNext()) {
ObjectName objName = (ObjectName) iterator.next();
p = ManagementFactory.newPlatformMXBeanProxy(mbsc, objName.getCanonicalName(), MemoryPoolMXBean.class);
pools.add(p);
}
}
mbeans = mbsc.queryNames(gcName, null);
if (mbeans != null) {
gcmbeans = new ArrayList<GarbageCollectorMXBean>();
Iterator iterator = mbeans.iterator();
GarbageCollectorMXBean gc = null;
while (iterator.hasNext()) {
ObjectName objName = (ObjectName) iterator.next();
gc = ManagementFactory.newPlatformMXBeanProxy(mbsc, objName.getCanonicalName(), GarbageCollectorMXBean.class);
gcmbeans.add(gc);
}
}
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
use of java.lang.management.MemoryPoolMXBean in project uavstack by uavorg.
the class JVMStateCapHandler method readHeapPoolUsage.
private void readHeapPoolUsage(MonitorElementInstance instance) {
List<MemoryPoolMXBean> pmbList = ManagementFactory.getMemoryPoolMXBeans();
/*for (MemoryPoolMXBean mpmb : pmbList) {
String jvmMemPoolName = getHeapPoolName(mpmb.getName().trim());
MemoryUsage mu = mpmb.getUsage();
instance.setValue(jvmMemPoolName + "_use", mu.getUsed());
instance.setValue(jvmMemPoolName + "_commit", mu.getCommitted());
instance.setValue(jvmMemPoolName + "_max", mu.getMax());
instance.setValue(jvmMemPoolName + "_init", mu.getInit());
}*/
Set<String> addedSet = new HashSet<String>();
for (MemoryPoolMXBean mpmb : pmbList) {
String jvmMemPoolName = getHeapPoolName(mpmb.getName().trim());
MemoryUsage mu = mpmb.getUsage();
if (addedSet.contains(jvmMemPoolName)) {
instance.setValue(jvmMemPoolName + "_use", (Long) instance.getValue(jvmMemPoolName + "_use") + mu.getUsed());
instance.setValue(jvmMemPoolName + "_commit", (Long) instance.getValue(jvmMemPoolName + "_commit") + mu.getCommitted());
instance.setValue(jvmMemPoolName + "_max", (Long) instance.getValue(jvmMemPoolName + "_max") + mu.getMax());
instance.setValue(jvmMemPoolName + "_init", (Long) instance.getValue(jvmMemPoolName + "_init") + mu.getInit());
} else {
addedSet.add(jvmMemPoolName);
instance.setValue(jvmMemPoolName + "_use", mu.getUsed());
instance.setValue(jvmMemPoolName + "_commit", mu.getCommitted());
instance.setValue(jvmMemPoolName + "_max", mu.getMax());
instance.setValue(jvmMemPoolName + "_init", mu.getInit());
}
}
}
Aggregations