Use Python to get Admin/Tenants usage from Azure Stack Development Toolkit environment


Recently, I’ve been working on the Azure Stack Development Toolkit API to basically figure out how to retrieve the usage data from Azure Stack.

The useful link always need to check is the Azure Stack official documentation.
https://docs.microsoft.com/en-us/azure/azure-stack/

OK. Let’s get started.

First thing first, we need to do the preparation, to make sure we got what we need.

  • client_id
  • client_secret
  • username
  • password
  • app_id_uri
  • directory_id
  • admin_arm_url
For the explanation, visit the following link. 
Follow the instructions to create a document called “_PRIVATEwithPass.txt” under asdk_usage directory.
So basically the processes are use the parameters to make a POST request to get a bearer token from Microsoft. And then use the token to request the usage data.
You can use the administrator management API to list all the subscriber IDs and make a usage request for one of the tenants. There are four resource providers that available at the moment.

  • Network
  • Storage
  • Compute
  • Key Value
And each provider contains different meters. By saying that, you should notice the returned usage data always labeled by meter id. Unfortunately, you have to match the meter id to the meter name.
Here is the article from Microsoft list all the available meters for Azure Stack.

For the full version of code.