I have a requirement to collect statistics of a JVM in regular time intervals using. Later, i need to log the JVM available memory/free memory, used memory, total memory.
Following are the two options i have thought of.
ManagementFactory.getMemoryPoolMXBeans() and iterating through each MemoryPoolMXBean and finally collecting the statistics using MemoryPoolMXBean.getUsage().
Runtime.freeMemory(), Runtime.maxMemory(), Runtime.totalMemory
Which is the best way to collect the statistics. using MemoryPoolMXBean.getUsage() or Runtime Class.