919 - 926 - 9847

Quick and dirty uptime monitor

Although we use FusionReactor to determine the health of our servers on our team, the environment as a whole is still monitored by another group. And they cannot access FusionReactor. Our previous method of monitoring just a URL worked fine when the servers were not clustered. Now, however, you can't really be sure what instance you're on. Therefore, we get false up/down messages for a specific instance.

What I've done is this, I've got a new monitor.cfm file such as the one below:


<cfscript>
    System = createObject("java","java.lang.System");
JRun = createObject("java","jrunx.kernel.JRun");
</cfscript>
<cfset this_servername = JRun.getServerName()>
<cfoutput>
    Instance: #this_servername#<br>
    Server Name: #cgi.Server_Name#<br>
</cfoutput>
<!--- Change timeout behavior if more than one instance is displayed --->
<cfif isdefined('url.all')>
    <cfset timeoutBehavior=15>
<cfelse>
    <cfset timeoutBehavior=28>
</cfif>
<!--- Ensure that url.instance is defined --->
<cfparam name="url.instance" default="all">


<cfif url.instance EQ 'someinstance' or url.instance EQ 'all'>
<br><br>
<cfset sStatus="">
<cftry>
<cfhttp method="get"
        url="http://someinstance.com:9301/monitor.cfm"
        timeout="#timeoutBehavior#"
        throwOnError="true">

        <cfcatch type="any"><cfset sStatus="bad"></cfcatch>
</cftry>
<b>SOMEINSTANCE 1 - status</b> <cfif sStatus EQ "bad">Down<cfelse>Up</cfif>
<cfif sStatus EQ "" OR sStatus EQ "good">
    <cfoutput>#cfhttp.filecontent#</cfoutput>
</cfif>
</cfif>

This code calls out to a file sitting within the instances built-in web server path. Since I need to leave this enabled to effectively manage the instance anyway, it's a good way to test that it's "alive". That monitor.cfm file contains:


<cfscript>
    System = createObject("java","java.lang.System");
JRun = createObject("java","jrunx.kernel.JRun");
</cfscript>

<cfinclude template="Duration.cfm">
<cfset uptime = duration(server.coldfusion.expiration,now())><br>
<b>Uptime</b><br>
<cfoutput>#uptime.days# Day(s) #uptime.hours# Hour(s) #uptime.minutes# Minute(s)</cfoutput><br>

<cfset this_servername = JRun.getServerName()>
<cfoutput>Instance: #this_servername#</cfoutput>

This display the instance information, and uses the UDF duration call (from CFLIB) to get the uptime count for the server. This information is then used within the first monitor call to display uptime status.

Why bother? Well, I need some type of text on the page to tell the monitor (soon to be Nagios) that my instances are up. And near as I can tell, this is the only accurate way to do so. It's not pretty, I admit, but it gets the job done.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)