I'm currently trying to get servers direct memory value and store it into database, but I'm getting 0
value all the time, does my method fails to return the correct value of 500 MB
.
The method I have is this:
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
...
public int toGb(long valueInBytes) {
return (int) (valueInBytes / (1024 * 1024 * 1024));
}
public int getMemoryDirect() {
long memoryDirect = 0;
List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
for(BufferPoolMXBean pool : pools) {
if(pool.getName().equals("direct")) {
memoryDirect = pool.getTotalCapacity();
}
}
return toGb(memoryDirect);
}
Is there other way to retrieve this value?
Any help is apprecheated :)