你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Get-AzMetric

获取资源的指标值。

语法

GetWithDefaultParameters (默认值)

Get-AzMetric
    [-ResourceId] <String>
    [[-MetricName] <String[]>]
    [-TimeGrain <TimeSpan>]
    [-StartTime <DateTime>]
    [-EndTime <DateTime>]
    [-MetricFilter <String>]
    [-Dimension <String[]>]
    [-DetailedOutput]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

GetWithFullParameters

Get-AzMetric
    [-ResourceId] <String>
    [-MetricName] <String[]>
    [-TimeGrain <TimeSpan>]
    [-AggregationType <AggregationType>]
    [-StartTime <DateTime>]
    [-EndTime <DateTime>]
    [-Top <Int32>]
    [-OrderBy <String>]
    [-MetricNamespace <String>]
    [-ResultType <ResultType>]
    [-MetricFilter <String>]
    [-Dimension <String[]>]
    [-DetailedOutput]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

说明

Get-AzMetric cmdlet 获取指定资源的指标值。

示例

示例 1:获取包含汇总输出的指标

Get-AzMetric -ResourceId "/subscriptions/e3f5b07d-3c39-4b0f-bf3b-40fdeba10f2a/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/website3" -TimeGrain 00:01:00
Id         : /subscriptions/e3f5b07d-3c39-4b0f-bf3b-40fdeba10f2a/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}

此命令获取网站 3 的指标值,时间粒度为 1 分钟。

示例 2:获取包含详细输出的指标

Get-AzMetric -ResourceId "/subscriptions/e3f5b07d-3c39-4b0f-bf3b-40fdeba10f2a/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/website3" -TimeGrain 00:01:00 -DetailedOutput
Id         : /subscriptions/e3f5b07d-3c39-4b0f-bf3b-40fdeba10f2a/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}

此命令获取网站 3 的指标值,时间粒度为 1 分钟。 输出是详细的。

示例 3:获取指定的指标

Get-AzMetric -ResourceId "/subscriptions/e3f5b07d-3c39-4b0f-bf3b-40fdeba10f2a/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/website3" -MetricName "Requests" -TimeGrain 00:01:00
Id         : /subscriptions/e3f5b07d-3c39-4b0f-bf3b-40fdeba10f2a/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}

此命令获取请求指标的详细输出。

示例 4:获取具有指定维度筛选器的指定指标的汇总输出

$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 : {}

此命令获取具有指定维度筛选器和聚合类型的 PageViews 指标的汇总输出。

参数

-AggregationType

查询的聚合类型

参数属性

类型:

Nullable<T>[Microsoft.Azure.Management.Monitor.Models.AggregationType]

默认值:None
接受的值:None, Average, Count, Minimum, Maximum, Total
支持通配符:False
不显示:False

参数集

GetWithFullParameters
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-DefaultProfile

用于与 Azure 通信的凭据、帐户、租户和订阅。

参数属性

类型:IAzureContextContainer
默认值:None
支持通配符:False
不显示:False
别名:AzContext, AzureRmContext, AzureCredential

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-DetailedOutput

指示此 cmdlet 显示详细的输出。 默认情况下,输出汇总。

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Dimension

要查询其指标的指标维度

参数属性

类型:

String[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-EndTime

指定本地时间查询的结束时间。 默认值为当前时间。

参数属性

类型:DateTime
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MetricFilter

指定要查询指标的指标维度筛选器。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MetricName

指定指标名称的数组。

参数属性

类型:

String[]

默认值:None
支持通配符:False
不显示:False
别名:MetricNames

参数集

GetWithDefaultParameters
Position:1
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-MetricNamespace

指定要查询指标的指标命名空间。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

GetWithFullParameters
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-OrderBy

指定要用于排序结果和排序方向的聚合(示例:sum asc)。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

GetWithFullParameters
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ResourceId

指定指标的资源 ID。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:0
必需:True
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ResultType

指定要返回的结果类型(元数据或数据)。

参数属性

类型:

Nullable<T>[Microsoft.Azure.Management.Monitor.Models.ResultType]

默认值:None
接受的值:Data, Metadata
支持通配符:False
不显示:False

参数集

GetWithFullParameters
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-StartTime

指定本地时间查询的开始时间。 默认值为当前本地时间减去一小时。

参数属性

类型:DateTime
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-TimeGrain

以 hh:mm:ss 格式指定指标的时间粒度作为 TimeSpan 对象。

参数属性

类型:TimeSpan
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-Top

指定要使用$filter指定的最大检索记录数(default:10)。

参数属性

类型:

Nullable<T>[Int32]

默认值:None
支持通配符:False
不显示:False

参数集

GetWithFullParameters
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

CommonParameters

此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters

输入

String

TimeSpan

Nullable<T>

DateTime

Nullable<T>

Nullable<T>

String

SwitchParameter

输出

PSMetric

备注

有关支持的指标的详细信息,请参阅: https://learn.microsoft.com/azure/azure-monitor/platform/metrics-supported