Skip to content
← Cosmos workspace

Cosmos monitoring setup

NoSqlStudio reads Cosmos metrics through tiered data sources. This page is the step-by-step guide for wiring each tier. Pick the path that matches your budget and observability needs.

Tier matrix

TierCostProduction impactUnlocks
TIER C · ALWAYS-ON
Local samples
US$ 0NoneRU Budget (app-only), Throttling RCA (429 from headers), Hot Partitions heat, Query Cost — all from captured response headers. Sees only NoSqlStudio traffic.
TIER B · FREE
Azure Monitor
US$ 0None — reads platform metrics from ARM, never touches Cosmos data plane.Aggregate RU Budget, Throughput Optimizer, Throttling count, Hot Partitions per PartitionKeyRangeId — covers production traffic.
TIER A · PAID
Log Analytics
~US$ 2.50 / GB ingest + retentionDocumented as minimal by Microsoft; ingestion stream runs continuously.Full per-shape KQL in app, Diagnostic Logs pane, per-shape Throttling RCA, composite-index recommendations from real workload traces.
Path 1

FREE — Azure Monitor + Local samples

Setup time: ~10 min. Cost: US$ 0/month. Impact: zero on production. Covers RU Budget, Throughput Optimizer, Throttling count, Hot Partitions (aggregate), Query Cost (in-app).

Part A — Azure portal / CLI

1. Create a Service Principal

Portal: Azure Active Directory → App registrations → New registration → name nosqlstudio-cosmos-reader. Copy Application (client) ID, Directory (tenant) ID, and create a Client Secret under Certificates & secrets.

CLI equivalent:

az ad sp create-for-rbac \
  --name nosqlstudio-cosmos-reader \
  --role "Monitoring Reader" \
  --scopes /subscriptions/<SUB_ID>/resourceGroups/<RG_NAME>

2. Assign role Monitoring Reader

Minimum scope: the resource group holding the Cosmos account. If you want to cover multiple Cosmos accounts in different RGs, assign at subscription level.

az role assignment create \
  --assignee <APP_ID> \
  --role "Monitoring Reader" \
  --scope /subscriptions/<SUB_ID>/resourceGroups/<RG_NAME>

3. Copy the Cosmos Resource ID

Format: /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.DocumentDB/databaseAccounts/<account>

az cosmosdb show -n <ACCOUNT_NAME> -g <RG_NAME> --query id -o tsv

Part B — NoSqlStudio

  1. Connect to your Cosmos account in NoSqlStudio.
  2. Open Cosmos Optimizer (Ctrl+Alt+Shift+Y or menu Tools).
  3. Go to the Cloud Credentials tab.
  4. In TIER B · FREE — Azure Monitor, fill: Resource ID, Tenant ID, Client ID, Client secret.
  5. Leave Workspace ID (GUID) in the TIER A section empty — you are opting out of paid tier.
  6. Click Save credentials (encrypted).

Part C — Verify

Go back to the RU Budget tab. The source-mode banner should show a green Azure Monitor chip + the text aggregate only — no per-shape breakdown. Click Refresh — numbers populate within 1–2 minutes (Azure can take a few minutes for fresh metrics to be available).

Path 2

PAID — add Log Analytics

Setup time: additional ~15 min. Cost: ~US$ 2.50/GB ingested + ~US$ 0.10/GB-month retention. Only do this if you need per-shape granularity — for 90% of investigations, Azure Monitor alone is sufficient.

Part A — Create a Log Analytics workspace

az monitor log-analytics workspace create \
  -g <RG_NAME> -n nosqlstudio-cosmos-logs \
  --retention-time 30 \
  --location <REGION>

Part B — Put cost guardrails in place BEFORE enabling logs

  • Short retention: 30 days minimum on most tiers.
  • Daily cap (e.g. 1 GB/day): stops ingestion if exceeded — existing data still queryable.
  • Budget alert on the subscription (e.g. US$ 50/month with alert at 80%).
az monitor log-analytics workspace update \
  -g <RG_NAME> -n nosqlstudio-cosmos-logs \
  --quota 1

Part C — Enable Diagnostic Settings on the Cosmos account

Portal: Cosmos DB → Monitoring → Diagnostic settings → Add. Tick only what you actually need:

  • MongoRequests — essential, what the in-app KQL pane queries.
  • DataPlaneRequests — optional, duplicates info from MongoRequests for the Mongo API.
  • ControlPlaneRequests — skip; admin operations only.
  • QueryRuntimeStatistics, PartitionKeyStatistics — most expensive, skip unless explicitly needed.

Destination: Resource specific table type (cheaper than Azure Diagnostics legacy).

az monitor diagnostic-settings create \
  --name to-loganalytics \
  --resource $(az cosmosdb show -n <ACCOUNT> -g <RG> --query id -o tsv) \
  --workspace $(az monitor log-analytics workspace show -g <RG> -n nosqlstudio-cosmos-logs --query id -o tsv) \
  --logs '[{"category":"MongoRequests","enabled":true}]' \
  --export-to-resource-specific true

Part D — Grant Log Analytics Reader to the Service Principal

az role assignment create \
  --assignee <APP_ID> \
  --role "Log Analytics Reader" \
  --scope $(az monitor log-analytics workspace show -g <RG> -n nosqlstudio-cosmos-logs --query id -o tsv)

Part E — Copy the Workspace ID (GUID)

Important: not the Resource ID — it's a separate GUID. Found in Portal under Log Analytics workspace → Overview → Workspace ID.

az monitor log-analytics workspace show \
  -g <RG_NAME> -n nosqlstudio-cosmos-logs \
  --query customerId -o tsv

Part F — NoSqlStudio

  1. Cloud Credentials tab → TIER A · PAID — Log Analytics section.
  2. Paste the GUID into Workspace ID (GUID).
  3. Click Save.

Part G — Verify

Diagnostic Logs (KQL) pane: banner now shows Log Analytics — full granularity. The Run in app button unlocks. Pick the "Slow queries — last 1 hour" template, click Run. Results render in the table below.

Quick decision table

ScenarioRecommendation
Dev cluster, test environmentPath 1 (FREE). Skip Log Analytics.
Production cluster, healthy — want basic observabilityPath 1 (FREE).
Active incident — need to know WHICH query spiked at 14:32Path 1 + 2 temporarily. Disable Diagnostic Setting after the investigation.
Compliance — log retention required for N daysPath 1 + 2 permanent. Daily cap mandatory.
No Azure budget at allTIER C (Local samples) only. Leave Cloud Credentials empty. Workspace falls back automatically — only loses Diagnostic Logs (KQL).

Troubleshooting — “I created the Diagnostic Setting but no data is flowing”

A brand-new Diagnostic Setting sometimes refuses to start emitting events for 30+ minutes (or never), even though the management plane reports it as “active”. This is a known quirk of Azure Monitor when a previous setting on the same resource was recently deleted, or when only a single log category is enabled.

How to confirm you are stuck in this state

Run the probe below — works either inside the workspace’s Logs blade (just the KQL part) or from your terminal via az CLI. Replace <your-workspace-guid> with the GUID you copied from Workspace → Overview → Workspace ID. If cnt stays at 0 for more than 10 minutes while the account is actively serving traffic, you are stuck.

az monitor log-analytics query \
  --workspace <your-workspace-guid> \
  --analytics-query "CDBMongoRequests | where TimeGenerated > ago(10m) | summarize cnt=count()" \
  -o table

The workaround that unsticks it

Delete the Diagnostic Setting and recreate it with three log categories enabled at the same time instead of just MongoRequests. The extra categories prime the diagnostic pipeline that the single-category setting failed to initialise.

RID="/subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.DocumentDB/databaseAccounts/<acct>"
WS="/subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.OperationalInsights/workspaces/<ws-name>"

az monitor diagnostic-settings delete --name nosqlstudio-monitoring --resource "$RID"

az monitor diagnostic-settings create \
  --name nosqlstudio-monitoring \
  --resource "$RID" \
  --workspace "$WS" \
  --logs '[{"category":"MongoRequests","enabled":true},{"category":"DataPlaneRequests","enabled":true},{"category":"QueryRuntimeStatistics","enabled":true}]' \
  --metrics '[{"category":"Requests","enabled":true}]' \
  --export-to-resource-specific true

After the recreate, re-run the KQL probe. Events typically appear within 3–7 minutes. Once flowing, you can leave all three categories enabled (the extra two cost a bit more ingestion but give you query plan + raw request payloads in CDBQueryRuntimeStatistics and CDBDataPlaneRequests), or disable the extras after the pipeline warms up.

When even the workaround doesn’t work

  • Confirm the Cosmos account API is MongoDB (run az cosmosdb show --ids "$RID" --query "kind" — must print MongoDB; MongoRequests only fires for that API).
  • Confirm the workspace region matches the Cosmos account region (cross-region pipelines are slower and sometimes drop the first hour).
  • Check az monitor activity-log list --resource-id "$RID" --offset 1h for any failed diagnostic-setting operations.
  • Last resort: open an Azure support ticket — the diagnostic pipeline is fully Microsoft-managed and we can’t inspect it further from the outside.

Disabling later to stop paying

  1. NoSqlStudio: Cloud Credentials → delete the Workspace ID (GUID) → Save. App falls back to Azure Monitor automatically (banner flips green within seconds).
  2. Azure: Cosmos account → Diagnostic settings → delete the setting. Stops the ingestion stream.
  3. Optional: delete the Log Analytics workspace if it's not used for anything else. Otherwise leave it — retention cost drops to zero as no new logs flow in.