Search code examples
azureazure-functionsalertazure-application-insightsazure-bicep

Set alert rule when certain CPU percentage is exceeded


I'd like to automate an alert rule in Azure using Bicep when a certain CPU utilization exceeds the threshold value at a specific period of time and an alert rule when the system memory utilization exceeds the threshold value at a specific period of time. It should function as a general setting that can be used for different cases, not only a specific one.

Is it possible to apply these alert rules for application insights (azure functions, app services)?

As I could not find any templates for this case in Bicep, I am asking for help if someone could share a sample code of how it could look like, as I am very new to IaC.

Thank you very much for your help!

Best regards Jennifer M.


Solution

  • You can create alert in Azure monitor by selecting required condition. Once alert created, download arm template and convert it to bicep. Using converted bicep file, you can create alert as mentioned in link. I have reproduced issue from my side and below are steps I followed,

    1. created an alert for app service and selected condition as cpu percentage. enter image description here enter image description here
    2. Once alert created, exported arm template. enter image description here
    3. Using below command, converted arm template to bicep file.
    az bicep decompile -f theARMfile.json
    
    1. Using Azure Cli, uploaded bicep file and ran below commands.
    az group create --name ExampleGroup --location "South Central US"
    az deployment group create \
      --resource-group ExampleGroup \
      --template-file azuredeploy.bicep \
      --parameters storageAccountType=Standard_GRS
    

    enter image description here enter image description here

    Reference link