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

Azure Monitor REST API 筛选器语法

许多 Azure Monitor API 采用参数 {filter-expression},可用于筛选或约束收集的数据集。

在请求多个资源中使用筛选器“*”

重要

*多个资源的筛选器中的 不是通配符。 它是用于请求多个资源的文本字符串。 *用于请求单个时序中的多个资源。

在下面的示例 $filter=Microsoft.ResourceId eq '*' 中,告知 API 在订阅和区域中为每个虚拟机资源返回单独的时序。 如果没有筛选器,API 将会返回聚合了所有 VM 的平均 CPU 的单个时序。 每个资源的时间序列由每个时序条目上的 Microsoft.ResourceId 元数据值进行区分。

如果使用 $filter=Microsoft.ResourceId eq '*' 并且没有资源,则在本例中,指定时序中的 VM 将返回空时间序列 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 '管理员, Operation' and 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 and eventTimestamp le 2014-12-29T23:36:37Z and eventChannels eq '管理员, 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 '管理员, 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 '管理员, Operation' and 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 '管理员, Operation“和 correlationId eq '07c85493-5e87-4efd-9200-0c64d904d878'