question

StephenLawrence-6936 avatar image
0 Votes"
StephenLawrence-6936 asked DavidIremiren-4029 commented

help to set up azure alert for disk space alert when 10gb or less

I've had a look around this forum but I can't find anything specific to virtual machines on Azure.

I thought it would have been an option as a Signal name (see screenshot below)

40453-image.png



please can you point me in the right direction?

thanks

Stephen

azure-cloud-services
image.png (100.6 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @prmanhas-MSFT

I'm very sorry to be a further pain..

just for clarification, the script provided ignores drive D, is this because drive D is always allocated to Temporary Storage on virtual machines?

Also, when I run the script in 'Logs', it identifies 'HarddiskVolume1' as being below 10gb.
40796-image.png

I presumed that this would be the primary C:\ drive, but looking on the VM, drive C:\ has 105GB free

40795-image.png

Please can you advise?

-Stephen


0 Votes 0 ·
image.png (69.2 KiB)
image.png (40.4 KiB)
image.png (76.7 KiB)

@StephenLawrence-6936 I might need to dig little deep into this. Allow me some time and I will keep you posted on same.

Thanks

·

3 Votes 3 ·
prmanhas-MSFT avatar image
4 Votes"
prmanhas-MSFT answered DavidIremiren-4029 commented

@StephenLawrence-6936 Apologies for the delay in response and all the inconvenience caused because of the issue.

I did some research and found below which might be helpful in your use case:

 // enter a GB value to check
 let setgbvalue = 100;
 // Query
 Perf
 | where TimeGenerated > ago(1h)
 | where ObjectName == "LogicalDisk" and CounterName == "Free Megabytes"
 | where InstanceName !contains "D:"
 | where InstanceName  !contains "_Total" 
 | extend FreeSpaceGB = CounterValue/1024
 | summarize FreeSpace = min(FreeSpaceGB) by Computer, InstanceName
 | where FreeSpace < setgbvalue

The let setgbvalue is where you can change the value of free space the server can have before it alerts. In example we are using 20gb. This will allow you enough time to fix any alerts before the server has issues.

Then doing a simple Perf query that looks over the last hour for the Object LocalDisk and Counter Free Megabytes. It then also looks for any instance that contains : . This basically looks for any drive that contains a :, so C:, D:, etc.

We then set a variable called FreeSpaceGB to be the CounterValue (the Free Megabytes from the above lines) and dived it by 1024 to get the value in GB.

Next we use the Summarize command to FreeSpace = the minimum FreeSpaceGB by Computer and InstanceName. This will give us the Server name, which drive is affected and the FreeSpace.

The last line filters the results to only show servers with disk space less then the value set.

So we have the query but how do we get an email alert when a server goes under the set frees pace? For that we can use Azure Monitor and the alerts feature.

Setting the Alerts

To set the alert you will need to navigate to Azure Monitor in the Azure Portal.

In here click on Alerts.
40666-image.png


Here you need to click on the blue + New alert rule button.

40630-image.png

In this blade, you will need to select the Log Analytics workspace you have the servers associated to under the RESOURCE section.

40721-image.png

You then need to add a CONDITION. This is where we add the query from before. Click on Add condition and then select Custom log search.
40722-image.png

Paste in the query from before. You can change the setgbvalue to the value you need. Then set the Threshold to be 0.

Change the Evaluated based on values to 60 and then click Done.
40723-image.png


Under ACTION GROUPS you can either Select existing or Create New. If you chose to create new you will have a blade like the shown. Just fill it in and click OK.
40724-image.png

Now you have to enter some ALERT DETAILS. Here just give the alert rule a name and a description. You also have to set the Severity rating.

Once you have everything how you want it, click on Create alert rule.
40713-image.png

Your alert has now been created and if you left the Enable rule upon creation enabled. Then as soon as an alert triggers you will receive an email. This will look something like this image.

40657-image.png

There you have it. You are now being alerted when a server has less than 20gb of disk space. You can configure same alert for 10 gb as well.

Hope it helps.

Please 'Accept as answer' if it helped, so that it can help others in the community looking for help on similar topics









image.png (164.9 KiB)
image.png (87.8 KiB)
image.png (42.9 KiB)
image.png (72 B)
image.png (45.0 KiB)
image.png (24.9 KiB)
image.png (50.4 KiB)
image.png (246.1 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi prmanhas-MSFT

I'm so very grateful for your help and expertise

Thank you very much, this has saved us a big headache

Stephen

0 Votes 0 ·

@StephenLawrence-6936 Glad to hear that I could be of help :)

Thanks

0 Votes 0 ·

Hi,
do have any ideia how to create low disk space alert when SQL logs are filling all the disk space?
Could you helo on this question.

Thanks in advance.

0 Votes 0 ·

@prmanhas-MSFT ,

I know its been a while since you put together this alerts solution, but i noticed that the layout of the alert rule creation has changed.
The Alert conditions page has some new entries.
Do you have an updated solution for this?
187041-image.png


0 Votes 0 ·
image.png (39.1 KiB)
HasanNumanoglu-3114 avatar image
2 Votes"
HasanNumanoglu-3114 answered

looks like a joke. we are just asking about a simple alert..

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndrewHellyer-7605 avatar image
0 Votes"
AndrewHellyer-7605 answered DavidIremiren-4029 commented

Use this instead, or you will get false positives due to the values returned from "HarddiskVolume" from InstanceName

 // enter a GB value to check
 let setgbvalue = 10;
 // Query
 Perf
 | where TimeGenerated > ago(1h)
 | where ObjectName == "LogicalDisk" and CounterName == "Free Megabytes"
 | where InstanceName !contains "D:"
 | where InstanceName !contains "_Total"  
 | where InstanceName !contains "HarddiskVolume"
 | extend FreeSpaceGB = CounterValue/1024
 | summarize FreeSpace = min(FreeSpaceGB) by Computer, InstanceName
 | where FreeSpace < setgbvalue
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@AndrewHellyer-7605

Great addition to the query, really cleans it up.

Many thanks for this

0 Votes 0 ·