针对已启用 Azure Arc 的服务器的 Azure Resource Graph 示例查询
此页面是针对已启用 Azure Arc 的服务器的 Azure Resource Graph 示例查询的集合。
示例查询
按域获取已启用 Arc 的服务器的计数和百分比
此查询汇总已启用 Azure Arc 的服务器上的 domainName
属性,并使用含 bin
的计算创建一个 Pct
列,来表示每个域中已启用 Arc 的服务器的百分比。
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)
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
另一个属性的好方法。 然后,此查询使用将 kind
作为 leftouter
的 join
,通过匹配扩展 ID 的大写 substring
来获取扩展。 /extensions/<ExtensionName>
之前的 ID 部分与混合计算机 ID 的格式相同,因此我们将此属性用于 join
。 然后会针对虚拟机扩展的名称将 summarize
用于 make_list
以合并每个扩展的名称,其中 ID、OSName 和 ComputerName 在单个数组属性中是相同的。 最后,我们使用 asc
按小写 OSName 进行排序。 默认情况下,order 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
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 的服务器
此查询返回所有运行 Connected Machine 代理过时版本且已启用 Arc 的服务器。 结果中不包含状态为“已过期”的代理。 该查询使用 leftouter
join
将顾问提出的关于任何已确定为过时的 Connected Machine 代理的建议和混合计算机组合在一起,以筛选出一段时间内未与 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
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"