An EventMonitor is a Monitor implementation that is used to capture an event in the system. An event is a occurrence in the system that does not wrap a unit of work; that is it is a singular occurence that could not be said to have a start and stop time.
How should I use an EventMonitor?
Below is an example of some monitoring code that fires an event in the case that a search validation error occurred.
EventMonitor monitor = new EventMonitor("HotelSearchValidationError"); monitor.set("location", location); monitor.set("arrivalDate", arrivalDate); monitor.set("departureDate", departureDate); monitor.fire();
This is all the code that is needed. When the fire() method is called, the EventMonitor will submit itself to the MonitoringEngine for processing.
There are format restrictions on the names you can use for monitors and attributes. This is to preserve our sanity and simplify issues downstream.
Monitor names and attribute names must conform to this regular expression:
If they do not, a RuntimeException will be thrown when you exercise the application code in question.
Additional Lifecycle Requirements
There is one more line of code you must add to your instrumentation if the spot in question will be the "topmost" usage of ERMA monitors within the current thread.
That line should occur just before the topmost monitor is constructed in your application thread. That call is a lifecycle signal, essentially, which lets your app tell ERMA that you expect there to be no pre-existing, higher-level monitors (called CompositeMonitor's in ERMA lingo, of which TransactionMonitor is the canonical example) at this point in the current thread.