Provisioning an Azure Monitor Workspace

Preview

Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in

Provisioning an Azure Monitor Workspace

This guide shows you how to provision an Azure Monitor workspace against Locally - the workspace that stores Prometheus metrics. As with the other guides we're going to use the Azure CLI, but the same resources can be provisioned with HashiCorp Terraform, Pulumi or Bicep too.

This covers the control plane only. Locally doesn't emulate the workspace's data plane yet, so you can create and manage the workspace, but not send metrics to it or query them.

Before you start

Plugin required

This requires the Microsoft.Monitor plugin, which you can install with:

$ locally plugin install --name Microsoft.Monitor

1. Start Locally

Firstly, we need to launch Locally which we can do from a terminal by running:

$ locally build

Once Locally has started, the Locally Dashboard will open automatically:

Screenshot of the Locally Dashboard

2. Create a Resource Group

Next we can create the Resource Group:

$ locally run az group create -n sample-resources -l berlin

There's two things to note here:

  1. The Azure CLI supports Automatic Configuration, meaning that it can automatically be configured to work against Locally just by prefixing commands with locally run.
  2. Locally intentionally uses a different set of locations to Azure as a safety precaution, so that you can be confident you're deploying against Locally rather than regular Azure. You can also configure Locally to use the Azure locations too, but you'll want to be extra sure that you're prefixing commands with locally run when you do.

3. Create the Workspace

With the Resource Group in place, we can create the workspace. The Azure CLI calls these accounts, after the Microsoft.Monitor/accounts resource type:

$ locally run az monitor account create -n sample-amw -g sample-resources -l berlin
{
  "note": "some fields skipped for brevity",

  "id": "/subscriptions/307d8f52-9719-460e-9f85-aa408e28ee55/resourceGroups/sample-resources/providers/Microsoft.Monitor/accounts/sample-amw",
  "metrics": {
    "prometheusQueryEndpoint": "https://sample-amw.monitor.locally:5668/"
  },
  "name": "sample-amw",
  "provisioningState": "Succeeded",
  "type": "Microsoft.Monitor/accounts"
}

The response includes a prometheusQueryEndpoint, as it does in Azure. We can read it back at any point:

$ locally run az monitor account show -n sample-amw -g sample-resources --query metrics.prometheusQueryEndpoint -o tsv

Note

Locally provisions the workspace but doesn't serve Prometheus queries yet, so nothing answers on that endpoint. The same goes for the data collection endpoint and rule named under defaultIngestionSettings, which Azure creates in a managed Resource Group - Locally returns their IDs, but doesn't create them.

We can list the workspaces in the Resource Group:

$ locally run az monitor account list -g sample-resources --query "[].{Name:name, Location:location, State:provisioningState}" -o table
Name        Location    State
----------  ----------  ---------
sample-amw  berlin      Succeeded

And update one, here to add a tag:

$ locally run az monitor account update -n sample-amw -g sample-resources --tags env=dev --query "{name:name, tags:tags}"
{
  "name": "sample-amw",
  "tags": {
    "env": "dev"
  }
}

We can see the Azure Monitor workspace in the Locally Dashboard too:

Screenshot of the Azure Monitor workspace in the Locally Dashboard

4. Tidy up

Finally, we can tidy up. To remove just the workspace:

$ locally run az monitor account delete -n sample-amw -g sample-resources --yes

Or to remove the Resource Group and everything within it:

$ locally run az group delete -n sample-resources --yes

Doing this with other tooling

Whilst this guide used the Azure CLI, an Azure Monitor workspace works the same way through any of the tooling that Locally supports - a Microsoft.Monitor/accounts resource in HashiCorp Terraform or OpenTofu, Pulumi, Bicep or an ARM Template all provision against Locally in the same way, with only the location changed.

Next steps

To alert on activity in your subscription, see Alerts. To provision the rest of your monitoring alongside the workspace, see Log Analytics Workspace and Application Insights.

Should you encounter any issues, please take a look at the troubleshooting section.

Preview

Sign in during Public Preview to get the Team plan free, plus an early-adopter discount when we launch. Sign in

A local cloud for you and your AI agents.

Your Azure infrastructure, running on your machine. Deploy in seconds, break things freely, and ship to Azure when you're ready.