Logging Service Invocation Metadata to Database

Using the StatisticsJDBCInterceptor, Membrane Monitor and Router can log metadata about service invocation to any database that can be accessed via JDBC.
Each entry in the database will contain:

Version 2.1.0 and never

To activate database logging you can use the following proxies.xml file.
<membrane>
	<serviceProxy name="predic8.com" port="2000">
		<statisticsJDBC dataSource="dataSource" />
		<target host="membrane-soa.org" port="80" />
	</serviceProxy>
</membrane>

The attribute dataSource must name a data source defined in the monitor-beans.xml file. Further down you will find more information about data sources.

Version 1.6.0 to 2.0.x

To activate database logging, uncomment the following XML snippet in the file monitor-beans.xml located in conf directory:
<!--
 Storing exchange statistics in database 
 ======================================= 
 You can store exchange statistical data on permanent storage. Please uncomment 
 the following bean definition and configure the bean below. Do not forget 
 to provide jdbc connector jar file in the lib directory. 
-->
<!--
<bean class="com.predic8.membrane.core.interceptor.statistics.StatisticsJDBCInterceptor" init-method="init">
	<property name="dataSource" ref="dataSource" />
</bean>
-->

As you can see, the bean tag references a data source.

Data Sources

For some common databases the monitor-beans.xml file already contains bean definitions for data sources. The bean definitions for data sources are further down in the file monitor-beans.xml.

If you are using MySQL:

Find and uncomment the following bean definition in the monitor-beans.xml file:
<!--
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
	<property name="driverClassName" value="com.mysql.jdbc.Driver" />
	<property name="url" value="jdbc:mysql://localhost:3306/membrane" />
	<property name="username" value="root" />
	<property name="password" value="root" />
</bean>
-->
Adjust the url, username, and password properties, restart the application, and you're all set.

If you are using Oracle:

Find and uncomment the following bean definition in the monitor-beans.xml file:
<!--
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
	<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
	<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:your-database" />
	<property name="username" value="your-username" />
	<property name="password" value="your-password" />
</bean>
-->
Adjust the url, username, and password properties, restart the application, and you're all set.

Note: if you drop the 'statistic' table for some reason, do not forget to delete the sequence named 'stat_seq' and the trigger named 'stat_seq_trigger'.

If you are using Derby:

Find and uncomment the following bean definition in the monitor-beans.xml file:
<!--
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
	<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
	<property name="url" value="jdbc:derby://localhost:1527/membranedb-test;create=true" />
	<property name="username" value="APP" />
	<property name="password" value="root" />
</bean>
-->
Adjust the url, username, and password properties, restart the application, and you're all set.

If you are using some other database:

Create and add a new data source bean definition to monitor-beans.xml file according to bean definitions above. For more specific information about driver class name and url patterns please refer to your database connector's documentation.

Note: The StatisticsJDBCInterceptor uses the following table structure in your database:
CREATE TABLE `statistics` (
	`id` INT NOT NULL PRIMARY KEY, 
	`statuscode` INT, 
	`time` VARCHAR(155), 
	`rule` VARCHAR(255), 
	`method` VARCHAR(50), 
	`path` VARCHAR(1000), 
	`client` VARCHAR(255), 
	`server` VARCHAR(255), 
	`reqcontenttype` VARCHAR(100), 
	`reqcontentlength` INT, 
	`respcontenttype` VARCHAR(100), 
	`respcontentlength` INT, 
	`duration` LONG 
);
If the table doesn't exist, it will be created. To modify the assumed structure, edit com.predic8.membrane.core.interceptor.statistics.util.JDBCUtil and rebuild the application.