Logging Service Invocation Metadata to Database
Using the StatisticsJDBCInterceptor, Membrane API Gateway 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 RFC 2616
- 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
<spring:beans xmlns="http://membrane-soa.org/proxies/1/" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd"> <spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> [...] </spring:bean> <router> <serviceProxy name="predic8.com" port="2000"> <statisticsJDBC dataSource="dataSource" /> <target host="membrane-soa.org" port="80" /> </serviceProxy> </router> </spring:beans>
The configuration of the dataSource spring bean still has to be filled in.
Data Sources
If you are using MySQL:
Replace the spring:bean definition of the bean with the ID dataSource by:<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <spring:property name="driverClassName" value="com.mysql.jdbc.Driver" /> <spring:property name="url" value="jdbc:mysql://localhost:3306/membrane" /> <spring:property name="username" value="root" /> <spring:property name="password" value="root" /> </spring:bean>
If you are using Oracle:
Replace the spring:bean definition of the bean with the ID dataSource by:<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <spring:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <spring:property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:your-database" /> <spring:property name="username" value="your-username" /> <spring:property name="password" value="your-password" /> </spring: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:
Replace the spring:bean definition of the bean with the ID dataSource by:<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <spring:property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" /> <spring:property name="url" value="jdbc:derby://localhost:1527/membranedb-test;create=true" /> <spring:property name="username" value="APP" /> <spring:property name="password" value="root" /> </spring: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 );
For more information, read the reference page of the statisticsJDBC element