简体   繁体   English

KQL 查询以获取 VMSS 中的实例数

[英]KQL Query to get number of instances in VMSS

I'm trying to create a query that gives me the number of instances running in Azure from scale sets.我正在尝试创建一个查询,该查询为我提供了规模集中在 Azure 中运行的实例数。

I need to configure an alert for monitoring when the number of instances drops below 2 VMs.当实例数量低于 2 个虚拟机时,我需要配置一个警报以进行监控。 Unless anyone knows how to monitor VM Scale sets, how do you track heartbeat when you have VMs scaling up and down.除非有人知道如何监控 VM 规模集,否则当 VM 向上和向下扩展时如何跟踪心跳。

I have tried in Resource Graph Explorer and they're available under:我已经在 Resource Graph Explorer 中尝试过,它们可以在以下位置找到:

Resources
    | where type =~ 'Microsoft.Compute/virtualMachineScaleSets'
    | where name contains "-conto"
    | join kind=inner (ResourceContainers | where type=='microsoft.resources/subscriptions' | project SubName=name, subscriptionId) on subscriptionId
    | project VMMSName = name, RGName = resourceGroup, VMMSSKU = sku.name, VMMSCount = sku.capacity, SubName, SubID = subscriptionId

But I can't use the same query in Log analytics.但我不能在日志分析中使用相同的查询。 When I do a query in log anaytics, which has the option to create an alert I don't get numbe rof instances, and I need to have a way to monitor the VMs.当我在 log anaytics 中进行查询时,它可以选择创建警报,但我没有得到 numbe rof 实例,我需要有一种方法来监视 VM。

Heartbeat
| where ResourceType contains "virtualmachinescaleset"

Any help would be greatly appreciated.任何帮助将不胜感激。 Thanks in advance.提前致谢。

As of now as per the MSDOC we don't have any metrics to get the no.截至目前,根据MSDOC ,我们没有任何指标来获得否决 of VM Scale set instances down/up . VM Scale set 实例 down/up

We can get the VM Scale Sets Performance metrics like (CPU/Disk/Memory/etc.,)我们可以获得 VM Scale Sets 性能指标,例如(CPU/Disk/Memory/etc.)

Refer here for more information请参阅此处了解更多信息

Thanks @ hey for the workaround which you have provided.感谢@hey您提供的解决方法。

Workaround:解决方法:

Install the Azure Monitor Agent in your all VM Scale Set.在您的所有 VM 规模集中安装Azure 监控代理

Azure Monitor Agent will send the heartbeat by default. Azure Monitor Agent 默认会发送心跳 It will be added in an Azure Monitor .它将被添加到Azure Monitor中。

Query to get no of VM Scale Set instances from heartbeats.查询以从检测信号中获取 VM 规模集实例的数量。

 InsightsMetrics | where Namespace == "Computer" | where Origin =="vm.azm.ms/map" | where Name == "Heartbeat" | summarize Hb_count = count() by bin(TimeGenerated, 10m), Computer | extend alive=iff(Hb_count > 2, 1.0, 0.0) //computer considered "down" if it has 2 or fewer heartbeats in 10 min interval | where alive == true | project TimeGenerated, alive, Computer | summarize Hb_alive_count = count() by bin(TimeGenerated, 10m), alive | project TimeGenerated, Hb_alive_count | render timechart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM