Skip to content

Commit f69fe2a

Browse files
authored
[Monitor]add parameter dimension for Get-AzMetric (#22478)
* add parameter dimension for Get-AzMetric * make -metricfilter available for both parameter sets
1 parent 22473f4 commit f69fe2a

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/Monitor/Monitor/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Added parameter `Dimension` for `Get-AzMetric` to easily filter metrics by dimensions [#22320]
2223

2324
## Version 4.5.0
2425
* Added cmdlets for monitor workspace:

src/Monitor/Monitor/Metrics/GetAzureRmMetricCommand.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
using Microsoft.Azure.Management.Monitor.Models;
2323
using Microsoft.Rest.Azure.OData;
2424
using System.Globalization;
25+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
26+
using Microsoft.Azure.Commands.Common.Exceptions;
2527

2628
namespace Microsoft.Azure.Commands.Insights.Metrics
2729
{
@@ -104,9 +106,15 @@ public class GetAzureRmMetricCommand : ManagementCmdletBase
104106
/// <summary>
105107
/// Gets or sets the metricfilter parameter of the cmdlet
106108
/// </summary>
107-
[Parameter(ParameterSetName = GetAzureRmAMetricFullParamGroup, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The metric dimension filter to query metrics for")]
109+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The metric dimension filter to query metrics for")]
108110
public string MetricFilter { get; set; }
109111

112+
/// <summary>
113+
/// Gets or sets the dimension parameter of the cmdlet
114+
/// </summary>
115+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The metric dimensions to query metrics for")]
116+
public string[] Dimension { get; set; }
117+
110118
/// <summary>
111119
/// Gets or sets the metricnames parameter of the cmdlet
112120
/// </summary>
@@ -133,6 +141,15 @@ protected override void ProcessRecordInternal()
133141
message: "The DetailedOutput parameter will be deprecated in a future breaking change release.");
134142
bool fullDetails = this.DetailedOutput.IsPresent;
135143

144+
if (this.IsParameterBound(c => c.Dimension))
145+
{
146+
if (this.IsParameterBound(c => c.MetricFilter) && !string.IsNullOrEmpty(this.MetricFilter))
147+
{
148+
throw new AzPSArgumentException("usage: -Dimension and -MetricFilter parameters are mutually exclusive.", "MetricFilter");
149+
}
150+
this.MetricFilter = string.Join(" and ", this.Dimension.Select(d => string.Format("{0} eq '*'", d)));
151+
}
152+
136153
// EndTime defaults to Now
137154
if (this.EndTime == default(DateTime))
138155
{

src/Monitor/Monitor/help/Get-AzMetric.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ Gets the metric values of a resource.
1616
### GetWithDefaultParameters (Default)
1717
```
1818
Get-AzMetric [-ResourceId] <String> [-TimeGrain <TimeSpan>] [-StartTime <DateTime>] [-EndTime <DateTime>]
19-
[[-MetricName] <String[]>] [-DetailedOutput] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
19+
[-MetricFilter <String>] [-Dimension <String[]>] [[-MetricName] <String[]>] [-DetailedOutput]
20+
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2021
```
2122

2223
### GetWithFullParameters
2324
```
2425
Get-AzMetric [-ResourceId] <String> [-TimeGrain <TimeSpan>] [-AggregationType <AggregationType>]
2526
[-StartTime <DateTime>] [-EndTime <DateTime>] [-Top <Int32>] [-OrderBy <String>] [-MetricNamespace <String>]
26-
[-ResultType <ResultType>] [-MetricFilter <String>] [-MetricName] <String[]> [-DetailedOutput]
27-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
27+
[-ResultType <ResultType>] [-MetricFilter <String>] [-Dimension <String[]>] [-MetricName] <String[]>
28+
[-DetailedOutput] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2829
```
2930

3031
## DESCRIPTION
@@ -254,6 +255,21 @@ Accept pipeline input: True (ByPropertyName)
254255
Accept wildcard characters: False
255256
```
256257
258+
### -Dimension
259+
The metric dimensions to query metrics for
260+
261+
```yaml
262+
Type: System.String[]
263+
Parameter Sets: (All)
264+
Aliases:
265+
266+
Required: False
267+
Position: Named
268+
Default value: None
269+
Accept pipeline input: True (ByPropertyName)
270+
Accept wildcard characters: False
271+
```
272+
257273
### -EndTime
258274
Specifies the end time of the query in local time.
259275
The default is the current time.
@@ -275,7 +291,7 @@ Specifies the metric dimension filter to query metrics for.
275291
276292
```yaml
277293
Type: System.String
278-
Parameter Sets: GetWithFullParameters
294+
Parameter Sets: (All)
279295
Aliases:
280296

281297
Required: False

0 commit comments

Comments
 (0)