I was having a discussion on a private list when David McGuigan came up with a very interesting idea. What he proposed is very cool and much more than what I'm going to demo here, but I thought a simple proof of concept might be of interest. The core of his idea involved a ColdFusion Administrator tool that would give a live report of running applications. This tool would provide a wealth of data and features, but I thought I'd quickly write up a proof of concept for something a bit simpler. In this example I'll demonstrate how to make use of the Admin API, and specifically the Server Monitor API, to create such a report.

I wrote my proof of concept within the CF Admin folder which allows me to run all API commands without needing to login. So for example:

<cfset sm = createObject("component", "CFIDE.adminapi.servermonitoring")>

<!--- Figure out what we have enabled. ---> <cfset settings = sm.getMonitorSettings()>

<!--- Get all the active apps as keys, the func below also returns the ram use if we've enabled it. ---> <cfset appScopeMemory = sm.getAllApplicationScopesMemoryUsed()>

The variable appScopeMemory returned a structure of active applications, including an empty one, so I create a list after removing the blank key.

<!--- we have a blank scope to remove ---> <cfset structDelete(appScopeMemory, "")> <cfset activeApps = listSort(structKeyList(appScopeMemory), "textnocase")>

Once I have the list of applications, I loop through it and run a few calls. For this simple proof of concept I just focus on the application and session scope usage.

<cfloop index="app" list="#activeApps#"> <cfset sessions = sm.getActiveSessions(app)> <cfset appvars = sm.getApplicationScopeMemoryUsed(app)>

<cfoutput> <div class="appBlock"> <h2>#app#</h2>

<cfif settings.memoryMonitoringEnabled> Application scope usage: #numberFormat(getTotalAppMemoryUsage(appvars))#<br/> </cfif> Application Variables: <cfdump var="#appvars#" expand="false" label="Application Vars"> <cfif settings.memoryMonitoringEnabled> Session scope usage: #numberFormat(getTotalSessionMemoryUsageForApp(sessions))#<br/> </cfif> Active Session Count: #sm.getActiveSessionCount(app)#<br/> <cfdump var="#sessions#" expand="false" label="Sessions">

</div> </cfoutput> </cfloop>

Here's an example of the result:

I was going to spend more time to properly format the dumps... but meh. It's a proof of concept and it serves the purpose. You can click to expand and see all the application variables and active sessions.

If you want to play with this code yourself, grab the download below. If you haven't played yet with ColdFusion Admin extensions, take a look at my guide.

Download attached file.