Azure Monitor 日志查询中的 resource() 表达式resource() expression in Azure Monitor log query

resource 表达式在范围限定为资源的 Azure Monitor 查询中使用,可以从其他资源检索数据。The resource expression is used in a Azure Monitor query scoped to a resource to retrieve data from other resources.

语法Syntax

resource(标识符)resource(Identifier)

参数Arguments

  • 标识符:资源的资源 ID。Identifier: Resource ID of a resource.
标识符Identifier 说明Description 示例Example
资源Resource 包括资源的数据。Includes data for the resource. resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup/providers/microsoft.compute/virtualmachines/myvm")resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup/providers/microsoft.compute/virtualmachines/myvm")
资源组或订阅Resource Group or Subscription 包括资源及其包含的所有资源的数据。Includes data for the resource and all resources that it contains. resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup)resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup)

注释Notes

  • 你必须具有该资源的读取访问权限。You must have read access to the resource.

示例Examples

union (Heartbeat),(resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup/providers/microsoft.compute/virtualmachines/myvm").Heartbeat) | summarize count() by _ResourceId, TenantId
union (Heartbeat),(resource("/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcesgroups/myresourcegroup).Heartbeat) | summarize count() by _ResourceId, TenantId

后续步骤Next steps