Publish custom data from API Manager to WSO2 Business Activity Monitor

WSO2 API Manager provides out of the box integration with WSO2 Business Activity Monitor (WSO2 BAM), this integration would allow API Manager to publish a pre-defined event stream which would be stored, processed and summarized by WSO2 BAM to provide a meaningful set of information in the API Manager dashboard. A case may arise when an organization wants to publish custom data to the WSO2 BAM. For example a user may want to publish some values which are passed in the response message header to WSO2 BAM. In such a case the existing data Publisher needs to be customized to accommodate this custom value. API Manager’s extension mechanism allows you to write your own class to do this. In order to do this you can extend the ‘APIMgtUsageDataPublisher’ class and write your own data publisher. Given below is a custom data publisher written to pass a custom value to the WSO2 BAM. Please note that this is similar to the existing data publisher class with the difference of it using a custom DTO to publish response data.

This custom data publisher refers to a ‘CustomDataBridgeResponsePublisherDTO’ to publish data to WSO2 BAM. Given below is the custom DataBridgeResponsePublisherDTO.

As you could see here, we have add a ‘customValue’ field to the original datastream , and when creating the payload the custom value is included in the payload. In this example we are passing a string as the custom value, this logic can be replaced to pass any other value to WSO2 BAM.

 

Once you have done this changes build the source and add the jar file to the following folder.

<API_Manager_Home>\repository\components\lib

 

Java project file is attached for you to customize the values as required and build (through Maven).

Once this is done lets add the datapublisher class to APIManager.xml file. Lets modify the file to reflect the details of our custom data publisher. Given below is a sample snippet of the file. Notice that the custom data publisher is included as the ‘PublisherClass’ and the version of the response stream has been changed to’1.1.0′.

Now lets look at the changes needed to be done to WSO2 BAM, we need configure WSO2 BAM to expect this new data stream. You can do this by configuring the API Manage toolbox to include this value. The toolbox can be found in the following location.

<API_Manager_Home>\wso2am-1.9.1\statistics

The toolbox is a compressed file (.tbox format) that can be uncompressed, amended and re-compressed backed to a ‘.tbox’ file. I have attached a modified ‘.tbox’ file with this blog. This toolbox is configured to accept the field ‘customValue’ received in the response data stream.

Once you have a modified toolbox you enable statistics from the ‘admin-dashboard’ of API Manager which will automatically install this new toolbox to WSO2 BAM. Please make sure that you have uninstalled any existing API Manager toolbox before doing this.

 

You have now configured to publish a custom data value from WSO2 API Manager to WSO2 BAM

 

Git Project for the this example is given below. Toolbox is also available within this project.

https://github.com/nadeesha5814/Custom_Analytics

Advertisements

Integrating WSO2 API Manager with a 3rd Party Billing tool

How can we integrate 3rd party billing to the WSO2 API Manager?

WSO2 API Manager with the integration of WSO2 Business Activity Monitor (WSO2 BAM) provides out of the box capability to generate API statistics. However some organisation would require the API Manager to be used with their own (3rd party) billing systems. There are few ways that this can be done. These methods are illustrated in the diagram below
3rd party
1. The API Manager already collects all API related data when an API invocation is made by a service consumer. The API Manager can publish them to WSO2 BAM, which the WSO2 BAM uses to generate information required for API statistics. The same process can be utilized by a 3rd party tool to access API information from the API Manager. Once the data is published to the WSO2 BAM, WSO2 BAM would stores the data in a Cassandra data-store and summarize these data periodically based on a set of Apache Hive queries. The summarized information can then be inserted to a RDBMS which can be accessed by the 3rd party billing tool.
2. API Manager can publish to any thrift data endpoint which can be utilized by the 3rd party billing system to recieve data from WSO2 API Manager. This would provide direct integration with the 3rd party billing system.
3. API Manager uses a thrift data publisher to publish data to a billing system, it is possible to write an extension in the WSO2 API Manager to provide the capability to publish data in a different protocol to a 3rd party billing tool. This extends the capability of API Manager to work with any billing system that can recieve data using standard web API’s.
The WSO2 API Manager is shipped with a standard set of Hive queries(As part of the BAM toolbox) to summarize API data. It is possible to modify or write your own Hive queries to summarize the API information based on your own KPI’s to fit the needs of the 3rd party billing system. The billing system can directly access the RDBMS and use it as a data source to generate billing information.

Managing the WSO2 API Manager via JMX in 3 easy steps

WSO2 API Manager provides multiple ways in measuring the performance of its server runtime. The server performance can be measured by the management console of the API Manager. Alternative to this the server runtime performance can also be monitored remotely through a JMX client such as JConsole.

Given below are the steps required to configure the performance monitoring of the API Manager via JMX.

  1. On the API Manager Server startup you would find the JMX server URL as below.
JMX Service URL  : service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi

This URL allows the JMX endpoint of the WSO2 API Manager to be accessed remotely.

  1. Start JConsole, JConsole can be found in JDK_HOME/bin folder. JConsole can be started by typing jconsole in the Shell/Command prompt.

JMX

  1. In the JConsole ‘New Connection’ page enter the above JMX service URL of the API Manager along with the admin username and the password as shown below. Once this is done click on the connect button.

Now you would be able to see statistics relating to the WSO2 API Manager Server runtime in the JConsole.