So this isn't exactly old news, but while I've played quite a bit with the new Server Monitor in ColdFusion 8, I never really took a good look at the Alerts section. This week I finally took some time to play with alerts. Alerts are a great way to monitor your box without having to have the Server Monitor constantly running in a browser window. As you can guess, alerts will monitor various different things on your server and let you know if something goes wrong.
Out of the box you can monitor the following:
- Unresponsive Server: Checks your server to see if it is acting up and not responding well.
- Slow Server: Lets you see if the average response time for a request is more than a threshold amount.
- JVM Memory: Let's you throw an alert if the amount of memory being used goes over a certain amount.
- Timeouts: This is an interesting one. It lets you fire an alert if you have X amount of timeouts within Y seconds.
When an alert is fired, you have a variety of options. Some of the alert types have slightly different options, but in general they all allow for:
- Sending an Email.
- Dumping a snapshot. This is the same as the manual snapshots you can perform in the Server Monitor.
- Kill threads that take longer than a certain amount.
- Reject new requests
There is also another option which is pretty darn cool. An alert can trigger an "Alert CFC." This is a CFC that you write that contains two methods: onAlertStart and onAlertEnd. This allows you to do any custom handling of the alert that you want. You could log to the database. You could use the Instant Messenger Event Gateway to send you an IM. You can send an SMS message. The point is - you aren't limited to the options listed above. You can basically handle the alert with anything ColdFusion can do.
You can browse alerts in the Server Monitor as well:

The above screen shows that I have one alert. Double clicking on the alert lets me see the snapshot since I enabled that option. ColdFusion will also alert you when the status reverts to normal:

In order for snapshots to work, you must enable Server Monitoring, which as Charlie has blogged will add minimal overhead to your server. I also pinged Adobe about any impact from alerts in general and was told there was no impact that folks would need to be concerned about.
I'm currently using this myself - mainly to monitor the issues I've had lately with ColdFusionBloggers but also for curiosity's sake as well. Is anyone out there using this yet? Anyone written a custom alert CFC? (Would folks like to see an example of one?)
Archived Comments
This is one of the features I'm looking forward to most in CF8. In one of my current apps I have the requirement of reading and writing to some very old fox pro tables. I'm using a Type 4 JDBC driver written by some guys in China, and every once in a while we have server lockups and other seemingly unexplainable issues. It's going to be very nice to have some of these tools at our disposal.
I haven't had a chance to try it out yet but I've wondered so far.... if my server is unresponsive and having issues... how is it going to be able to run a CFC and email/SMS/IM me? Seems contradictory of the problem somewhat ;)
I'll quote from the Alerts Config page:
If the number of threads specified by Hung Thread Count execute for longer than the time specified by Busy Thread Time, the server is considered to be unresponsive.
So I think the idea is that the server is up - just acting badly.
They may also have reserved part of the underlying JVM or start a second JVM instance for server monitoring so that any of the code it runs, whether built-in or custom, is "out-of-band" in some manner and can run ColdFusion code even if the main threads of the ColdFusion server are having issues.
three and a half years late but I can comment on this.
a) the screen does not tell you which directory to place your .cfc in. After many trials it worked in \jrun4\bin
b) onAlertEnd() is working for me, i just do a CFDUMP of #arguments.theAlert# where theAlert is an argument that i defined and passed into the function. (the data type is a structure)
c) i'm having problems getting onAlertStart() event to trigger; this would be useful to me so I don't have to wait for the GC to finish before getting text'd
While I'm at it, I may as well post some code:
<cffunction name="onAlertEnd" access="public" returntype="string">
<cfargument name="structAlert" type="struct" required="yes">
<cfset vServerAlias = "DEVBOX")>
<cfmail from="CFIDE [#vServerAlias#]"
to="jchahine@bcbsm.com"
subject="JVM GC is FINISHED on #UCASE(vServerAlias)#"
type="html"
>
<p>JVM garbage cleanup on #UCASE(vServerAlias)# is finished.<p>
<cfdump var="#ARGUMENTS.structAlert#">
</cfmail>
<cfset myResult="1">
<cfreturn myResult>
</cffunction>
</cfcomponent>
I'm not showing the onAlertStart() because I didn't get it to kickoff yet. Still troubleshooting that.
Interesting. To your a), I wonder if it's simply path based, so if you had a CF mapping called mystuff, and put your cfc there, if you could then do
mystuff.mycfcname
as your CFC.
Thanks Ray,
i got onAlertStart() to work... (it turns out i had a typo in my email address so I didn't get the alert)
I also configured a CF Mapping "BIN" to where the .cfc resides (in jrun4\bin), but when I referenced BIN.CFCNAME in the alert config screen, nothing happened. No biggie though, as long as I share with my team where the .cfc resides we're good to go!