Please Note - Statistics publishing using REST Client was deprecated from APIM 2.0.0. Please refer this to continue.
In this blog post I will explain how to configure WSO2 API Manager Analytics 2.0.0 with WSO2 API Manager 2.0 to publish and view statistics. Before going further into the topic, I thought to give a brief summary about the role of WSO2 API Manager Analytics 2.0.0 in here
In this blog post I will explain how to configure WSO2 API Manager Analytics 2.0.0 with WSO2 API Manager 2.0 to publish and view statistics. Before going further into the topic, I thought to give a brief summary about the role of WSO2 API Manager Analytics 2.0.0 in here
WSO2
API manager embedded with the ability to view statistics of the
operations carried out such as usage comparison, monitoring Throttled
Out Requests, API last access time and so on. To view so, the user
has to configure an analytics server with API Manager and it allows
to view statistics based on the given criteria. Until WSO2 API Manager 2.0.0, the
recommended analytics server to view statistics was WSO2 DAS ( Data
Analytics Server ) which is a high performing enterprise data
analytics platform. Before that WSO2 BAM (Business Activity Monitor) used to collect and analyze runtime statistics from the API Manager. Based on the WSO2 DAS, with the vision of having a
separate but custom analytics package including new features that
will perform all the analytics for API Manager, WSO2 API Manager
Analytics has been introduced. WSO2 API Manager analytics fuses
batch and real-time analytics with predictive analytics and generate
alerts when an abnormal situation occurs via machine learning.
Hope
now you have a sound knowledge on what API Manager analytics is all
about. So let's starts with configuration.
Steps to configure,
1. First download the WSO2 API Manager Analytics 2.0.0 release pack and unzip it.
(
Download )
2. Start the Analytics server (By default the port offset was given as 1 in carbon.xml)
3. Go to Management Console of Analytics Server and logged in as administrator (Username- admin, Password- admin).
4. Go to Manager -> Carbon Applications. List and delete the existing org.wso2.carbon.analytics.apim carbon app.
5. Browse Rest Client car app (org_wso2_carbon_analytics_apim_REST-1.0.0.car) from [APIM_ANALYTICS_HOME]/statistics and upload.
That's it from APIM Analytics side. Now see how to configure API Manager to finalize the configurations.
2. Start the Analytics server (By default the port offset was given as 1 in carbon.xml)
3. Go to Management Console of Analytics Server and logged in as administrator (Username- admin, Password- admin).
4. Go to Manager -> Carbon Applications. List and delete the existing org.wso2.carbon.analytics.apim carbon app.
5. Browse Rest Client car app (org_wso2_carbon_analytics_apim_REST-1.0.0.car) from [APIM_ANALYTICS_HOME]/statistics and upload.
That's it from APIM Analytics side. Now see how to configure API Manager to finalize the configurations.
6. Download
the WSO2
API Manager 2.0.0 pack and unzip it ( Download )
7. Open
api-manager.xml ([APIM_HOME]/repository/conf/api-manager.xml
) and enables the Analytics. The configuration should be look like
this. ( by default the values set as false )
<Analytics> <!-- Enable Analytics for API Manager --> <Enabled>true</Enabled>
8. Then
configure Server URL of the analytics server used to collect
statistics. The define format is ' protocol://hostname:port/'.
Although admin credentials to login to the remote DAS server has to
be configured like below.
<DASServerURL>{tcp://localhost:7612}</DASServerURL> <DASUsername>admin</DASUsername> <DASPassword>admin</DASPassword>
Assuming
Analytics server in the same machine as the API Manager 2.0, the
hostname I used here is 'localhost'. Change according to the hostname
of remote location if the Analtics server run on different instance.
By default the server port is adjusted with offset '1'. If the
Analytics server has a different port offset ( check
[APIM_ANALYTICS_HOME]/repository/conf/carbon.xml
for the offset ), change the port in <DASServerURL>
accordingly. As an example if the Analytics server has the port
offset of 3, <DASServerURL> should be {tcp://localhost:7614}.
Now
we have to choose between 2 clients to fetch and publish statistics.
- The RDBMS client which fetches data from RDBMS and publish.
- The REST client which directly fetches data from Analytics server.
I
chose REST client to publish data in this tutorial and will explain
how to configure the data fetching using RDBMS in next blog post.
For
your information, API Manager 2.0 enables RDBMS configuration
to proceed with statistics, by default.
9. To
enable publishing using REST Client, <StatsProviderImpl> should
be uncommented (By default, it's in as a comment) and comment <StatsProviderImpl> for RDBMS
<!-- For APIM implemented Statistic client for DAS REST API --> <StatsProviderImpl>org.wso2.carbon.apimgt.usage.client.impl.APIUsageStatisticsRestClientImpl</StatsProviderImpl> <!-- For APIM implemented Statistic client for RDBMS --> <!--StatsProviderImpl>org.wso2.carbon.apimgt.usage.client.impl.APIUsageStatisticsRdbmsClientImpl</StatsProviderImpl-->
10. Then
the REST API url should be configured with hostname and port along
with the credentials to access,
<DASRestApiURL>https://localhost:9444</DASRestApiURL> <DASRestApiUsername>admin</DASRestApiUsername> <DASRestApiPassword>admin</DASRestApiPassword>
As
mentioned before, the port associate with the default offset of 1 for
WSO2 APIM analytics 1.0.0.
11. Now
Save api-manager.xml and start the API Manager 2.0 server.
That's
it. Open
publisher in a browser ( https://<ip-address>:<port>/publisher). Go
to Statistics and select API Usage as an example. The screen
should looks like this with a message of 'Data Publishing Enabled.
Generate some traffic to see statistics.'
Just
create few APIs and try to invoke them in order to get some traffic to generate statistics on graph. So you can see the statistics like this.