Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Enable API tracking option by setting the <APIUsageTracking> element to true in <APIM_HOME>/repository/conf/api-manager.xml. Also specify the data source used for getting BAM statistics in <DataSourceName> element. For example,

    Code Block
    languagehtml/xml
    <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>
        <!-- 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>
    Note

    Note: In the above configuration, the default Thrift port is increased by 1 because we apply an offset of 1 to default BAM port later in this guide.

    Info

    <BAMServerURL> refers to the endpoint to which events will be published from the API Gateway. This endpoint is also known as the event receiver. You can define multiple event receiver groups, each with one or more receivers. A receiver group is defined within curly braces and receiver URLs are delimited by commas.

    For example, <BAMServerURL>{tcp://localhost:7612/,tcp://localhost:7613/},{tcp://localhost:7712/,tcp://localhost:7713/}</BAMServerURL>. The example has two receiver groups defined with two receivers in each group. When a request passes through the API Gateway, an event will be published to one selected receiver in each group.

  2. Specify the data source definition in <APIM_HOME>/repository/conf/datasources/master-datasources.xml file as follows.  WSO2AM_STATS_DB is the datasource used to fetch analytical data. Note that the JNDI config names must match the ones defined earlier in BAM.

    Code Block
    languagehtml/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>
                     <!-- 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>
    Note

    In the above configuration,

    • Replace <BAM_HOME> with the absolute path of BAM installation directory.
    • The JNDI config name must match with configurations of api-manager.xml file defined later in this guide.


    Next, prepare BAM to collect and analyze statistics from API manager.

...