This sample demonstrates how to setup WSO2 Business Activity Monitor (BAM) to collect and summarize runtime statistics from the WSO2 API Manager and generate bills for API consumers on usage.
- Java Development Kit/JRE version 1.6.* or 1.7.*. Also see Installation Prerequisites.
- Download and install WSO2 BAM using the instructions given in BAM Installation Guide: docs.wso2.org/business-activity-monitor/Getting Started.
Building and running the sample
<BAM_HOME>/repository/conf/carbon.xmlfile where <BAM_HOME> is the BAM binary distribution folder that was downloaded as a prerequisite above. Change the carbon.xml file's port offset to 1. This is done to avoid any port conflicts of running two WSO2 Carbon instances in the same machine.
- Copy the
<BAM_HOME>/repository/deployment/server/bam-toolboxfolder. Create the bam-toolbox directory if it already doesn't exist.
The API Manager Analytic Toolbox : A toolbox is an installable archive, with a .tbox extension. It contains necessary artifacts that models a complete usecase, from collecting data, analyzing through defined Hive scripts to summarizing data through gadgets, Jaggery scripts and other dashboard components.
Connect the datasource to the database where the analytical data is stored using the
<BAM_HOME>/repository/conf/datasources/master-datasources.xmlfile as follows. In the example,
WSO2AM_STATS_DBis the datasource used to fetch the analytical data stored in an H2 database. If you want to use a different database, see Changing the statistics database.
Because you changed the default BAM port in step 2 above, you must change the Cassandra port given in JDBC connection url in the following datasource configuration found in master-datasources.xml file. Since the port offset is 1, the Cassandra port must be 9161.
For a list of default ports used by WSO2 products, see Default Ports of WSO2 Products.
If you run the Hive scripts before changing the default Cassandra port according to the BAM port offset, you keep getting an exception. To overcome this, add the following line at the beginning of the Hive script and rerun.drop table <hive_cassandra_table_name>;
Start WSO2 BAM server by running wso2server.bat (on Windows) and wso2server.sh (on Linux).
Configuring API Manager
To enable API statistics collection, configure the following properties in
<APIM_HOME>/repository/conf/api-manager.xmlfile. Ensure that
<DataSourceName>name is the same as JNDI config name in master-datasources.xml file in BAM.
Configure the data source definition in
Note: Replace <BAM_HOME> in the configuration below with the path to the actual BAM distribution location and the JNDI names must match the ones defined earlier in API Manager.
Viewing billing information
Once the above configurations are done, log in to API Store Web application (
//<YourHostName>:9443/store). You will see the menu items required for API Monetization in the menu bar at the top of the page.