Configuring Erma Using Spring

Using Spring to manage configuration for ERMA is the easiest way to get going. Let's look at the steps you would need to take to add this configuration to your application.

Starting up the system

When you're application starts up, you need to set some references on the MonitoringEngine and call startup(). Since the MonitoringEngine is a singleton, orbitz-lib-monitoring includes a simple bean that will interact with the MonitoringEngine on Spring's behalf. Here's the configuration that will create an instance of that bean. We will create the mpf bean in the next section.

<bean class="com.orbitz.monitoring.lib.BaseMonitoringEngineManager" init-method="startup" destroy-method="shutdown">
  <constructor-arg ref="mpf"/>
</bean>

Creating a MonitorProcessorFactory

We need to pass a MonitorProcessorFactory to the BaseMonitoringEngineManager to actually process Monitors. The best implementation to use here is the SimpleMonitorProcessFactory since it's made to be wired together. SimpleMonitorProcessorFactory takes an array of ProcessGroups in its constructor.

<bean id="mpf" class="com.orbitz.monitoring.lib.factory.SimpleMonitorProcessorFactory">
  <constructor-arg>
    <list>
      <ref bean="routeToLog"/>
    </list>
  </constructor-arg>
</bean>

Creating ProcessGroups

ProcessGroups are used to manage the routing of Monitors to MonitorProcessors. The constructors take MonitorProcessor references. These are the processors that should receive Monitors to process.

<bean id="routeToLog" class="com.orbitz.monitoring.lib.factory.ProcessGroup">
  <description>
    Routes all monitoring events to the log files for easy development testing of instrumentation
  </description>
  <constructor-arg ref="LogProcessor"/>
</bean>

You can also control which Monitor instances are processed by a ProcessGroup by defining an expression. Your expression should return true if a given Monitor should be processed by this ProcessGroup.

The JEXL library is used to parse and evaluate the boolean expression. The monitor to be evaluated is bound to the evaluation context with the name m. JEXL supports obtaining arbitrary properties on an object if that object implements the method get(String propertyName). It just so happens that ERMA uses this same method naming schema to get attributes. This means that your JEXL expression can access attributes of that monitor in a very natural way.

m.name == 'Foo'
m.count > 2
m.name.matches(".*BookEvent.*") && m.latency > 10000

Creating MonitorProcessors

The last piece, is definiing the MonitorProcessor instances that will process the Monitors. This is straight forward.

<bean id="LogProcessor" class="com.orbitz.monitoring.lib.processor.LoggingMonitorProcessor"/>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License