Azure系列 介绍关于Azure的理念概述并包涵操作与资源等 (适用于启用 Azure Arc 的服务器的 Azure 资源图示例查询)

Azure 资源图是一项 Azure 服务,可让您大规模查询,从而帮助您有效地管理环境。查询使用 Kusto 查询语言 (KQL) 创建。有关详细信息,请参阅了解 Azure 资源图查询语言

本页面提供了适用于已启用 Azure Arc 的服务器的 Azure 资源图查询示例列表。您可以通过 Azure PowerShell 或 Azure CLI 运行这些查询,也可以在 Azure 门户中使用资源图资源管理器运行。您可以根据需要修改这些查询。

 提示

您可以使用 Azure 中的 Microsoft Copilot,以自然语言编写 Azure 资源图查询。有关详细信息,请参阅在 Azure 中使用 Microsoft Copilot 获取资源信息

示例查询

按域获取启用 Arc 的服务器数量和百分比

此查询汇总了Azure Arc 启用服务器domainName的属性,并使用计算创建了一列,用于显示每个域中启用 Arc 的服务器的百分比。binPct

库斯托
Resources
| where type == 'microsoft.hybridcompute/machines'
| project domain=tostring(properties.domainName)
| summarize Domains=make_list(domain), TotalMachineCount=sum(1)
| mvexpand EachDomain = Domains
| summarize PerDomainMachineCount = count() by tostring(EachDomain), TotalMachineCount
| extend Pct = 100 * bin(todouble(PerDomainMachineCount) / todouble(TotalMachineCount), 0.001)
  • Azure CLI
  • Azure PowerShell
  • 门户网站
Azure CLI
az graph query -q "Resources | where type == 'microsoft.hybridcompute/machines' | project domain=tostring(properties.domainName) | summarize Domains=make_list(domain), TotalMachineCount=sum(1) | mvexpand EachDomain = Domains | summarize PerDomainMachineCount = count() by tostring(EachDomain), TotalMachineCount | extend Pct = 100 * bin(todouble(PerDomainMachineCount) / todouble(TotalMachineCount), 0.001)"

列出 Azure Arc 服务器上安装的所有扩展程序

首先,此查询使用project混合机器资源类型获取大写的 ID toupper(),获取计算机名称以及机器上运行的操作系统。获取大写的资源 ID 有助于为join后续属性的获取做好准备。然后,查询使用join`with kindas`leftouter来获取substring扩展 ID 的大写部分。ID 的前半部分/extensions/与混合机器 ID 的格式相同,因此我们使用此属性joinsummarize接下来,使用 `with as` 来获取虚拟机扩展的名称,将ID操作系统名称计算机名称相同的make_list扩展名称合并到一个数组属性中。最后,我们使用 `order` 按小写的操作系统名称排序。默认情况下,排序方式为降序。ascorder by

库斯托
Resources
| where type == 'microsoft.hybridcompute/machines'
| project
  id,
  JoinID = toupper(id),
  ComputerName = tostring(properties.osProfile.computerName),
  OSName = tostring(properties.osName)
| join kind=leftouter(
  Resources
  | where type == 'microsoft.hybridcompute/machines/extensions'
  | project
    MachineId = toupper(substring(id, 0, indexof(id, '/extensions'))),
    ExtensionName = name
) on $left.JoinID == $right.MachineId
| summarize Extensions = make_list(ExtensionName) by id, ComputerName, OSName
| order by tolower(OSName) asc
  • Azure CLI
  • Azure PowerShell
  • 门户网站
Azure CLI
az graph query -q "Resources | where type == 'microsoft.hybridcompute/machines' | project id, JoinID = toupper(id), ComputerName = tostring(properties.osProfile.computerName), OSName = tostring(properties.osName) | join kind=leftouter( Resources | where type == 'microsoft.hybridcompute/machines/extensions' | project  MachineId = toupper(substring(id, 0, indexof(id, '/extensions'))),  ExtensionName = name ) on \$left.JoinID == \$right.MachineId | summarize Extensions = make_list(ExtensionName) by id, ComputerName, OSName | order by tolower(OSName) asc"

列出未运行最新发布代理版本的启用 Arc 的服务器

此查询返回所有运行过时版本的连接计算机代理的启用 Arc 的服务器。状态为“已过期”的代理将从结果中排除。该查询会leftouter join汇总针对任何被识别为过时的连接计算机代理的 Advisor 建议,并筛选出一段时间内未与 Azure 通信的任何代理。

库斯托
AdvisorResources
| where type == 'microsoft.advisor/recommendations'
| where properties.category == 'HighAvailability'
| where properties.shortDescription.solution == 'Upgrade to the latest version of the Azure Connected Machine agent'
| project
    id,
    JoinId = toupper(properties.resourceMetadata.resourceId),
    machineName = tostring(properties.impactedValue),
    agentVersion = tostring(properties.extendedProperties.installedVersion),
    expectedVersion = tostring(properties.extendedProperties.latestVersion)
| join kind=leftouter(
  Resources
  | where type == 'microsoft.hybridcompute/machines'
  | project
    machineId = toupper(id),
    status = tostring (properties.status)
  ) on $left.JoinId == $right.machineId
| where status != 'Expired'
| summarize by id, machineName, agentVersion, expectedVersion
| order by tolower(machineName) asc
  • Azure CLI
  • Azure PowerShell
  • 门户网站
Azure CLI
az graph query -q "AdvisorResources | where type == 'microsoft.advisor/recommendations' | where properties.category == 'HighAvailability' | where properties.shortDescription.solution == 'Upgrade to the latest version of the Azure Connected Machine agent' | project  id,  JoinId = toupper(properties.resourceMetadata.resourceId),  machineName = tostring(properties.impactedValue),  agentVersion = tostring(properties.extendedProperties.installedVersion),  expectedVersion = tostring(properties.extendedProperties.latestVersion) | join kind=leftouter( Resources | where type == 'microsoft.hybridcompute/machines' | project  machineId = toupper(id),  status = tostring (properties.status) ) on \$left.JoinId == \$right.machineId | where status != 'Expired' | summarize by id, machineName, agentVersion, expectedVersion | order by tolower(machineName) asc"

列出已安装 SQL Server、PostgreSQL 或 MySQL 的启用 Arc 的服务器

此查询返回所有已安装 SQL Server、PostgreSQL 或 MySQL 的 Arc 服务器。

库斯托
resources
| where type =~ 'microsoft.hybridcompute/machines'
| extend machineId = tolower(tostring(id)), datacenter = iif(isnull(tags.Datacenter), '', tags.Datacenter), status = tostring(properties.status)
| extend mssqlinstalled = coalesce(tobool(properties.detectedProperties.mssqldiscovered),false)
| extend pgsqlinstalled = coalesce(tobool(properties.detectedProperties.pgsqldiscovered),false)
| extend mysqlinstalled = coalesce(tobool(properties.detectedProperties.mysqldiscovered),false)
| extend osSku = properties.osSku, osName = properties.osName, osVersion = properties.osVersion
| extend coreCount = tostring(properties.detectedProperties.logicalCoreCount), totalPhysicalMemoryinGB = tostring(properties.detectedProperties.totalPhysicalMemoryInGigabytes) 
| extend operatingSystem = iif(isnotnull(osSku), osSku, osName)
| where mssqlinstalled or mysqlinstalled or pgsqlinstalled
| project id ,name, type, resourceGroup, subscriptionId, location, kind, osVersion, status, osSku,coreCount,totalPhysicalMemoryinGB,tags, mssqlinstalled, mysqlinstalled, pgsqlinstalled
| sort by (tolower(tostring(name))) asc
  • Azure CLI
  • Azure PowerShell
  • 门户网站
Azure CLI
az graph query -q "resources | where type =~ 'microsoft.hybridcompute/mac
评论