Add Monitor Metrics Batchquery command - #3393
Open
msalaman wants to merge 2 commits into
Open
Conversation
msalaman
requested review from
a team,
Jackson Weber (JacksonWeber),
Leighton Chen (lzchen),
Radhika Gupta (rads-1996),
Rajkumar Rangaraj (rajkumar-rangaraj) and
xiang17
as code owners
August 26, 2026 23:29
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Azure Monitor Metrics batch query command (azmcp monitor metrics batchquery) to query metrics across multiple resources in a single request, wiring it into the Monitor toolset, serialization, docs, and tests.
Changes:
- Introduces
MetricsBatchQueryCommandwith new options and result model for multi-resource metrics queries. - Extends
IMonitorMetricsService/MonitorMetricsServicewith aQueryMetricsBatchAsyncimplementation backed byAzure.Monitor.Query.Metrics. - Updates Azure MCP Server docs (command reference, e2e prompts) and adds a changelog entry.
Show a summary per file
| File | Description |
|---|---|
| tools/Azure.Mcp.Tools.Monitor/tests/Azure.Mcp.Tools.Monitor.Tests/Metrics/MetricsBatchQueryCommandTests.cs | Adds unit tests for option binding, validation, and bucket-limit handling for the new command. |
| tools/Azure.Mcp.Tools.Monitor/src/Services/MonitorMetricsService.cs | Implements multi-resource metrics querying via MetricsClient.QueryResourcesAsync. |
| tools/Azure.Mcp.Tools.Monitor/src/Services/IMonitorMetricsService.cs | Adds service interface contract for batch metrics querying. |
| tools/Azure.Mcp.Tools.Monitor/src/Options/Metrics/MetricsBatchQueryOptions.cs | Introduces CLI options surface for batchquery. |
| tools/Azure.Mcp.Tools.Monitor/src/MonitorSetup.cs | Registers the new command in DI and the monitor metrics command group. |
| tools/Azure.Mcp.Tools.Monitor/src/Models/ResourceMetricsResult.cs | Adds a per-resource result wrapper for batch query responses. |
| tools/Azure.Mcp.Tools.Monitor/src/Commands/MonitorJsonContext.cs | Registers new result types for source-generated System.Text.Json (AOT). |
| tools/Azure.Mcp.Tools.Monitor/src/Commands/Metrics/MetricsBatchQueryCommand.cs | Adds the new tool command, validation, defaults, execution, and response shaping. |
| tools/Azure.Mcp.Tools.Monitor/src/Azure.Mcp.Tools.Monitor.csproj | Adds package reference for Azure.Monitor.Query.Metrics. |
| servers/Azure.Mcp.Server/docs/e2eTestPrompts.md | Adds e2e prompts for monitor_metrics_batchquery. |
| servers/Azure.Mcp.Server/docs/azmcp-commands.md | Documents the new azmcp monitor metrics batchquery command usage and example. |
| servers/Azure.Mcp.Server/changelog-entries/monitor-metrics-batchquery.yml | Adds changelog entry for the new command. |
| Directory.Packages.props | Centrally pins Azure.Monitor.Query.Metrics version. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 13/13 changed files
- Comments generated: 4
- Review effort level: Lite
Comment on lines
+365
to
+371
| // Resolve each resource name (or already-valid resource ID) to a full resource identifier. | ||
| var resourceIds = new List<ResourceIdentifier>(resourceNames.Count); | ||
| foreach (var resourceName in resourceNames) | ||
| { | ||
| var resourceId = await _resourceResolverService.ResolveResourceIdAsync(subscription, resourceGroup, resourceType, resourceName, tenant, retryPolicy, cancellationToken); | ||
| resourceIds.Add(resourceId); | ||
| } |
Comment on lines
154
to
156
| metrics.AddCommand<MetricsQueryCommand>(serviceProvider); | ||
| metrics.AddCommand<MetricsBatchQueryCommand>(serviceProvider); | ||
| metrics.AddCommand<MetricsDefinitionsCommand>(serviceProvider); |
Comment on lines
+19
to
+24
| [CommandMetadata( | ||
| Id = "6c1b0f5f-04c1-4b2e-8f0b-0d6f4f7cba2e", | ||
| Name = "batchquery", | ||
| Title = "Query Azure Monitor Metrics for Multiple Resources", | ||
| Description = "Query Azure Monitor metrics for multiple resources in a single batch request. Returns time series data for the specified metrics, grouped by resource. All resources must belong to the same subscription, Azure region, and resource type.", | ||
| Destructive = false, |
Comment on lines
+75
to
+82
| public override async Task<CommandResponse> ExecuteAsync(CommandContext context, MetricsBatchQueryOptions options, CancellationToken cancellationToken) | ||
| { | ||
| try | ||
| { | ||
| string[] resources = [.. options.Resources.Split(',').Select(t => t.Trim())]; | ||
| string[] metricNames = [.. options.MetricNames.Split(',').Select(t => t.Trim())]; | ||
|
|
||
| var results = await _metricsService.QueryMetricsBatchAsync( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Add
Monitor Metrics Batchquerycommand to support querying for multiple resourcesGitHub issue number?
#1464
Pre-merge Checklist
servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationREADME.mdchanges running the script./eng/scripts/Process-PackageReadMe.ps1. See Package READMEToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.jsonbreaking-changelabelservers/Azure.Mcp.Server/docs/azmcp-commands.md./eng/scripts/Update-AzCommandsMetadata.ps1to update tool metadata inazmcp-commands.md(required for CI)servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline