Getting additional machine information in ColdFusion

This post is more than 2 years old.

Rey asks:

Hey do you know how I can get the SERVER details information where coldfusion8 is running or any server within our network. I looked at the Server.Variables but that stuff is very basic. I need to get things like CPU type, RAM, Virtual Memory etc...Please help.

Now in general your code should be as portable as possible and shouldn't care about the machine it's running on. But there are definitely times when you need to know more about the environment your code is running in. Rey is correct that the Server scope provides a bit of this. You can see the operating system name and version along with other tidbits. You can also go down to Java if you want even more data. The java.lang.System object can reveal a lot of data about your system.

<cfset runtime = createObject("java", "java.lang.System")> <cfset props = runtime.getProperties()> <cfdump var="#props#"> <cfset env = runtime.getenv()> <cfdump var="#env#">

Run this on your own machine to see what's represented. Most of it should mimic what you see if you click the blue system info link in your ColdFusion admin. What's missing is the amount of RAM. I did some googling but everything I found reflected the amount of total/available RAM for the JVM, not the box itself. Luckily a follower on Twitter, appleseedexm, pointed out another Java interface, OperatingSystemMXBean. He pointed out that this doesn't work everywhere, but it worked for me. In order to get an instance of this interface you have to make an instance of a management factory:

<cfset mf = createObject("java", "")> <cfset osbean = mf.getOperatingSystemMXBean()> <cfoutput> free physical mem = #osbean.getFreePhysicalMemorySize()#<br/> total physical mem = #osbean.getTotalPhysicalMemorySize()#<br/> </cfoutput>

For my laptop this returned:

free physical mem = 4512501760
total physical mem = 8519028736

Hope this helps!

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Shaun McCran posted on 1/31/2011 at 2:03 AM

Woo! I did something very similar just now:, needed to find the jvm bersion on the server to confirm why my compiled app wouldn't run. (was getting a 'Unsupported major.minor version 49.0') java error.

Comment 2 by Steve Keator posted on 1/31/2011 at 6:25 PM

Interesting. Got a lot of cool information from this running on my local machine. Anyone know of any way to use something similar to this to see how much memory jRun is eating up?

Comment 3 by Raymond Camden posted on 1/31/2011 at 7:25 PM

JVM memory is much easier. Give me a minute and I'll hunt up the URL.

Comment 4 by Raymond Camden posted on 1/31/2011 at 7:26 PM

java.lang.Runtime has it:

You can also get it via the Admin API. I've used it in a few demos.

Comment 5 by todd sharp posted on 1/31/2011 at 9:03 PM

I'm not sure people even remember that .NET integration exists, but if you really wanted to you could get similar information via .NET:

I haven't tested it because quite frankly my .net install seems to be broken and I'm not going to bother fixing it (since this would probably be the only thing I'll ever use it for).

Comment 6 by Raymond Camden posted on 1/31/2011 at 9:12 PM

People still use .Net?

Comment 7 by todd sharp posted on 1/31/2011 at 9:38 PM

Ask Scott. I believe he's wrangling some as we speak.

Comment 8 by Randy Jacoy posted on 1/31/2011 at 10:52 PM

Does anyone know how to programmatically get the ColdFusion Update Level (patching level)? I am able to obtain most all of the other information from the CF Information page but I can't find the patching level.

Comment 9 by Raymond Camden posted on 2/1/2011 at 3:27 AM

I believe the updates are JAR files in standard locations. You could check those directories.

Comment 10 by Randy Jacoy posted on 2/1/2011 at 4:11 AM

Ah good point; I could just look in <cf install root>\lib\updates. I guess I was overthinking it. Thank you!

Comment 11 by spartan2276 posted on 5/23/2012 at 9:30 PM

Is it possible to get remote servers memory usage?

Comment 12 by Randy Jacoy posted on 5/23/2012 at 9:55 PM

I assume you are talking about the actual operating system memory use and not ColdFusion memory use. Try this:

<cfset mf = createObject("java", "")>
<cfset osbean = mf.getOperatingSystemMXBean()>

<cfset freeMemory = osbean.getFreePhysicalMemorySize() / 1024 / 1024>
<cfset totalMemory = osbean.getTotalPhysicalMemorySize() / 1024 / 1024>

Total Physical Memory: #NumberFormat(Round(totalMemory#))MB
Free Physical Memory:#NumberFormat(Round(freeMemory))#MB

Comment 13 by Raymond Camden posted on 5/23/2012 at 11:39 PM

Also - ColdFusion 10 added native functions for this.

Comment 14 by spartan2276 posted on 5/23/2012 at 11:56 PM

@Randy Jacoy,

Thanks but it gives me the same results. I get an accurate total memory count of what is on the actual server, but not the actual free memory count of the actual OS which is what I want, I need to use CF to get the actual OS server not CF server

Comment 15 by spartan2276 posted on 5/23/2012 at 11:58 PM

I need to get info display on a web page, something like the CF server monitor does but not using flex.

Comment 16 by Raymond Camden posted on 5/24/2012 at 1:05 AM

Use Ajax then.