Microsoft Azure – 跨订阅范围内的 VM CPU 利用率
在这里,在本文中,我们将在 Azure 订阅中查找 Azure 虚拟机,其中平均 CPU 利用率在范围内,并仅按降序或升序显示订阅中使用率最高或未充分利用的虚拟机的结果。
通过使用以下 KQL 查询,您可以使用 Azure Monitor 日志获取 azure 数据源结果。在 Azure Monitor 日志或 Log Analytics 工作区或 Azure 工作簿中运行以下查询以获取结果。
注意:在执行将订阅 ID 和订阅名称替换为您的活动 Azure 订阅 ID 和订阅名称之前。
1.平均 CPU 使用率介于 (Value .. Value) 之间的排名靠前的 VM(按降序排列):
KQL 日志查询:
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time"
and InstanceName == "_Total"
//Replace Subscription Id values with our Azure Subscription Ids
//You can add or remove additions according to your requirement
| where _SubscriptionId == "68xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 1
_SubscriptionId == "61xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 2
_SubscriptionId == "74xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 3
_SubscriptionId == "6cxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 4
_SubscriptionId == "acxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" //Subscription 5
//Replace your Subscription Id's and Subscription Names
//You can add or remove additions according to your requirement
| extend AzureSubscriptionName =case(
_SubscriptionId =~ '68xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 1',
_SubscriptionId =~ '61xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 2',
_SubscriptionId =~ '74xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 3',
_SubscriptionId =~ '6cxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 4',
_SubscriptionId =~ 'axxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 5',
_SubscriptionId)
| summarize AVG_CPU = round(avg(CounterValue), 3) by bin(TimeGenerated, 30d), Computer, AzureSubscriptionName
| where AVG_CPU between ( 15 .. 50 )
| top 10 by AVG_CPU desc
此查询将返回平均 CPU 利用率在 15 到 50 之间的前 10 台 Azure 虚拟机,按降序排列,其中包含 Table Time Generated、Azure VM Name 和 Azure Subscription Name。
输出:
2.最大 CPU 利用率范围在 (Value .. Value) 之间的最高 VM(按降序排列):
KQL 日志查询:
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time"
and InstanceName == "_Total"
//Replace Subscription Id values with our Azure Subscription Ids
//You can add or remove additions according to your requirement
| where _SubscriptionId == "68xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 1
_SubscriptionId == "61xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 2
_SubscriptionId == "74xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 3
_SubscriptionId == "6cxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 4
_SubscriptionId == "acxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" //Subscription 5
//Replace your Subscription Id's and Subscription Names
//You can add or remove additions according to your requirement
| extend AzureSubscriptionName =case(
_SubscriptionId =~ '68xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 1',
_SubscriptionId =~ '61xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 2',
_SubscriptionId =~ '74xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 3',
_SubscriptionId =~ '6cxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 4',
_SubscriptionId =~ 'axxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 5',
_SubscriptionId)
| summarize MAX_CPU = round(max(CounterValue), 3) by bin(TimeGenerated, 30d), Computer, AzureSubscriptionName
| where MAX_CPU between ( 50 .. 99)
| top 10 by MAX_CPU desc
此查询将返回最大 CPU 利用率范围在 50 到 100 之间的前 10 个 Azure 虚拟机,按降序排列,其中包含 Table Time Generated、Azure VM Name 和 Azure Subscription Name。
输出:
3.最大 CPU 利用率范围在 (Value .. Value) 之间的最高 VM(按升序排列):
KQL 日志查询:
Perf
| where ObjectName == "Processor" and CounterName == "% Processor Time"
and InstanceName == "_Total"
//Replace Subscription Id values with our Azure Subscription Ids
//You can add or remove additions according to your requirement
| where _SubscriptionId == "68xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 1
_SubscriptionId == "61xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 2
_SubscriptionId == "74xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 3
_SubscriptionId == "6cxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or //Subscription 4
_SubscriptionId == "acxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" //Subscription 5
//Replace your Subscription Id's and Subscription Names
//You can add or remove additions according to your requirement
| extend AzureSubscriptionName =case(
_SubscriptionId =~ '68xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 1',
_SubscriptionId =~ '61xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 2',
_SubscriptionId =~ '74xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 3',
_SubscriptionId =~ '6cxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 4',
_SubscriptionId =~ 'axxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'Subscription 5',
_SubscriptionId)
| summarize MIN_CPU = round(min(CounterValue), 3) by bin(TimeGenerated, 30d), Computer, AzureSubscriptionName
| where MIN_CPU between ( 10 .. 20)
| top 10 by MIN_CPU asc
此查询将返回前 10 个 Azure 虚拟机,其中最低 CPU 使用率范围在 10 到 20 之间,按升序排列,其中包含生成的表时间、Azure VM 名称和 Azure 订阅名称。
输出:
注意:尝试使用您自己的订阅名称和 ID。