I have a large Java app that uses massive amounts of memory at times and I would like to monitor this at intervals to see if heap or permgen limits are reached or have gotten ne
You can try visualVM, a Java profiler that goes with every JDK. You will find it in the "bin" folder.
Here's a snippet from a piece of code we have that periodically logs the memory usage of our app:
import java.lang.management.GarbageCollectorMXBean
import java.lang.management.ManagementFactory
import java.lang.management.MemoryPoolMXBean
import java.lang.management.MemoryUsage
log("Heap", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage());
log("NonHeap", ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage());
List<MemoryPoolMXBean> beans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean bean: beans) {
log(bean.getName(), bean.getUsage());
}
for (GarbageCollectorMXBean bean: ManagementFactory.getGarbageCollectorMXBeans()) {
log(bean.getName(), bean.getCollectionCount(), bean.getCollectionTime());
}