--- name: azmon_workspace_promql description: Query Azure Monitor Workspaces (Managed Prometheus) using PromQL to investigate OpenTelemetry (OTel) hostmetrics and process performance telemetry (CPU, memory, swap/paging, disk I/O latency, filesystem capacity, network errors/connections, and per-process resource usage) across Linux and Windows machines. Use whenever asked about Azure Monitor Workspace metrics, Managed Prometheus, PromQL queries, or OTel machine/host performance telemetry. --- # Azure Monitor Workspace (PromQL & OpenTelemetry Host/Process Telemetry) Skill ## When to Use This Skill Use this skill whenever you need to: - Discover or query an **Azure Monitor Workspace** (`Microsoft.Monitor/accounts` / Azure Managed Prometheus). - Run **PromQL** instant queries (`/api/v1/query`), range queries (`/api/v1/query_range`), series metadata lookups (`/api/v1/series`), or metric discovery (`/api/v1/label/__name__/values`). - Investigate **OpenTelemetry (`hostmetrics` and `process`)** performance telemetry from Linux or Windows machines (CPU saturation, kernel/iowait/interrupt spikes, memory pressure, swap paging, disk I/O latency, filesystem fullness, network drops/TCP states, or top resource-consuming processes). --- ## Dual-Runtime Execution Model (Azure SRE Agent vs. GitHub Copilot App / CLI) This skill is designed to run in **two environments**: | Runtime Environment | Available Tools | How to Execute Discovery & PromQL Queries | |---|---|---| | **1. Azure SRE Agent (Cloud)** | `RunAzCliReadCommands` (Azure Operation) + built-in Code Execution (`ExecutePythonCode`) | Use `RunAzCliReadCommands` (without `-o` or `--query` flags) to run `az monitor account list` and the `az_rest_command` built by `scripts/promql_helper.py`, and use built-in Python Code Execution to run `promql_helper.py` for URL construction and response summarization. | | **2. GitHub Copilot App / CLI (Local)** | Local terminal (`powershell` / `bash`) with `python` and `az` CLI | Run `python "/scripts/promql_helper.py" discover` and `python "/scripts/promql_helper.py" run ...` directly in the shell. Locally, `promql_helper.py` automatically acquires the `https://prometheus.monitor.azure.com` token from your active `az login` session (`DefaultAzureCredential` / `az account get-access-token`), executes the HTTP request, and outputs the statistical summary in a single step. | --- ## Critical Naming Convention (#1 Gotcha): DOTS vs. Underscores **Read this first to avoid wasted queries.** Azure Managed Prometheus with OpenTelemetry collectors (especially Azure Arc / hybrid compute / AMA OTel pipelines) frequently stores OTel metrics and labels using **dot-separated** names without unit suffixes, NOT the underscore-separated names found in standard Prometheus exporters. ### Metric Names (Dot-Separated vs. Underscore-Separated) | OTel / Azure Monitor Workspace Dot Name (Most Common) | Standard Prometheus Exporter Underscore Name | |---|---| | `system.cpu.utilization` | `system_cpu_utilization_ratio` / `system_cpu_utilization` | | `system.cpu.time` | `system_cpu_time_seconds_total` | | `system.memory.utilization` | `system_memory_utilization_ratio` / `system_memory_utilization` | | `system.memory.usage` | `system_memory_usage_bytes` | | `system.disk.io` | `system_disk_io_bytes_total` | | `system.disk.operations` | `system_disk_operations_total` | | `system.disk.operation_time` | `system_disk_operation_time_seconds_total` | | `system.filesystem.usage` | `system_filesystem_usage_bytes` | | `system.network.io` | `system_network_io_bytes_total` | | `process.cpu.utilization` | `process_cpu_utilization_ratio` / `process_cpu_utilization` | | `process.cpu.time` | `process_cpu_time_seconds_total` | | `process.memory.utilization` | `process_memory_utilization_ratio` / `process_memory_utilization` | | `process.memory.usage` | `process_memory_usage_bytes` | **Rule**: Always discover metric names via `/api/v1/label/__name__/values` first (Step 2A). When dot-separated names are present, follow the PromQL syntax rules below. ### Label Names in Dot-Separated OTel Workspaces Labels also use **dots**, not underscores: | Label Name | Description | Generic Example Value | |---|---|---| | `microsoft.resourceid` | Full ARM resource ID of the machine (machine hostname is the last path segment) | `/subscriptions//resourcegroups//providers/microsoft.hybridcompute/machines/` | | `microsoft.resourcegroupname` | Resource group of the machine | `rg-prod-compute` | | `microsoft.resourcetype` | ARM resource type of the machine | `microsoft.hybridcompute/machines` or `microsoft.compute/virtualmachines` | | `microsoft.subscriptionid` | Subscription GUID of the machine | `` | | `microsoft.amwresourceid` | ARM resource ID of the Azure Monitor Workspace itself | `/subscriptions//resourcegroups//providers/microsoft.monitor/accounts/` | | `process.executable.name` | Process executable name | `sqlservr.exe`, `wdavdaemon`, `nginx` | | `process.command` | Full process command / invocation | `"c:\program files\..."` | | `process.owner` | Process owner | `root`, `nt service\...` | | `process.pid` | Process ID | `5548` | | `state` | CPU state or memory state | `idle`, `user`, `system`, `interrupt`, `nice`, `softirq`, `steal`, `wait`, `iowait`, `used`, `free` | | `cpu` | Per-core CPU identifier (Windows machines) | `cpu0`, `cpu1` | --- ## PromQL Syntax Rules for Dot-Named Metrics and Labels Because metric and label names contain dots (`.`), standard bare PromQL identifiers fail with parse errors. You **must** use `{__name__="..."}` selectors and double-quoted label names: ### 1. Using Dot-Separated Metric Names ```promql # WRONG - dots are not valid in bare PromQL metric identifiers system.cpu.utilization{state="idle"} # CORRECT - always use the __name__ selector {__name__="system.cpu.utilization", state="idle"} ``` ### 2. Using Dot-Separated Label Names in `by()` / `without()` Clauses Labels with dots **must be double-quoted** inside aggregation and grouping clauses: ```promql # WRONG - unquoted dots in label names fail to parse avg by (microsoft.resourceid) ({__name__="system.cpu.utilization"}) # CORRECT - quote the dot-separated label name avg by ("microsoft.resourceid") ({__name__="system.cpu.utilization"}) ``` ### 3. Multi-Label Grouping ```promql sum by ("microsoft.resourceid", "process.executable.name") ({__name__="process.cpu.utilization"}) ``` --- ## Ready-to-Use PromQL Recipes (Dot-Named OTel Schema) Use these verified expressions directly once `/api/v1/label/__name__/values` confirms dot-separated metric names: ### CPU Utilization % per Machine (range or instant query) ```promql (1 - avg by ("microsoft.resourceid") ({__name__="system.cpu.utilization", state="idle"})) * 100 ``` ### Memory Utilization % per Machine (range or instant query) ```promql avg by ("microsoft.resourceid") ({__name__="system.memory.utilization"}) * 100 ``` ### Top N Processes by CPU % per Machine (instant or range query) ```promql topk(10, sum by ("microsoft.resourceid", "process.executable.name") ({__name__="process.cpu.utilization"})) * 100 ``` ### Top N Processes by Memory % per Machine (instant or range query) ```promql topk(10, sum by ("microsoft.resourceid", "process.executable.name") ({__name__="process.memory.utilization"})) * 100 ``` > **Why `sum by` for process metrics?** `sum by ("microsoft.resourceid", "process.executable.name")` aggregates across multiple PIDs of the same executable name and across CPU states (`user`, `system`), giving the total resource footprint of that executable on each machine. For additional disk, filesystem, network, and underscore-schema recipes, see `references/otel_host_process_promql.md`. --- ## Critical Guardrails (API & Tool Constraints) 1. **NEVER pass `-o` / `--output` or `--query` to `RunAzCliReadCommands`**: - SRE Agent's `RunAzCliReadCommands` tool automatically formats output as JSON. Passing `-o json`, `-o table`, `-o tsv`, or `--query` causes the tool to fail with `"Unknown error occurred"`. Always invoke plain read commands and parse the returned JSON. 2. **Always use `GET` with `az rest` and `--resource "https://prometheus.monitor.azure.com"`**: - The Azure Monitor Workspace Prometheus endpoint is a **data-plane API** requiring an Entra ID token for `https://prometheus.monitor.azure.com`. - Always run `az rest --method get --resource "https://prometheus.monitor.azure.com" --url "https:///api/v1/..."` so the request executes as a **Safe** read command under `RunAzCliReadCommands` without write-approval prompts. 3. **Azure Monitor Workspace PromQL API Limitations**: - **Mandatory single `__name__` matcher**: Every `/query`, `/query_range`, and `/series` call **must** include an explicit metric name (e.g., `{__name__="system.cpu.utilization"}`). Bare label selectors like `{state="idle"}` fail with HTTP 400/422. - **No regex on `__name__`**: `{__name__=~"system.*"}` is NOT supported. Query each metric individually. - **Label values API restriction**: `/api/v1/label/