Monitoring and Statistics
In this chapter we explain how to set up WSO2 Business Activity Monitor (BAM) to render API statistics. Follow the instructions below to set up BAM to be used with the WSO2 API Manager. Throughout this chapter, <AM_HOME> refers to the API Manager installation directory whereas, <BAM_HOME> refers to the Busienss Activity Monitor installation directory.
1. Download WSO2 BAM 2.0 from location: http://wso2.com/products/business-activity-monitor.
Note
For WSO2 API Manager 1.0.0 version, WSO2 BAM 2.0.0 is required.
2. Open the file api-manager.xml at location <AM_HOME>/repository/conf folder.
3. Enable its API tracking option by setting the "APIUsageTracking" element to true as follows:
<APIUsageTracking> <!-- Enable/Disable the API usage tracker. --> <Enabled>true</Enabled> <PublisherClass>org.wso2.carbon.apimgt.usage.publisher.APIMgtUsageDataBridgeDataPublisher</PublisherClass> <ThriftPort>7612</ThriftPort> <BAMServerURL>tcp://localhost:7612/</BAMServerURL> <BAMUsername>admin</BAMUsername> <BAMPassword>admin</BAMPassword> <DataSourceName>jdbc/WSO2AM_STATS_DB</DataSourceName> </APIUsageTracking>
4. Restart the API Manager.
5. Next, configure a database to which BAM can write analyzed information. This information is retrieved by the API Publisher before displaying on the corresponding statistical dashboards. Thrift protocol is used to publish data from the API Manager to BAM.
6. Open the file master-datasources.xml at location <AM_HOME>/repository/conf/datasources folder.
7. The <Name>jdbc/WSO2AM_STATS_DB</Name> XML node defines the datasource used to fetch analytical data. By default, it appears as follows in the master-datasources.xml file.
<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:h2:<!-- Full path to JDBC database -->;AUTO_SERVER=TRUE</url> <username>wso2carbon</username> <password>wso2carbon</password> <driverClassName>org.h2.Driver</driverClassName> <maxActive>50</maxActive> <maxWait>60000</maxWait> <testOnBorrow>true</testOnBorrow> <validationQuery>SELECT 1</validationQuery> <validationInterval>30000</validationInterval> </configuration> </definition> </datasource>
Edit it to point to <BAM_HOME>/repository/databases/APIMGT_STATS_DB database, which is where the default analytics scripts write by default.
Note
<DataSourceName> of <APIUsageTracking> entry in <AM_HOME>/repository/conf/api-manager.xml should be same as the JNDI config name in <AM_HOME>/repository/conf/datasources/master-datasources.xml.
 Next, prepare BAM to create statistics from the API manager.
8. Copy the file <AM_HOME>/statistics/API_Manager_Analytics.tbox to directory, <BAM_HOME>/repository/deployment/server/bam-toolbox. If this folder is not in the BAM installation folder by default, create it before copying the file. The toolbox file describes the information collected, how to analyze the data, as well as the location of the database where the analyzed data is stored.
9. Change port offset for the BAM product to 1 by editing the file <BAM_HOME>/repository/conf/carbon.xml file (search for the offset node). This increments all ports used by the servers by 1, which means the BAM server will now run on port 9444 - the port that the API manager uses by default.
10. Start WSO2 BAM server from <BAM_HOME>/bin/wso2server.[sh/bat].
If you want to host the BAM server on a different machine or change the running port, you must edit file api-manager.xml located at <AM_HOME>/repository/conf folder. Edit the APIUsageTracking block as follows:
<!--API usage tracker configuration used by the BAM data publisher in API gateway.--> <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 server used to collect statistics. Must be specified in protocol://hostname:port/ format.--> <BAMServerURL>https://localhost:9444/</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>
Once the WSO2 BAM is configured to render and produce statistics of APIs hosted and managed in the API Manager, you can view them through various statistical dashboards in the API Publisher, depending on the permission levels of the login. For information, refer to section Viewing API Statistics.
Â
Â