In this episode of our WSO2 tutorial: The open source API management tool of WSO2, the WSO2 API Manager, has the possibility to show API statistics but has always needed another WSO2 product to show statistics on the API usage. Previous versions used the WSO2 Business Activity Monitor for this, current versions use the WSO2 Data Analytics Server (DAS).
The data from the API Manager (gathered at the API gateway) is sent / retrieved via the thrift protocol (TCP).
Connecting WSO2 API Manager and DAS
Where previous versions of the WSO2 API manager, the 100% open source api management tool, required some simple integration work (i.e. uploading a TBOX or cApp file), the most recent version of the API Manager and WSO2 DAS does almost all of the work for you.
Just download and install both products, and start the admin dashboard on the API Manager. In this article we install both on the same machine (localhost) with a port offset of 1 for DAS (in order to make sure that the products do not conflict).
The only thing you need to enter the event receiver (the URL for the thrift protocol) and the URL for the Data Receiver Group. As soon as you save the configuration, the necessary files are installed (.CAR file). No manual uploads necessary, everything is done in the background.
This is a good thing, in a way since it makes life easier, but on the other hand, does hide the way the connection is made. We will discuss in a bit more detail what is going on behind the scenes.
Both BAM and DAS are products that are not only used for integration with API Manager. They are data analytics tools that allow large datasets to be aggregated, analysed and the outcome displayed on for instance a dashboard. These three elements (aggregation, analysis and display) are also found in the cApps that are installed in the background when you connect DAS with API Manager (the TBOX is the same concept that was used by the WSO2 Business Activity Monitor).
In the .CAR file you will find all definition needed to gather the data for the analytics: Eventstream definitions, Eventreceiver definitions and Eventstore definitions. If you are interested on how this works, check out the content of the .CAR file.
Two modes of operation
There are actually two modes of operation when integrating DAS and API manager, the first one is the one described above, the data is directly taken from the summary table (see also the image below). The second method is the mode that was common before the current releases, you would create a database to store the API invocation data (e.g. a MySQL database) and retrieve the data from there. As you can see, all data is sent to the Stream Data Table and from there, depending on the mode of operation either sent to the Summary table and from there directly to the API Rest Client and the Dashboard or to an external RDBMS and from there to the RDBMS client and the Dashboard.
IF you want information on how to enable the RDBMS option, please check the https://docs.wso2.com/display/AM1100/Publishing+API+Runtime+Statistics+Using+RDBMS documentation online.
The script to run the summary data, runs every 5 minutes, this is governed by a Cron expression found in the
APIM_STAT_SCRIPT .xml in the directory
APIM_STAT_SCRIPT in the API_Manager_Analytics_REST.car.
<CronExpression>0 0/5 * 1/1 * ? *</CronExpression>
This expression indicates that the script needs to be run every 5 minutes. If you want your results faster, change the value of the second parameter (0/5) to for instance (0/2). In that case the script will run every two minutes.
Running API Manager and DAS on Windows
The combination of API Manager and DAS might give problems with the current version of the WSO2 products. Reason is that there is a missing JAR file (snappy-java-220.127.116.11) that should be included in order to make it work. In order to solve this, please take the following steps:
- download the jar file from (for example) http://mvnrepository.com/artifact/org.xerial.snappy/snappy-java/18.104.22.168
- drop the file in
- Edit the repositoryconfanalyticssparkexternal-spark-classpath.conf to include a link to the jar
After you have done this, you can start both DAS and the API Manager and enable the analytics.
|WSO2TORIALS help you to change, update or improve WSO2 products and are based on our experiences with the products. WSO2TORIALS will guide you step by step with minimal knowledge required.|