Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Introduction

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 usage of consumers.

Prerequisites

Building and Running the Sample

Configuring BAM

1. Open $BAM_HOME/repository/conf/carbon.xml file 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.

<!-- 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>

2. Copy the 'API_Manager_Analytics.tbox' in $AM_HOME/samples/Billing folder to $BAM_HOME/repository/deployment/server/bam-toolbox folder. Create the bam-toolbox directory if it already doesn't exist.

3. Add the following code segment to $BAM_HOME/repository/conf/datasources/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>
               <!-- JDBC URL to query the database -->
               <url>jdbc:h2:repository/database/APIMGTSTATS_DB;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>

4. Start WSO2 BAM server by running wso2server.bat (on Windows) and wso2server.sh (on Linux).

Configuring API Manager

5. To enable API statistics collection, configure the following properties in $AM_HOME/repository/conf/api-manager.xml file.

<!--
 Enable/Disable the API usage tracker.
 -->
<Enabled>true</Enabled>

<!--
 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>

<!--
 Enable/Disable Usage metering and billing for api usage
-->
<EnableBillingAndUsage>true</EnableBillingAndUsage>

6. Ensure that <DataSourceName> of <APIUsageTracking> element in api-manager.xml file is un-commented and the value is the same as JNDI config name in master-datasources.xml file.

7. Configure the data source definition in $AM_HOME/repository/conf/datasources/master-datasources.xml file.

Note

Replace <BAM_HOME> in the configuration below with the path to the actual BAM distribution location.

<datasource>
     <name>WSO2AM_STATS_DB</name>
     <description>The datasource used for getting statistics to API Manager</description>
     <jndiConfig>
         <!-- This jndi name should be same as the DataSourceName defined in api-manager.xml -->
         <name>jdbc/WSO2AM_STATS_DB</name>
     </jndiConfig>
     <definition type="RDBMS">
         <configuration>
             <!-- JDBC URL to query the database -->
             <url>jdbc:h2:<BAM_HOME>/repository/database/APIMGTSTATS_DB;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>

8. Copy $AM_HOME/samples/Billing/billing-conf.xml file into $AM_HOME/repository/conf folder.

View Billing Information

Once the above configurations are done, log in to API Store Web application (https://<YourHostName>:9443/store). You will see the menu items required for API Monetization are now visible in the Store.

If you are a new user, there will not be any billing information at the beginning.



 

  • No labels