简体   繁体   English

如何使用 azure 资源图获取 Azure VM 最后一次重启

[英]how to get Azure VM last reboot using azure resource graph

I'm using azure resource graph to create dashboard and need the VM last reboot or Power-Off date.我正在使用 azure 资源图来创建仪表板并需要 VM 上次重启或关机日期。 Need your helps please.请需要你的帮助。 Thank you谢谢

I tried to reproduce the same in my environment:我试图在我的环境中重现相同的内容:

Graph query:图查询:

Resources
| where type == 'microsoft.compute/virtualmachines'
| summarize count() by PowerState = tostring(properties.extended.instanceView.powerState.code)

Checked the powerstate:检查电源状态: 在此处输入图像描述

Tried below query:尝试以下查询:

resources
| where type has 'microsoft.compute/virtualmachines/extensions' 
| where name has 'MicrosoftMonitoringAgent' or name has 'AzureMonitorWindowsAgent' 
| extend AzureVM = extract('virtualMachines/(.*)/extensions',1,id), ArcVM = extract('machines/(.*)/extensions',1,id)
|summarize count() by name=tolower(AzureVM), ArcVM=tolower(ArcVM), subscriptionId, resourceGroup,  AgentType=name
| extend hasBoth = iff(count_ > 0, 'Yes', 'No') 
| join 
 ( 
    resources
    | where type =~ 'Microsoft.Compute/virtualMachines'
    | project name, properties.extended.instanceView.powerState.displayStatus,
                    properties.extended.instanceView.powerState.code,
                    created_ = properties.timeCreated
    | order by name desc
 ) on name

where i got created time of azure vm running and deallocation time.我在哪里创建了 azure 虚拟机运行时间和释放时间。

在此处输入图像描述

If you want the alert when the vm stpped you can check this: azureportal - Azure alert to notify when a vm is stopped - Stack Overflow如果你想在虚拟机停止时发出警报,你可以检查这个: azureportal - Azure 警报在虚拟机停止时通知 - 堆栈内存溢出

Reference: resource-graph-samples |参考资料: 资源图示例 | Microsoft Learn 微软学习

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

相关问题 如何将 Azure VM 重新启动和关闭日志获取到 Azure Log Analytics 中? - How to get Azure VM reboot and shutdown logs into Azure Log Analytics? Azure使用Azure资源图计算VMSS中的所有VM - Azure count all VM's in VMSS using Azure Resource Graph Powershell 脚本列出 Azure 订阅下 vm 的上次重新启动 - Powershell script to list last reboot of vm's under a Azure Subscription 使用REST获取资源消耗详细信息和Azure VM的成本 - Get resource consumption details and costing of Azure VM using REST 使用资源管理器部署和Rest API获取Azure VM - Get Azure VM using resource manager deployment and rest api 如何从 Azure 资源图中的 JSON 数组 object(示例 VM 数据磁盘)动态获取所有嵌套属性 - How to dynamically get all nested properties from JSON Array object (example VM data disks) in Azure resource graph 如何从 powershell 脚本重新启动 azure vm 并继续其余步骤 - How to reboot a azure vm from powershell script and continue the remaining steps 使用 Azure Resource Graph 获取其他用户的资源 - Using Azure Resource Graph to get other user's Resources 如何在资源组中备份Azure VM? - How to backup Azure VM in Resource Group? 如何获取 azure VM 的 azure VMUUID? - How to get the azure VMUUID of azure VM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM