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:
- HTTP status code
- Request time
- The rule that processed the request
- HTTP method used
- Request path as specified by rfc2616
- Client (see rule key)
- Server, the request target
- Content-Type header of the request
- Content-Length headers of the request
- Content-Type header of the response
- Content-Length headers of the response
- Request/response cycle duration
<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.
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> -->
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> -->
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> -->
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 );