}
public MeasuredResource getMeasuredResource() {
//if (memBean == null)
// memBean = ManagementFactory.getMemoryMXBean();
ProcessMemoryUtilization memoryUtilization;
MemoryUsage heapUsage = null;
MemoryUsage nonHeapUsage = null;
double utilization = 0;
if(memBean!=null) {
heapUsage = memBean.getHeapMemoryUsage();
nonHeapUsage = memBean.getNonHeapMemoryUsage();
utilization = (double)heapUsage.getUsed()/(double)heapUsage.getMax();
}
if (sigar!=null) {
try {
double vSize = sigar.getProcessVirtualMemorySize(pid)/MB;
double resident = sigar.getProcessResidentMemory(pid);
double shared = sigar.getProcessSharedMemory(pid);
vSize = (vSize>0?vSize/MB:vSize);
resident = (resident>0?resident/MB:resident);
shared = (shared>0?shared/MB:shared);
if(logger.isTraceEnabled()) {
NumberFormat nf = NumberFormat.getInstance();
StringBuilder builder = new StringBuilder();
nf.setMaximumFractionDigits(2);
builder.append("\n");
builder.append("VSize = ").append(nf.format(vSize)).append(" MB\n");
builder.append("Resident = ").append(nf.format(resident)).append(" MB\n");
builder.append("Shared = ").append(shared).append("\n");
builder.append("Heap Init = ").append(nf.format(heapUsage.getInit()/MB)).append(" MB\n");
builder.append("Heap Used = ").append(nf.format(heapUsage.getUsed()/MB)).append(" MB\n");
builder.append("Heap Max = ").append(nf.format(heapUsage.getMax()/MB)).append(" MB\n");
builder.append("Heap Committed = ").append(nf.format(heapUsage.getMax()/MB)).append(" MB\n");
builder.append("Non Heap Init = ").append(nf.format(nonHeapUsage.getInit()/MB)).append(" MB\n");
builder.append("Non Heap Used = ").append(nf.format(nonHeapUsage.getUsed()/MB)).append(" MB\n");
builder.append("Non Heap Max = ").append(nf.format(nonHeapUsage.getMax()/MB)).append(" MB\n");
builder.append("Non Heap Committed = ").append(nf.format(nonHeapUsage.getMax()/MB)).append(" MB");
logger.trace(builder.toString());
}
if(heapUsage!=null) {
memoryUtilization = new ProcessMemoryUtilization(id,
utilization,
vSize,
resident,
shared,
heapUsage.getInit()/MB,
heapUsage.getUsed()/MB,
heapUsage.getMax()/MB,
heapUsage.getCommitted()/MB,
nonHeapUsage.getInit()/MB,
nonHeapUsage.getUsed()/MB,
nonHeapUsage.getMax()/MB,
nonHeapUsage.getCommitted()/MB,
tVals);
} else {
memoryUtilization = new ProcessMemoryUtilization(id, utilization, vSize, resident, shared, tVals);
}
} catch (Exception e) {
logger.warn("SIGAR exception getting Process Memory", e);
memoryUtilization = getJvmMemoryUtilization(utilization, heapUsage, nonHeapUsage);