共用方式為


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

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}

此命令會取得 Requests 指標的詳細輸出。

範例 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
別名:指標名稱

參數集

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

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

參數屬性

類型:

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