Building charts for Adapter analytics using IBM Cloud Mobile Analytics service and IBM Mobile Foundation Service


IBM Mobile Foundation Service can be configured to connect to IBM® Mobile Analytics for IBM Cloud service to pump the analytics events and logs. Currently the Mobile Analytics service doesn’t support out-of-the-box Mobile Foundation Service specific features like custom charts and adapter analytics. However, there is an approach where you can exploit the ’Db2 Warehouse export’ option of the Mobile Analytics service and achieve the building and viewing of Custom charts or analytics for Mobile Foundation Adapters.

This blog details this approach of building adapter analytics using Mobile Analytics service and Mobile Foundation leveraging the Db2 Warehouse on Cloud service capabilities for charting. You can use the Mobile Foundation server installed on your on-premises environment or quickly configure a Foundation server on IBM Cloud using the IBM Mobile Foundation service. We will use the Mobile Foundation service on IBM Cloud in this blog.


Log in to IBM Cloud and create a Mobile Foundation service.

Create BMS Analytics service in IBM Bluemix and configure Mobile Foundation service instance with it.

See Details

Exporting analytics data from Mobile Analytics service to ‘Db2 Warehouse on Cloud’ service.

  • Launch Console from Mobile foundation service and open Analytics service console from there.
  • On the left side click on Db2 Warehouse under Export.
  • This enables the analytics data export to Db2 Warehouse.
  • Follow the steps as listed there and click on Create Db2 Warehouse. This takes you to the Bluemix Db2 Warehouse service creation page; choose the IBM Db2 Warehouse on Cloud Entry plan and create the instance.

    Db2 Warehouse Export page

  • Go to Service Credentials tab and click on New credential. Click on Add to create a new credential for Db2 Warehouse.
  • Under Actions, click on View credentials and copy the credential details to clipboard (use the copy to clipboard button on the right.)
  • Go back to Mobile Analytics console, select Db2 Warehouse under Export and go to the second step in “Set Up Export” page. Here paste the Db2 Warehouse credentials that you had copied earlier into the clipboard and click on Submit.
  • On submission, the view displays the export enabled page which details the DB schema and tables that would be created in Db2 Warehouse.

    Db2 Warehouse Export schema

  • Add some adapter calls in a mobile app using the Mobile First SDK. A sample code snippet for the same from android is given below.

    private void callAdapter(){
          URI adapterPath = null;
          try {
              adapterPath = new URI("/adapters/javaAdapter/resource/unprotected");
          } catch (URISyntaxException e) {
          WLResourceRequest request = new WLResourceRequest(adapterPath, WLResourceRequest.GET);
          request.send(new WLResponseListener() {
              public void onSuccess(WLResponse wlResponse) {
                  // Will print "Hello world" in LogCat.
                  Log.i("MobileFirst Quick Start", "Success: " + wlResponse.getResponseText());
              public void onFailure(WLFailResponse wlFailResponse) {
                  Log.i("MobileFirst Quick Start", "Failure: " + wlFailResponse.getErrorMsg());
  • Register the app to connect to the Mobile foundation service and trigger the custom events from mobile application. Check the analytics screens in the Mobile Analytics console. See the custom data sent under Troubleshooting > App Log Search.
  • Now from Bluemix Dashboard, select the Db2 Warehouse on Cloud service which will open its service console. On the console, click on Open. This opens the Db2 Warehouse with the DB schema that has been created for Mobile Analytics.
  • Click on Explore on the top of the page. The DB schema name can be found from the Db2 Warehouse credentials which is used for Mobile Analytics. Click on the DB schema name. Here all tables should get listed as shown below. Click on a table to see the table description.

    Db2 Warehouse Tables

  • Click of View Data below the table description to see the table contents.

    Db2 Warehouse Table Contents

Creating and running R script to plot adapter analytics charts in Db2 Warehouse on Cloud

Now that we have successfully exported the analytics data to DB2 Warehouse we shall now chart them.

  • Choose NETWORKTRANSACTION table and click on Browse Data tab to see that all the adapter calls sent from Mobile Analytics is available here in columns like ADAPTERNAME, PROCEDURENAME etc.
  • Db2 Warehouse on cloud comes with R studio where the R scripts can be run to create charts.
  • Click on Analyze > Launch R studio. The login credentials for R studio is the <username> and <password> in the service credentials of Db2 Warehouse which was created above.
  • R studio has a mainly four windows. Click on + on the top left and choose R script.
  • Under the Script area add your R script and Save the same as below.

    R script

R Script to plot number of adapter requests

  • R-script below can be used to plot number of adapter requests. Change the Db2 Warehouse schema name with yours.

    ########### R script for displaying MFP number of adapter calls made. ###############
    con <- idaConnect("BLUDB","","")
    dfrm <-table(df[,c(1)])
    barplot(dfrm, main="Bar chart of adapter requests",legend = rownames(dfrm), beside=TRUE,col=rainbow(7))
  • To run the complete script, in the scripting window select all the content and click Run.
  • Once run successfully, it creates the chart image as ‘adapter-requests.jpg’ under Files tab in the bottom right window as shown in the above screenshot.
  • Click on the picture to see the chart.
  • See the Console window for any errors.
  • Further details of R studio usage can be found in R studio Help.

    Adapter Requests

R script to plot the response time of adapter calls

  • R-script below can be used to plot adapter response time. Change the Db2 Warehouse schema name with yours.

    ########### R script for displaying MFP adapter response time ###############
    con <- idaConnect("BLUDB","","")
    ggplot(df, aes(x=TIMESTAMP, y=SERVERPROCESSINGTIME)) +
    geom_point(aes(col=ADAPTERNAME), size=3) +
    labs(title="Adapter Response Time", y="Server Processing Time (ms)", x="Adapter request time")
  • Once run successfully, it creates the chart image as ‘adapter-requests.jpg’ under Files tab in the bottom right window as shown in the above screenshot.

    Adapter Response Time

Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on May 02, 2018