Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
nageshcaparthy
Product and Topic Expert
Product and Topic Expert
It has been quite some time since we have been Onboarding SAP BTP Customers, in case you are new to BTP, you can reach us via SAP BTP Onboarding Resource Center.  The primary topic we discuss in onboarding calls is best practices around Account Modeling and Governance, which are achieved using Directories and Subaccounts in SAP BTP. By design, there are many ways to achieve this, and no one size fits all. Naturally, as part of these conversations, we are frequently asked, how can customers measure/monitor the consumption of these services separately? On the global account level of SAP BTP, customers are provided a Usage Analytics tab which displays all the details of each of the services by Service Usage, Directory/Subaccount Usage, or by Global Account Overview with respective roles to view this data.

We’re seeing an increase in customers adding Directories to their account model as it helps in better governance and control. Let us take a small example, as a customer if you own one SAP BTP Global Account for your worldwide operations, you could split your account setup into regions like EMEA, Americas, APAC, etc. Setting it up this way will provide you the option to have different budgeting for each region or directory that you create.


Image 1


In the above example labels were used to capture the details of the specific Cost Center for each region along with individual subaccount administrators responsible for the services which are activated. While such a setup is the best practice, it also limits the view of the usage of these services based on the roles you assign (Global Admin, Directory Admin, Sub-Account Admin, Viewer Roles, etc…). To provide more flexibility in monitoring capabilities we recommend using the free SAP BTP Services – Usage Data Management Service (aka Resource Consumption APIs). The service provides the following REST APIs that can help to generate BTP Services usage reports:

  • Cloud Credit Details - Get cloud credit data history for a global account

  • Monthly Directory Usage - Get monthly usage reporting data for a directory and a specified time

  • Monthly Subaccounts Cost - Get monthly cost reporting data for all subaccounts and a specified time. Applies to global accounts that use the Cloud Platform Enterprise Agreement (CPEA) consumption-based commercial model

  • Monthly Usage - Get monthly usage reporting data for a global account and a specified time

  • Subaccount Usage - Get usage reporting data for a subaccount and a specified time


Note: All of the above APIs are supported for Consumption-based licenses and Cloud Management Tools - Feature Set B only. Please check SAP API Hub - Resource Consumption – API Reference for more details on each API and you can refer to the help guide.

In this blog, I will focus on how to use the Usage Data Management Services (aka Resource Consumption APIs) mainly on Monthly Usage API and Monthly Directory Usage API using a postman client and converting the data to excel (or developing an application for internal reporting based on customer requirements).

Pre-requisite:

  • Assign the entitlement Usage Data Management Service to your Subaccount

  • Cloud Foundry is enabled and a Space is created

  • To use the Monthly Usage API you need the Global Account Administrator to generate the global report and the Subaccount Administration role to activate the service

  • The Monthly Directory Usage API works with a setup of Directory and Subaccounts as shown in Image 1 and you need to have a Directory Setup with Users Management Enabled if not enabled go to the directory you want to generate the report for, click on Users -> click on Enable Entitlement and User Management



Image 2


Note: You need to be the Directory Administrator to activate it and without enabling entitlement and User Management, you will not be able to create the reporting-directory Instance.

  1. Monthly Usage API setup


First, let us start with the Monthly Usage API. To use this API let us first assign the entitlement Usage Data Management Service to the sub-account.


a. Log in to your SAP BTP Global Account, click on Entitlements, and select your Sub-Account (Image 3 shows that the subaccount is already a part of the Directory – BTP Onboarding Directory this helps me to demonstrate Directory Usage also)



Image 3


b. Click on Configure Entitlement, click on Add Service Plans, search for Usage Data Management and select it, on the right side of the screen select both service plans reporting-ga-admin and reporting-directory, and add the service plans and save the settings.



Image 4


c. Now navigate to your sub-account, click on Service Marketplace, search for Usage Data Management, click on Create, and select the service plan as reporting-ga-admin, I have opted for Cloud Foundry runtime with Space as usage, instance name for CLI usage as shown in image 5 below, click on Next and save the details(no JSON required).



Image 5


d. Select the newly created Instance usagecli (with the help of the right arrow towards the end of the row), click on Service Keys and then click on Create, enter a name for the Service Key Name (example: UsageKey), and click on create. A new service key should be generated as shown below.



Image 6


Click on the 3 dots to view the value of the Service Key. We will be using the following details, so please download it or make a note of the following values as shown in image 6.






    • Clientid

    • Clientsecret

    • URL

    • target_url





Image 7


The above details help us to consume the Monthly Usage API. Now, before we go to the postman client, let's proceed with the configurations for Directory Usage API.


2. Directory Usage API Setup

Before we begin, please ensure that you have met the pre-requisites as shown in Image 2 and Image 3. If you have the above requirement set, you are ready to create the instance.

a. Navigate to your subaccount, click on Service Marketplace, search for Usage Data Management service, click on create, and select the plan reporting-directory, I have selected runtime environment as cloud foundry and space which were previously used, and enter the CLI instance name as shown below and click on Next.



Image 8


b. Here, you need to enter the JSON with the Directory ID value which can be found in the General tab in your Directory view.



Image 9


Syntax: {"directoryGuid": "DirectoryGUID value"}


Enter the JSON value as shown below, click on Next and click on create. (If the values are incorrect it may fail to create an instance)



Image 10


c. Similar to previous steps, now click on the right arrow, select Service Keys, click on Create, enter a value in the Service Key Name (example – directorykey) and click on Create. Once the values are created, download the file as we would need the values of the following






    • Clientid

    • Clientsecret

    • url

    • target_url




The above steps help us to expose the Directory Usage APIs.


3. Generating the Usage Reports using Postman client

The approach of using the postman client is the same for all the Resource Consumption APIs with respective data values. I will demonstrate the Monthly Usage API.

a. Open Postman client, select GET Request, and enter the URL from the Service Key file which was downloaded from the reporting-ga-admin instance and suffix the value


/oauth/token?grant_type=client_credentials


b. Click on Authorization, select Basic Auth, here you should enter the User Name and Password. Please copy the values from the Service Key file, clientid will be your User Name, and clientsecret will be your password. Enter these values and click on Send as shown in image 11.



Image 11


c. Now copy the access_token value which is the bearer value for our next API call. Now change the Authorization type to Bearer Token and enter the access_token value which we copied.


d. Change the GET request URL, this should be the target_url value from the service key file, and append the URL request from the Resource Consumption APIs to fetch the monthlyUsage In my case




URL Value:


https://uas-reporting.cfapps.eu10.hana.ondemand.com/reports/v1/monthlyUsage?fromDate=202201&toDate=202206



Image 12


You may use this approach to consume the report in an application of your choice or you may simply convert this JSON into a CSV/Excel file to understand the data.


The same configuration should work for






    • /reports/v1/cloudCreditsUsage

    • /reports/v1/monthlySubaccountsCost

    • /reports/v1/monthlyUsage (demonstrated in this blog)

    • /reports/v1/subaccountUsage




If you want to use the Directory Usage API (/reports/v1/monthlyDirectoryUsage), please use the service key values from the Directory Instance which was created in step 2. Change the values of clientid, and client password, generate a new bearer key, and follow the same process as described above.


I have attached a small screenshot of the CSV file generated from the JSON data which was generated above.



Image 13


Hope this blog helps to monitor your usage.

Cheers,

BTP Onboarding Team
7 Comments