Get-AzMetric
Gets the metric values of a resource.
Syntax
Get-AzMetric
[-ResourceId] <String>
[-TimeGrain <TimeSpan>]
[-StartTime <DateTime>]
[-EndTime <DateTime>]
[-MetricFilter <String>]
[-Dimension <String[]>]
[[-MetricName] <String[]>]
[-DetailedOutput]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Get-AzMetric
[-ResourceId] <String>
[-TimeGrain <TimeSpan>]
[-AggregationType <AggregationType>]
[-StartTime <DateTime>]
[-EndTime <DateTime>]
[-Top <Int32>]
[-OrderBy <String>]
[-MetricNamespace <String>]
[-ResultType <ResultType>]
[-MetricFilter <String>]
[-Dimension <String[]>]
[-MetricName] <String[]>
[-DetailedOutput]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
The Get-AzMetric cmdlet gets the metric values for a specified resource.
Examples
Example 1: Get a metric with summarized output
Get-AzMetric -ResourceId "/subscriptions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/website3" -TimeGrain 00:01:00
Id : /subscriptions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/website3/providers/Microsoft.Insights/metrics/Requests
Name :
LocalizedValue : Requests
Value : Requests
Type : Microsoft.Insights/metrics
Unit : Count
Data : {Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue, Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue,
Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue, Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue…}
Timeseries : {Microsoft.Azure.Management.Monitor.Models.TimeSeriesElement}
This command gets the metric values for website3 with a time grain of 1 minute.
Example 2: Get a metric with detailed output
Get-AzMetric -ResourceId "/subscriptions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/website3" -TimeGrain 00:01:00 -DetailedOutput
Id : /subscriptions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/website3/providers/Microsoft.Insights/metrics/Requests
Name : Microsoft.Azure.Management.Monitor.Models.LocalizableString
Type : Microsoft.Insights/metrics
Unit : Count
Data : {Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue, Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue,
Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue, Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue…}
Timeseries : {Microsoft.Azure.Management.Monitor.Models.TimeSeriesElement}
This command gets the metric values for website3 with a time grain of 1 minute. The output is detailed.
Example 3: Get a specified metric
Get-AzMetric -ResourceId "/subscriptions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/website3" -MetricName "Requests" -TimeGrain 00:01:00
Id : /subscriptions/a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/website3/providers/Microsoft.Insights/metrics/Requests
Name :
LocalizedValue : Requests
Value : Requests
Type : Microsoft.Insights/metrics
Unit : Count
Data : {Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue, Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue,
Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue, Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue…}
Timeseries : {Microsoft.Azure.Management.Monitor.Models.TimeSeriesElement}
This command gets detailed output for the Requests metric.
Example 4: Get summarized output for a specified metric with specified dimension filter
$dimFilter = "$(New-AzMetricFilter -Dimension City -Operator eq -Value "Seattle","Toronto") and $(New-AzMetricFilter -Dimension AuthenticationType -Operator eq -Value User)"
Get-AzMetric -ResourceId <ResourceId> -MetricName availabilityResults/availabilityPercentage -TimeGrain 00:05:00 -MetricFilter $dimFilter -StartTime 2024-07-02T00:00:00Z -EndTime 2024-07-02T00:10:00Z -AggregationType Average
Id : [ResourceId]/providers/Microsoft.Insights/metrics/availabilityResults/availabilityPercentage
Name :
LocalizedValue : Availability
Value : availabilityResults/availabilityPercentage
Type : Microsoft.Insights/metrics
Unit : Percent
Data :
Timeseries : {}
This command gets summarized output for the PageViews metric with specified dimension filter and aggregation type.
Parameters
-AggregationType
The aggregation type of the query
Type: | Nullable<T>[AggregationType] |
Accepted values: | None, Average, Count, Minimum, Maximum, Total |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.
Type: | IAzureContextContainer |
Aliases: | AzContext, AzureRmContext, AzureCredential |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-DetailedOutput
Indicates that this cmdlet displays detailed output. By default, output is summarized.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Dimension
The metric dimensions to query metrics for
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-EndTime
Specifies the end time of the query in local time. The default is the current time.
Type: | DateTime |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-MetricFilter
Specifies the metric dimension filter to query metrics for.
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-MetricName
Specifies an array of names of metrics.
Type: | String[] |
Aliases: | MetricNames |
Position: | 1 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-MetricNamespace
Specifies the metric namespace to query metrics for.
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-OrderBy
Specifies the aggregation to use for sorting results and the direction of the sort (Example: sum asc).
Type: | String |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-ResourceId
Specifies the resource ID of the metric.
Type: | String |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-ResultType
Specifies the result type to be returned (metadata or data).
Type: | Nullable<T>[ResultType] |
Accepted values: | Data, Metadata |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-StartTime
Specifies the start time of the query in local time. The default is the current local time minus one hour.
Type: | DateTime |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-TimeGrain
Specifies the time grain of the metric as a TimeSpan object in the format hh:mm:ss.
Type: | TimeSpan |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Top
Specifies the maximum number of records to retrieve (default:10), to be specified with $filter.
Type: | Nullable<T>[Int32] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Inputs
Nullable<T>[[Microsoft.Azure.Management.Monitor.Models.AggregationType, Microsoft.Azure.Management.Monitor, Version=0.21.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]
Nullable<T>[[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]
Nullable<T>[[Microsoft.Azure.Management.Monitor.Models.ResultType, Microsoft.Azure.Management.Monitor, Version=0.21.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]
String[]
Outputs
Notes
More information about the supported metrics may be found at: https://zcusa.951200.xyz/azure/azure-monitor/platform/metrics-supported