问题描述
我有一台虚拟机。现在我想如果我的磁盘空间显示非常低我的意思是小于 2 GB。然后我想触发 azure 监视器警报并希望收到有关此的电子邮件。是否有任何指标 azure 监视器提供。
解决方法
截至目前,没有针对磁盘空间的预定义警报。但您可以使用自定义日志搜索创建新警报以获取详细信息,然后触发向您发送电子邮件。
第 1 步:转到监控页面上的警报,然后点击新建警报规则。
第 2 步:然后选择资源,并在此处按资源选择您已启用 VM 监控的日志分析工作区。就我而言,它是 TestLog。
第 3 步:现在选择自定义日志搜索。
第 4 步:然后在搜索查询框中提供我在下面提供的自定义查询,您可以根据您的要求将阈值设置为“0”以及以分钟为单位的周期和频率例如,我将其设置为 60 分钟。
第 5 步:现在选择一个现有的操作组,或者您可以通过点击新建并填写详细信息来创建一个新的操作组。创建后,单击操作组并将通知类型添加为电子邮件或您要指定的任何内容。
第 6 步:填写其余详细信息,例如电子邮件主题和要设置的警报的严重性,然后创建警报。
自定义查询:
let setgbvalue = 200;//Set the disk space you want to check for.
Perf
| where TimeGenerated > ago(1h)
| where ObjectName == "LogicalDisk" and CounterName == "Free Megabytes"
// exclude all others as we are checking for C: here
| where InstanceName != "D:"
| where InstanceName != "_Total"
| where InstanceName != "HarddiskVolume1"
| extend FreeSpaceGB = CounterValue/1024 // converting the counter value to GB
| summarize FreeSpace = min(FreeSpaceGB) by Computer,InstanceName
| where FreeSpace < setgbvalue //setting condition to check if the value is less than our set value .
示例:
为了测试它,我将值设置为 200GB,我的磁盘空间为 106GB。我收到了如下邮件。