Scope Enhancer
Since the ColdFusion server runs on top of a Java subsystem, I thought it was time for the Server scope to actually contain information about the Java server as well as the CFML processor. The Enhancer adds a new JVM key to the Server scope and adds more keys to the Server.OS structure.
*click image to view full size

New keys:
- server.jvm.memory
- server.jvm.memory.pools
- server.jvm.threads
- server.jvm.arguments
- server.os.CommittedVirtualMemorySize
- server.os.FreePhysicalMemorySize
- server.os.FreeSwapSpaceSize
- server.os.ProcessCpuTime
- server.os.TotalPhysicalMemorySize
- server.os.TotalSwapSpaceSize
- server.os.AvailableProcessors
- server.os.MBeanInfo
Of course, you can remove any information that you don’t want from the code, but even on my wimpy 500MB RAM/1.33 MHz laptop, execution time for the code was max 67ms and averaged about 32ms.
I created a Java library that you can now include in your ColdFusion web application’s WEB-INF\lib directory.

This makes the code much more simple to read and maintain. Here’s an example call to enhance your Server scope.
<cfscript>
runtime = createobject("java", "java.lang.Runtime");
enhancer = createobject("java", "orbwave.ScopeEnhancer");
mgmtFactory = createobject("java", "java.lang.management.ManagementFactory");
sys = createobject("java", "java.lang.System");
memoryPoolBean = mgmtFactory.MemoryPoolMXBeans;
server.jvm = StructNew();
server.jvm.memory = StructNew();
server.jvm.memory.pools = enhancer.memoryPools();
server.jvm.memory.free = runtime.getRuntime().freeMemory();
server.jvm.memory.max = runtime.getRuntime().maxMemory();
server.jvm.arguments = mgmtFactory.RuntimeMXBean.getInputArguments();
server.jvm.threads = enhancer.serverThreads();
server.jvm.properties = enhancer.systemProperties();
server.os.environmentVariables = enhancer.environmentVariables();
</cfscript>
One addition was made in the new library and that is the os.environmentVariables key that holds all of the environment variables of your operating system.

Steps to install
- Download enhancer.jar library
- Put the enhancer.jar file in your web application’s WEB-INF\lib directory.
- Restart your Java application server
- Copy the code shown above into application (for example, your onApplicationStart event in Application.cfc)
Now all of the information is available for your use.
