DnyaneshSurya
DnyaneshSurya

Reputation: 207

How to create azure monitor alert when my disk space low in virtual machine

I have one virtual machine . Now I want if my disk space showing very low I mean less than 2 gb. Then I want to trigger azure monitor alerts and want to get Email regarding this. is there any metrics azure monitor provide.

Upvotes: 5

Views: 13742

Answers (1)

Ansuman Bal
Ansuman Bal

Reputation: 11421

There are no predefined alerts for diskspace as of now . But you can create a new alert with custom log search to get the details and then trigger the email to you.

Step 1 : Go to Alerts on your Monitor Page and click on New alert rule .

enter image description here

Step 2: Then select the resource and by resource here you have to select the Log analytics workspace which you have enabled the VM monitoring for . In my case its TestLog.

enter image description here

Step 3: Now select the Custom Log Search .

enter image description here

Step 4: Then provide the Custom Query which I have provided below in the search query box and you can set the threshold value to “0” and period and frequency in mins as per your requirement for an example I have set it to 60mins.

enter image description here

Step 5: Now Select an existing Action group that you have or you can create a new one by clicking on create new and filling the details . After its Created click on the action group and add the notification type as Email or anything you want to specify.

enter image description here

enter image description here

Step 6: Fill rest details like email subject and severity of the alert you want to set it to and then create alert.

enter image description here

Custom Query:

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 . 

enter image description here

Sample :

To test it I had set the value to 200GB and my disk space was 106GB. I received the mail as below.

enter image description here enter image description here

Upvotes: 4

Related Questions