0
  1. I need to set an azure alert to my azure function http triggered. When I have an internal server error (500) then I need to send an alert email to a group of emails.
  2. How to create a azure dash board to get the number of hits to an API.

need a better solution for alert email template and alerts setting.

1 Answers1

0

I Tried to reproduce the same in my environment to create azure alerts when the function gets HTTP 500 server error:

  1. Azure alert when azure function http triggered.

I have created a function app, like below.

Azure portal > Function App >Create

enter image description here

Create a function with visual studio and upload the same to the function app.

Sample code to create an exception.

public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
    ILogger log)
{
    throw new Exception("An error has occurred.");
}

Once publish the code to Azure Function app, check the Function Status. Like below.

Azure Portal > Function App > Select your Function app >Functions.

enter image description here

Run the function and check the result, like below.

Open Functions >Code + Test > Test/Run

Note: Body section add above vs code to get 500 server error.

enter image description here

Output

enter image description here

To generate the alert for HTTP 500 error.

Functions > Monitor > Run query in Application Insights

Query to check 500 internal error.

requests
| project
    timestamp,
    id,
    operation_Name,
    success,
    resultCode,
    duration,
    operation_Id,
    cloud_RoleName,
    invocationId=customDimensions['InvocationId']
| where timestamp > ago(30d)
| where cloud_RoleName =~ 'httpdtriggeredfunc01' and operation_Name =~ 'Function1'
| order by timestamp desc
| take 20

enter image description here

Click on a new alert rule to generate the alert for the same error.

Create an action group with your DL email id.

enter image description here

When the function triggered HTTP 500 internal server error, you will get an alert to your mail id.

enter image description here

Successfully received an email.

enter image description here

2. How to create an azure dashboard to get the number of hits to an API.

To create a dashboard for the function app.

Open your function app > Application Insights > View Application Insights data.

enter image description here

Once open the application Insights data and select the application dashboard option, it will create a dashboard for your function app automatically.

enter image description here

Venkat V
  • 2,197
  • 1
  • 1
  • 10