Connect Microsoft Azure
This guide explains how to prepare your Azure environment and establish a connection with Hypermeter.
Hypermeter reads the billed cost and the Azure Monitor utilization of the same resources, and puts them on one row per resource per day. A report can then show rightsizing and waste next to the real spend.
All access is read-only. Hypermeter signs in as one service principal in your Microsoft Entra tenant.
What Hypermeter collects
Two workflows do the work. This guide assumes that both are in your organization. If they are not, contact Exivity support.
| Workflow | Reads | Result |
|---|---|---|
| Metrics | The inventory from Azure Resource Graph, hourly metrics from Azure Monitor, and recommendations from Azure Advisor | The cubes Azure Rightsizing and Azure Disk Waste |
| Cost | The actual cost of a Microsoft Customer Agreement (MCA) billing profile, from the Cost Details API | The cost per day and per service, and the savings that Advisor claims compared with the real spend |
The metrics workflow collects these values:
| Data | Details |
|---|---|
| CPU | The percentage per hour, and a 95th percentile |
| Memory | The percentage in use. Azure reports it without a guest agent |
| Network | GB in and GB out |
| Disks | IOPS per volume, and the allocated size in GB |
| Capacity | The vCPUs and the memory of each virtual machine size |
| Recommendations | The recommendations of Azure Advisor |
For how Hypermeter calculates these values, see How to read the numbers.
Prerequisites
| You need | Details |
|---|---|
| A Microsoft Customer Agreement | The cost workflow reads an MCA billing profile. |
| Permission to register an application in Microsoft Entra ID | The application is the service principal that Hypermeter signs in with. If an application already collects MCA cost for Hypermeter, extend it. Do not create a second one. |
| Permission to assign Azure roles | The Owner or User Access Administrator role on the management group, or on each subscription. |
| Permission to assign billing roles | The owner role on the billing profile or on the billing account. |
| The Azure CLI | To register a resource provider in each subscription. |
| The owner role in Hypermeter | To store the client secret and to schedule the workflows. See Roles and permissions. |
Configure Azure access
1. Create the service principal
- In the Azure portal, open Microsoft Entra ID, then App registrations, and select New registration.
- Enter a name, for example
hypermeter-reader, and select Register. - Copy the Application (client) ID and the Directory (tenant) ID.
- Open Certificates & secrets, and select New client secret. Copy the value now. Azure shows it only once.
2. Assign the read roles
The service principal needs three read roles.
| Role | Scope | Hypermeter uses it for |
|---|---|---|
Reader | The management group, or each subscription | The inventory: virtual machines, scale sets, disks, and virtual machine sizes |
Monitoring Reader | The same scope as Reader | The metrics of Azure Monitor |
| Billing profile reader | The MCA billing profile | The cost reports |
Assign the roles at the management group where you can. A new subscription in the group then gets the roles automatically. You still register the provider in it.
To assign Reader and Monitoring Reader:
- Open the management group or the subscription, and open Access control (IAM).
- Select Add, then Add role assignment.
- Select the role, select the application, and save. Do this for both roles.
To assign the billing role:
- Open Cost Management + Billing, and select the billing profile.
- Open Access control (IAM), and select Add.
- Select Billing profile reader, search for the application, and select Add.
An MCA billing profile has its own billing roles. You do not assign them on a subscription. See Billing roles for Microsoft Customer Agreements in the Microsoft documentation.
3. Note the billing IDs
Copy the full billing account ID and the billing profile ID from Cost Management + Billing. The billing account ID of an MCA has the form <guid>:<guid>_2019-05-31.
Hypermeter needs both IDs. A service principal that has access to the billing profile only may not be able to find its billing account.
4. Register the Microsoft.Insights provider
Register the Microsoft.Insights resource provider in every subscription:
az provider register --namespace Microsoft.Insights --subscription '<subscription-id>'
Do this again for each new subscription. Without the provider, Azure Monitor answers with HTTP 403. That looks like a missing role, but it is not.
Connect Azure to Hypermeter
Enter the connection values
The workflows read the connection values from inputs.
Store the client secret as a secret and nowhere else.
| Input | Value |
|---|---|
tenant-id | The Directory (tenant) ID |
client-id | The Application (client) ID |
client-secret | The client secret, as a secret |
billing-account-id | The full MCA billing account ID |
billing-profile-id | The billing profile ID |
metric-type | ActualCost |
from-date and to-date | Leave both empty. See Schedule the cost workflow |
Both workflows use the same service principal. To enter the shared values once, put them in an input group and attach the group to both workflows.
Check the authenticator
The Extract jobs sign in with an OAuth 2 authenticator. It has these settings:
| Field | Value |
|---|---|
| URL | https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token |
| Client ID | The Application (client) ID |
| Client secret | The secret with the client secret |
| Grant type | client_credentials |
| Scope | https://management.azure.com/.default |
To create or change an authenticator, see Connections and authentication.
Schedule the cost workflow
- Open the cost workflow, open Operate, and select Schedules.
- Add a schedule with the cron expression
0 5 * * *and the timezoneUTC. The workflow then runs every day at 05:00 UTC. - Save, and turn on Enabled.
Good to know:
- With
from-dateandto-dateempty, each scheduled run collects one day, three days before the run. - Enter both dates only to collect history. Keep the period of each run short: a run over a long period can fail because it runs out of memory.
- One run collects one kind of cost. For amortized cost, set up a second run with
metric-typeAmortizedCost. - Hypermeter requests a report from the Cost Details API and downloads the result. It does not use Cost Management Exports. You need no storage account, no storage role, and no SAS token.
Choose and schedule the metrics workflow
The metrics workflow has two variants. Run only one of them. Both write the same data, so two variants only double the number of calls to Azure.
| Variant | Covers | Use it when |
|---|---|---|
| Standard | Virtual machines, scale sets, managed disks, Advisor, and virtual machine sizes | You need rightsizing for compute only |
| Extended | The same, plus SQL databases, elastic pools, App Service plans, disk throughput of virtual machines, and a check of the collected subscriptions against the billed subscriptions | You also need platform services, or proof that no subscription is missing |
- Open the workflow, open Operate, and select Schedules.
- Add a schedule with the cron expression
30 2 * * *and the timezoneUTC. The workflow then runs every day at 02:30 UTC. - Choose
run-timeas the Scheduled timestamp target. The workflow calculates its collection period from this time. - Save, and turn on Enabled.
Good to know:
- Each run collects the hourly values of the last 30 days. A run that collects a day again updates the rows of that day. It does not add them a second time.
- The inventory covers every subscription that the service principal can read. You do not enter a management group or a list of subscriptions.
- For a run with Execute, enter
run-timeyourself. A manual run does not get the values of a schedule. - If you also collect from AWS, give the workflows different start times.
For the steps of a schedule, see Schedule a workflow.
Collect the history at once
Azure keeps platform metrics for 93 days. After that, they are gone and nobody can get them back.
Collect the last 93 days directly after the first successful run of the metrics workflow. See Backfill a date range.
Verify the connection
A successful run does not prove that the data is complete. Azure also answers without an error when the service principal can see nothing. Compare the result with an inventory that you know.
After the first run of each workflow, check that:
- The inventory has the number of subscriptions, virtual machines, and disks that you expect.
- At least one running virtual machine has CPU and memory values.
- The Advisor recommendations are present, or Advisor has none for you.
- The cost rows have a subscription ID, a resource ID, a billing currency, a cost in that currency, and a date.
- The Azure Rightsizing view shows the billed cost next to the utilization.
How to read the numbers
| Value | What to know |
|---|---|
| CPU, 95th percentile | Azure Monitor has no percentiles. Hypermeter takes the 95th percentile of the hourly maximums. The field is named cpu_p95_of_hourly_max, and it is higher than a true 95th percentile. |
| Memory | Azure reports the available memory. Hypermeter shows the memory in use: 100 minus the available percentage. |
| Disk space | Azure does not report how much of a disk is in use. Hypermeter shows the allocated size, and whether a disk is idle according to its IOPS. |
| Cost per resource | Cost and metrics are matched on the resource ID and the usage date. |
Troubleshooting
| What you see | What it means | What to do |
|---|---|---|
| The metrics run fails with HTTP 403 | Microsoft.Insights is not registered in a subscription, or the Monitoring Reader role is missing. | Register the provider in every subscription. Then check the role. |
| The run succeeds, but virtual machines, disks, or whole subscriptions are missing | The service principal has no Reader role on those subscriptions. Azure Resource Graph then returns an empty result and no error. | Assign Reader and Monitoring Reader at the management group, or on each missing subscription. |
The sign-in fails, often with an error code that starts with AADSTS | The tenant ID or the client ID is wrong, or the client secret is wrong or expired. | Correct the inputs. For a new client secret, rotate the secret. |
| The cost run is refused, or it cannot find the billing account | The billing role is missing, or the billing account ID is not complete. | Assign Billing profile reader on the billing profile. Enter the full billing account ID. |
| The cost run fails on a long period | The report is too large for one run. | Leave from-date and to-date empty, or collect the history in short periods. |
| Metrics of more than 93 days ago are missing | Azure deleted them. | Nothing. Collect the history directly after the first run next time. |
If a run fails for another reason, see Troubleshooting run failures.