April 25, 2012
The latest release to BugLog (1.5.202) makes it very easy to build a custom "Heartbeat Monitor" to check the status of a web application and send you an alert via Email or SMS whenever there are signs of trouble.
A Heartbeat Monitor is a process that periodically checks if an app is fine. This can be done in multiple ways, either by the monitored application "pinging" the monitoring application in a regular interval; or by the monitoring application asking the monitored application if everything is ok (on a regular interval too). In both cases if the monitored application detects that there is a problem (by not hearing from the app in a while, or not receiving the expected response) then it sends some sort of alert to a system administrator. The model we will describe in this post is the first one, in which the application being monitored (the "Target") contacts the monitoring application (BugLogHQ) in a regular interval. We will then instruct BugLogHQ to send us an alert whenever it hasn't heard from the target app in a set amount of time. On a follow up post, we will describe how to implement the second approach, in which BugLogHQ periodically checks the target app for its status and then tell us whenever there is a problem. There are two steps to build our monitor. First we need to modify our target application (the one that we want to see if it is OK) to periodically send a short message to BugLogHQ telling it that everything is great. The second step is configuring your BugLogHQ server to listen to these messages.
In the selection box next to "Create new rule of type" select "heartbeatMonitor" and click on "Go".
Here is where we tell BugLog how to recognize our heartbeat messages. Here are the different settings and what they mean:
Description: This is just a user-friendly text describing this particular rule. You can enter something like "Heartbeat monitor for application X"
Timespan: This is how long to wait for a heartbeat message. In Step 1 we configured our scheduled task to emit a heartbeat once every hour, so in here we will set the timespan to 70 minutes (1 hour plus 10 minutes) to give it some extra time just in case the app server is busy. This is the amount of time the monitor will wait before it thinks that there is something wrong.
Alert Interval: This controls how often we want to be notified if the app remains down. So if we set it to 30 minutes, once the initial alert of the app being down has been sent to us, BugLog will only notify us again once this amount of time has passed. Otherwise we would be receiving alerts every two minutes until the heartbeat messages are received again.
Application: This is the name of the application sending the heartbeats. This is the application name as it appears on its Application.cfc.
Host Name: Use this if you want to configure heartbeats for different hosts running the same application.
Severity Code: This tells the monitor how to identify which messages to listen to. Remember that on heartbeat.cfc on the target app we used a severity code of "ping". Use that value here. Using a unique severity code is useful so that the heartbeat messages can be filtered out from the other "normal" messages and bug reports.
Recipient Email: This is where to send the alerts whenever the target app appears to be down. You can add one or more email addresses here, or even use one of those email addresses that are linked to phone numbers to receive the alert via SMS message.
Save the rule definition and then Stop/Start the BugLogListener service (in the BugLogHQ homepage) to make the rule go into effect; and that's it!
So there you have it, you can now let BugLogHQ do its thing while you relax poolside drinking fruity umbrella drinks with the comfort of knowing that you will be alerted once your app starts getting into trouble.