Reputation: 59331
Is there any way in ColdFusion code to determine on what server the code is executing? I have few load-balanced ColdFusion servers. I want to be able to know on which server the code is running when I catch an exception, so I can include that information in the logging / reporting code.
The servers are Windows 2003/IIS, if that matters. I'd love to know how to do it in Linux/Apache too. :-)
Upvotes: 18
Views: 12838
Reputation: 1
<cffunction name="getMachineName" returntype="string" access="private" output="false" hint="Server Name">
<cftry>
<cfexecute
name="hostname"
arguments=""
variable="local.machineNameResult"
timeout=10 />
<cfreturn Trim(local.machineNameResult)>
<cfcatch type="any">
<cfdump var="#cfcatch#">
<cfabort>
</cfcatch>
</cftry>
</cffunction>
<cfdump var="#getMachineName()#" />
<cfabort />
Upvotes: -2
Reputation: 717
For us using nodes behind a load balancing proxy I ended up calling the 'hostname' command, works on windows too - so here is the set:
<cfscript>
machineName = createObject("java", "java.net.InetAddress").localhost.getCanonicalHostName();
hostaddress = createObject("java", "java.net.InetAddress").localhost.getHostAddress();
</cfscript>
<cfdump var="#machineName#"><br />
<cfdump var="#hostaddress#"><br />
<cfdump var="#CGI.SERVER_NAME#"><br />
<cfexecute name = "hostname" timeout = "1"></cfexecute>
Upvotes: -1
Reputation: 1
Use the below piece of code to get the domain name.
<cfoutput>#cgi.server_name#</cfoutput>
Hoping this is what you are expecting.
Upvotes: -1
Reputation: 111
Another place to look for information about the executing JRun process is to instance the following:
<cfset oErrorJRun = createObject("java","jrunx.kernel.JRun")/>
<cfset strServerName = oErrorJRun.ServerName />
That will give you the name of the JRun instance where the code is being executed. We've run into occasions where in our cluster environment the IIS on one node will log the page hit, but the JRun on the other node will handle the request. Occasionally, we'll have one node's JRun stop responding, and we'll need to restart some services to get the traffic back to that node. I use the above code in my error handler plugin to stick the server name in an email I send to the admins, and to incorporate it in the filename where I write the debugging info.
Upvotes: 2
Reputation: 2031
This may help you further...
<cfscript>
machineName = createObject("java", "java.net.InetAddress").localhost.getCanonicalHostName();
hostaddress = createObject("java", "java.net.InetAddress").localhost.getHostAddress();
</cfscript>
<cfdump var="#machineName#"><br />
<cfdump var="#hostaddress#"><br />
Upvotes: 29
Reputation: 45127
I believe that CGI.SERVER_NAME will get you what you want.
Edit per comment: You might be able to do something a bit more "low level" ...
<cfset inet = CreateObject("java", "java.net.InetAddress")>
<cfdump var = "#inet.getLocalhost().gethostname()#">
(No CF server here at work, so I can't test that).
Upvotes: 2
Reputation: 17152
You can use Server Variables like
server.coldfusion.appserver
server.coldfusion.expiration
server.coldfusion.productlevel
server.coldfusion.productname
server.coldfusion.productversion
server.coldfusion.rootdir
server.coldfusion.serialnumber
server.coldfusion.supportedlocales
server.os.additionalinformation
server.os.arch
server.os.buildnumber
server.os.name
server.os.version
to tweak your code to specific platforms. Do a <cfdump var=”#SERVER#” />
to see what's applicable to your version of Coldfusion.
You can get the hostname with a Java call:
<cfscript>
machineName = createObject("java", "java.net.InetAddress").localhost.getHostName();
instanceName = createObject("java", "jrunx.kernel.JRun").getServerName();
</cfscript>
Upvotes: 9