共用方式為


Azure Monitor REST API 篩選器語法

許多 Azure Monitor API 採用一個參數 , {filter-expression}可用於篩選或約束收集的數據集。

在請求多個資源時使用篩檢程式“*”

這很重要

*多個資源的篩檢程式不是通配符。 它是一個用於請求多個資源的文字字串。 用於 * 請求單個時間序列中的多個資源。

在下面的 $filter=Microsoft.ResourceId eq '*' 示例中,指示 API 在訂閱和區域中為每個虛擬機資源返回單獨的時序。 如果沒有篩選條件,API 會傳回匯總所有 VM 的平均 CPU 的單一時間序列。 每個資源的時序由每個時序條目的 Microsoft.ResourceId 元數據值區分。

如果使用 $filter=Microsoft.ResourceId eq '*' 且沒有資源(在本例中為指定時序中的虛擬機),則返回空時序 timeseries:[] ,因為請求的維度集沒有結果,其中包括 ResourceId
沒有篩選器的同一查詢將返回單個時序,該時序返回所有 VM 的聚合平均 CPU = 0 ,因為這是所有請求維度的總和。

GET https://management.azure.com/subscriptions/12345678-abcd-98765432-abcdef012345/providers/microsoft.Insights/metrics?timespan=2023-06-25T22:20:00.000Z/2023-06-26T22:25:00.000Z&interval=PT5M&metricnames=Percentage CPU&aggregation=average&api-version=2021-05-01&region=eastus&metricNamespace=microsoft.compute/virtualmachines&$filter=Microsoft.ResourceId eq '*'

使用範例 $filter

以下是您可以作為 傳遞的 {filter-expression}可能表達式字串。 不允許使用其他語法。

  • 列出資源組的事件

    $filter=eventTimestamp ge <Start Time> and eventTimestamp le <End Time> and eventChannels eq 'Admin, Operation' and resourceGroupName eq '<ResourceGroupName>'
    

    範例

    $filter=eventTimestamp ge 2014-12-29T22:00:37Z 和 eventTimestamp le 2014-12-29T23:36:37Z 和 eventChannels eq 'Admin, Operation' 和 resourceGroupName eq 'CloudLab'

  • 列出資源的事件

    $filter=eventTimestamp ge <Start Time> and eventTimestamp le <End Time> and eventChannels eq 'Admin, Operation' and resourceUri eq '<ResourceURI>'
    

    範例

    $filter=eventTimestamp ge 2014-12-29T22:00:37Z 和 eventTimestamp le 2014-12-29T23:36:37Z 和 eventChannels eq 'Admin, Operation' 和 resourceUri eq '/subscriptions/089bd33f-d4ec-47fe-8ba5-0753aa5c5b33/resourcegroups/CloudLab/providers/Microsoft.Web/sites/mytestweb004'

  • 列出 Azure 訂閱的事件

    $filter=eventTimestamp ge <Start Time> and eventTimestamp le <End Time> and eventChannels eq 'Admin, Operation'
    

    範例

    $filter=eventTimestamp ge 2014-12-29T22:00:37Z 和 eventTimestamp le 2014-12-29T23:36:37Z 和 eventChannels eq 'Admin, Operation'

  • 列出 Azure 資源提供程式的事件

    $filter=eventTimestamp ge <Start Time> and eventTimestamp le <End Time> and eventChannels eq 'Admin, Operation' and resourceProvider eq '<ResourceProviderName>'
    

    範例

    $filter=eventTimestamp ge 2014-12-29T22:00:37Z 和 eventTimestamp le 2014-12-29T23:36:37Z 和 eventChannels eq 'Admin, Operation' 和 resourceProvider eq 'Microsoft.Web'

  • 列出相關ID的事件

    api-version=2014-04-01&$filter=eventTimestamp ge 2014-07-16T04:36:37.6407898Z and eventTimestamp le 2014-07-20T04:36:37.6407898Z and eventChannels eq 'Admin, Operation' and correlationId eq '<CorrelationID>'
    

    示例:api-version=2014-04-01&$filter=eventTimestamp ge 2014-12-29T22:00:37Z 和 eventTimestamp le 2014-12-29T23:36:37Z 和 eventChannels eq 'Admin, Operation' 和 correlationId eq '07c85493-5e87-4efd-9200-0c64d904d878'