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", "java.lang.management.ManagementFactory")>
<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!
Archived Comments
Woo! I did something very similar just now: http://www.mccran.co.uk/ind..., 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.
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?
JVM memory is much easier. Give me a minute and I'll hunt up the URL.
java.lang.Runtime has it: http://download.oracle.com/...
You can also get it via the Admin API. I've used it in a few demos.
I'm not sure people even remember that .NET integration exists, but if you really wanted to you could get similar information via .NET:
http://www.anujgakhar.com/2...
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).
People still use .Net?
Ask Scott. I believe he's wrangling some as we speak.
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.
I believe the updates are JAR files in standard locations. You could check those directories.
Ah good point; I could just look in <cf install root>\lib\updates. I guess I was overthinking it. Thank you!
Is it possible to get remote servers memory usage?
I assume you are talking about the actual operating system memory use and not ColdFusion memory use. Try this:
<cfset mf = createObject("java", "java.lang.management.ManagementFactory")>
<cfset osbean = mf.getOperatingSystemMXBean()>
<cfoutput>
<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
</cfoutput>
Also - ColdFusion 10 added native functions for this.
@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
I need to get info display on a web page, something like the CF server monitor does but not using flex.
Use Ajax then.