Skip to main content

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.

WorkflowReadsResult
MetricsThe inventory from Azure Resource Graph, hourly metrics from Azure Monitor, and recommendations from Azure AdvisorThe cubes Azure Rightsizing and Azure Disk Waste
CostThe actual cost of a Microsoft Customer Agreement (MCA) billing profile, from the Cost Details APIThe cost per day and per service, and the savings that Advisor claims compared with the real spend

The metrics workflow collects these values:

DataDetails
CPUThe percentage per hour, and a 95th percentile
MemoryThe percentage in use. Azure reports it without a guest agent
NetworkGB in and GB out
DisksIOPS per volume, and the allocated size in GB
CapacityThe vCPUs and the memory of each virtual machine size
RecommendationsThe recommendations of Azure Advisor

For how Hypermeter calculates these values, see How to read the numbers.

Prerequisites​

You needDetails
A Microsoft Customer AgreementThe cost workflow reads an MCA billing profile.
Permission to register an application in Microsoft Entra IDThe 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 rolesThe Owner or User Access Administrator role on the management group, or on each subscription.
Permission to assign billing rolesThe owner role on the billing profile or on the billing account.
The Azure CLITo register a resource provider in each subscription.
The owner role in HypermeterTo store the client secret and to schedule the workflows. See Roles and permissions.

Configure Azure access​

1. Create the service principal​

  1. In the Azure portal, open Microsoft Entra ID, then App registrations, and select New registration.
  2. Enter a name, for example hypermeter-reader, and select Register.
  3. Copy the Application (client) ID and the Directory (tenant) ID.
  4. 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.

RoleScopeHypermeter uses it for
ReaderThe management group, or each subscriptionThe inventory: virtual machines, scale sets, disks, and virtual machine sizes
Monitoring ReaderThe same scope as ReaderThe metrics of Azure Monitor
Billing profile readerThe MCA billing profileThe cost reports
Assign roles at the management group level

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:

  1. Open the management group or the subscription, and open Access control (IAM).
  2. Select Add, then Add role assignment.
  3. Select the role, select the application, and save. Do this for both roles.

To assign the billing role:

  1. Open Cost Management + Billing, and select the billing profile.
  2. Open Access control (IAM), and select Add.
  3. 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>'
Resource provider registration

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.

Secure credential storage

Store the client secret as a secret and nowhere else.

InputValue
tenant-idThe Directory (tenant) ID
client-idThe Application (client) ID
client-secretThe client secret, as a secret
billing-account-idThe full MCA billing account ID
billing-profile-idThe billing profile ID
metric-typeActualCost
from-date and to-dateLeave 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:

FieldValue
URLhttps://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token
Client IDThe Application (client) ID
Client secretThe secret with the client secret
Grant typeclient_credentials
Scopehttps://management.azure.com/.default

To create or change an authenticator, see Connections and authentication.

Schedule the cost workflow​

  1. Open the cost workflow, open Operate, and select Schedules.
  2. Add a schedule with the cron expression 0 5 * * * and the timezone UTC. The workflow then runs every day at 05:00 UTC.
  3. Save, and turn on Enabled.

Good to know:

  • With from-date and to-date empty, 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-type AmortizedCost.
  • 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​

Run only one metrics variant

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.

VariantCoversUse it when
StandardVirtual machines, scale sets, managed disks, Advisor, and virtual machine sizesYou need rightsizing for compute only
ExtendedThe same, plus SQL databases, elastic pools, App Service plans, disk throughput of virtual machines, and a check of the collected subscriptions against the billed subscriptionsYou also need platform services, or proof that no subscription is missing
  1. Open the workflow, open Operate, and select Schedules.
  2. Add a schedule with the cron expression 30 2 * * * and the timezone UTC. The workflow then runs every day at 02:30 UTC.
  3. Choose run-time as the Scheduled timestamp target. The workflow calculates its collection period from this time.
  4. 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-time yourself. 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​

Limited historical data retention

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 guarantee complete data

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​

ValueWhat to know
CPU, 95th percentileAzure 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.
MemoryAzure reports the available memory. Hypermeter shows the memory in use: 100 minus the available percentage.
Disk spaceAzure 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 resourceCost and metrics are matched on the resource ID and the usage date.

Troubleshooting​

What you seeWhat it meansWhat to do
The metrics run fails with HTTP 403Microsoft.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 missingThe 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 AADSTSThe 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 accountThe 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 periodThe 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 missingAzure deleted them.Nothing. Collect the history directly after the first run next time.

If a run fails for another reason, see Troubleshooting run failures.