共用方式為


Get-AzMetric

取得資源的計量值。

語法

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

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}

此命令會取得 website3 的計量值,其時間粒紋為 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}

此命令會取得 website3 的計量值,其時間粒紋為 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 availabilityResult/location -Operator eq -Value "Seattle","Toronto"

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>[AggregationType]
接受的值:None, Average, Count, Minimum, Maximum, Total
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-DefaultProfile

用於與 azure 通訊的認證、帳戶、租用戶和訂用帳戶。

類型:IAzureContextContainer
別名:AzContext, AzureRmContext, AzureCredential
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-DetailedOutput

指出此 Cmdlet 會顯示詳細的輸出。 根據預設,輸出會摘要說明。

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-Dimension

要查詢計量的計量維度

類型:String[]
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-EndTime

指定當地時間查詢的結束時間。 預設值為目前時間。

類型:DateTime
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-MetricFilter

指定要查詢計量的計量維度篩選。

類型:String
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-MetricName

指定計量名稱的陣列。

類型:String[]
別名:MetricNames
Position:1
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-MetricNamespace

指定要查詢計量的計量命名空間。

類型:String
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-OrderBy

指定要用於排序結果和排序方向的匯總(範例:sum asc)。

類型:String
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-ResourceId

指定計量的資源識別碼。

類型:String
Position:0
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-ResultType

指定要傳回的結果類型(元數據或數據)。

類型:Nullable<T>[ResultType]
接受的值:Data, Metadata
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-StartTime

指定當地時間查詢的開始時間。 預設值為目前的本地時間減去一小時。

類型:DateTime
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-TimeGrain

以 hh:mm:ss 格式指定計量的時間粒紋做為 TimeSpan 物件。

類型:TimeSpan
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

-Top

指定要擷取的記錄數目上限(預設值:10),以$filter指定。

類型:Nullable<T>[Int32]
Position:Named
預設值:None
必要:False
接受管線輸入:True
接受萬用字元:False

輸入

String

TimeSpan

Nullable<T>[[Microsoft.Azure.Management.Monitor.Models.AggregationType, Microsoft.Azure.Management.Monitor, Version=0.21.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]

DateTime

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[]

SwitchParameter

輸出

PSMetric

備註

如需所支援計量的詳細資訊,請參閱: https://learn.microsoft.com/azure/azure-monitor/platform/metrics-supported