Setting up an Azure File Share capacity alert is useful to know when you reach at least 80% of allocated quota for the file share. This will give the teams ample time to increase the allocation to avoid out of space issues. If we are using standard tier for storage account then we need to use one storage account for each file share, to get the correct alert. Sending the alert to slack channel is a useful way to get properly alerted to take action on time. Let's use an example learn how to setup alerts for multiple Azure file shares uing terraform.
Expectation is to get the alerts to slack channel as shown below.
Assume there are two storage accounts and each contains a single Azure file share. Since standard tier storage accounts do not support metrics dimentions per file share we have to keep our file shares in seperate storage accounts, meaning we can only have one file share in each storage account as recomended in here. Below terraform code creates two storage accounts and a file share in each account.
The next step would be to cerate an action group to send an email. First we have to get the email address of the slack channel. We can get it from slack channel properties windows, integrations tab.
Then we can use copied email adress and create an action group in Azure with terraform as shown below.
Once we create the action group we whould recieve an email in the slack channel saying the consumer group is set.
Next step is to create two alerts for each storage file share to send an alert when reached a given capacity usage. Note that for testing purpose here the values are set as 4GiB and 2GiB which is just an example values to trigger alerts.
resource "azurerm_monitor_metric_alert" "aks_fs_win" { name = "${azurerm_storage_account.filestorage_aks_win.name}-${azurerm_storage_share.aks_windows.name}-capacity-alert" resource_group_name = azurerm_resource_group.instance_rg.name scopes = ["${azurerm_storage_account.filestorage_aks_win.id}/fileservices/default"] description = "AKS file share ${azurerm_storage_account.filestorage_aks_win.name}/${azurerm_storage_share.aks_windows.name} reached 80% capacity" enabled = true auto_mitigate = true frequency = "PT1M" window_size = "PT1H" severity = 2 target_resource_type = "Microsoft.Storage/storageAccounts/fileservices" criteria { metric_namespace = "Microsoft.Storage/storageAccounts/fileservices" metric_name = "FileCapacity" aggregation = "Average" operator = "GreaterThanOrEqual" threshold = 4294967296 # 4GiB } action { action_group_id = azurerm_monitor_action_group.fileshare_capacity_action.id } } resource "azurerm_monitor_metric_alert" "aks_fs_linux" { name = "${azurerm_storage_account.filestorage_aks_linux.name}-${azurerm_storage_share.aks_linux.name}-capacity-alert" resource_group_name = azurerm_resource_group.instance_rg.name scopes = ["${azurerm_storage_account.filestorage_aks_linux.id}/fileservices/default"] description = "AKS file share ${azurerm_storage_account.filestorage_aks_linux.name}/${azurerm_storage_share.aks_linux.name} reached 80% capacity" enabled = true auto_mitigate = true frequency = "PT1M" window_size = "PT1H" severity = 2 target_resource_type = "Microsoft.Storage/storageAccounts/fileservices" criteria { metric_namespace = "Microsoft.Storage/storageAccounts/fileservices" metric_name = "FileCapacity" aggregation = "Average" operator = "GreaterThanOrEqual" threshold = 2147483648 # 2GiB } action { action_group_id = azurerm_monitor_action_group.fileshare_capacity_action.id } }
You can find the full terraform code exaple here in GitHub. After we deploy the terraform changes we should have below resources created in Azure.
Now we can ispect our file shares for the capacity usage.
We get an alert in Azure and in slack channel.
No comments:
Post a Comment