Here I'm going to explain about
how to configure WSO2BAM (Download here)to
collect, analyze and display the statistics from WSO2 API Manager. (Download
here)
Configuring WSO2 API Manager
Step 1: Configure the <APIUsageTracking> in the <APIM_home>/repository/ conf/api-manager.xml
as follows;
<APIUsageTracking>
<!-- Enable/Disable the API usage
tracker. -->
<Enabled>true</Enabled>
<!-- API Usage Data Publisher.
--> <PublisherClass>org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageDataBridgeDataPublisher</PublisherClass>
<!-- Thrift port of the remote BAM
server. ->
<ThriftPort>7612</ThriftPort>
<!-- Server URL of the remote
BAM/CEP server used to collect statistics. Must
be specified in
protocol://hostname:port/ format.
-->
<BAMServerURL>tcp://192.168.1.3:7612,tcp://192.168.1.3:7613</BAMServerURL>
<!-- Administrator username to
login to the remote BAM server. -->
<BAMUsername>admin</BAMUsername>
<!-- Administrator password to login
to the remote BAM server. -->
<BAMPassword>admin</BAMPassword>
<!-- JNDI name of the data source
to be used for getting BAM statistics.This data source should be defined in the
master-datasources.xml file in conf/datasources directory. -->
<DataSourceName>jdbc/WSO2AM_STATS_DB</DataSourceName>
</APIUsageTracking>
Make sure to mention both of BAM server URL's
in <BAMServerURL> separated by a (,). Also give JNDI name of the data
source to be used for getting BAM statistics in later part of the config
<DataSourceName> as mention above.
Step
2: Configure the data source
definition in master-datasources.xml. Here I have point the db to a MySql
database.
<datasource>
<name>WSO2AM_STATS_DB</name>
<description>The datasource used
for getting statistics to API Manager</description>
<jndiConfig>
<name>jdbc/WSO2AM_STATS_DB</name>
</jndiConfig>
<definition
type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/BAMDB</url>
<username>root</username>
<password>root</password>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT
1</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
Configuring WSO2BAM
Step
1: If you’re running a
multiple WSO2 products in same host, change the port offset of BAM, carbon.xml
in <BAM_home>/repository/conf/carbon.xml
<!-- Ports offset. This entry will
set the value of the ports defined below to the define value + Offset. e.g.
Offset=2 and HTTPS port=9443 will set the effective HTTPS port to 9445 -->
<Offset>1</Offset>
Step
2: Copy the file
<APIM_HOME>/statistics/API_Manager_Analytics.tbox
to
directory, <BAM_HOME>/repository/deployment/server/bam-toolbox
.
If you use Oracle DB to store statistical data, copyAPI_Manager_Analytics_Oracle.tbox
instead.
Step 3: Configure the data source definition in
master-datasources.xml.
<datasource>
<name>WSO2AM_STATS_DB</name>
<description>The datasource used
for getting statistics to API Manager </description>
<jndiConfig>
<name>jdbc/WSO2AM_STATS_DB</name>
</jndiConfig>
<definition
type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/BAMDB</url>
<username>root</username>
<password>root</password>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT
1</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
If you have change the default BAM port as
mentioned in the step 1, you must have to change the Cassandra port accordingly
in the JDBC connection url as well.
<datasource>
<name>WSO2BAM_CASSANDRA_DATASOURCE</name>
<description>The datasource used
for Cassandra data</description>
<definition
type="RDBMS">
<configuration>
<url>jdbc:cassandra://localhost:9161/EVENT_KS</url>
<username>admin</username>
<password>admin</password>
</configuration>
</definition>
</datasource>
For load balanced data publishing, follow the
same steps mention in the Configuring WSO2BAM section and specify the correct
URL in the <BAMServerURL> section in the
<APIM_home>/repository/conf/api-manager.xml.
Restart WSO2BAM server by running
<BAM_HOME>/bin/wso2server.[sh/bat]
.
And then the APIM server by running
<APIM_home>/bin/wso2server.[sh/bat]
.
Fail Over
testing
Once the APIM
busy, serving requests, check the statistics mentioned in the APIM publisher.
Then stop one BAM server instance and once the JVM stops, check whether the statistics
still updating fine in the publisher. Since the APIM set up is configured to
serve load balanced data publishing, statistics should be update correctly even
from one BAM node. (refer this article to setup a BAM cluster setup.)