If you're lucky, and by lucky I mean smart, you have FusionReactor installed on your server. The breadth and usefulness of the information afforded by the tool (especially when it comes to memory and garbage collection) is lost on most who use it. On some occasions you may find yourself needing to pull some memory numbers on an old server (or maybe just someone else's server) who doesn't have any tools installed. I found myself in this situation the other day when tweaking an old legacy server. It's sharing 1GB of ram between CFMX7, Railo, Apache, MySQL, and Linux. It actually operates pretty good on so little memory. After converting a couple of the legacy sites over to ContentBox which utilizes ORM and in-memory caching for performance I needed to tweak the heap space to be a bit bigger in Railo but I needed to decrease something else to make room.
Now, this old server doesn't have FusionReactor installed, but it does have SeeFusion and while that tells me the usage of my heap space it doesn't show me the amount of permanent generation that's in use. Remember, perm gen is stored outside of heap so the total memory footprint of CF will roughly be heap + permgen. (Of course, that comes with a few caveats, namely that you're actually using a JVM with a permanent generation!)
I wanted to trim down the perm gen space on CF and Railo to make room for a bigger heap. I knew what the starting and max perm gen sizes were from my -XX:PermSize and -XX:MaxPermSize JVM args, but I didn't know how much of that was actually being used! Of course, I could enable verbose GC logging, but that's a lot of work to parse through and I would have to restart the server and wait for the JVM to "warm up" again. Instead I used a Java class called ManagementFactory. This class will give you stats on each of your memory spaces in including your new and old generations (part of the heap). Based on your JVM and your garbage collector in use, you will see different names for the memory spaces, but this bit of code will get you started to see how many MB of space are currently allocated and how much of that allocated space is in use. Keep in mind that perm gen is not typically garbage collected, so once it goes up you won't see it go down.
iter = createObject("java","java.lang.management.ManagementFactory").getMemoryPoolMXBeans().iterator();
item = iter.next();
name = item.getName();
type = item.getType().toString();
used = item.getUsage().getUsed()/1024/1024;
max = item.getUsage().getMax()/1024/1024;
writeOutput("#round(used)#MB / #round(max)#MB <br><br>");
Here is the output from my local CF10 install.
Code Cache (Non-heap memory)
5MB / 48MB
PS Eden Space (Heap memory)
82MB / 150MB
PS Survivor Space (Heap memory)
6MB / 92MB
PS Old Gen (Heap memory)
363MB / 683MB
PS Perm Gen (Non-heap memory)
83MB / 512MB
Try dumping out the Java object that comes back from getUsage() and see what other methods you can call. Hint, getUsage().toString() is a good place to start.