CFMX Memory usage and system info
I've put together a collection of useful System functions:
getJavaMemoryInfo
Returns a struct which contains info about the memory usage of the underlying java runtime<cfscript>
var runtime = createObject("java","java.lang.Runtime").getRuntime();
var stMemInfo = structNew();
stMemInfo.freeMemory = runtime.freeMemory();
stMemInfo.maxMemory = runtime.maxMemory();
stMemInfo.totalMemory = runtime.totalMemory();
stMemInfo.heapMemory = runtime.totalMemory()-runtime.freeMemory();
return stMemInfo;
</cfscript>
</cffunction>
getProcessorCount
Obviously enough returns the number of processors (that the java runtime can access) in the machine.
<cfscript>
var runtime = createObject("java","java.lang.Runtime").getRuntime();
return runtime.availableProcessors();
</cfscript>
</cffunction>
getServerName
Get the servername from the system (should work in both windows and unix platforms) but I haven't tested it recently.
<cfset var machineName = "">
<cfset var factory = createObject("java", "coldfusion.server.ServiceFactory")>
<cfif factory.runtimeservice.getServerScope().os.name CONTAINS "Windows">
<cfregistry action="get"
branch="HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\TCPIP\Parameters"
entry="Hostname"
variable="machineName"
type="String">
<cfelse>
<cfexecute name="/bin/hostname" variable="machineName" timeout="5" />
</cfif>
<cfreturn LCase(trim(machineName))>
</cffunction>
getCFInstanceName
Return the instance name - useful in clusters to see which instance is handling the request.
<cfscript>
// code to display the java instance name var jrunObj = createObject("java", "jrunx.kernel.JRun");
return jrunObj.getServerName();
</cfscript>
</cffunction>




