February 14, 2021 by Anuraj Estimated read time : 4 mins
This article shows you how create and run custom availability tests using Azure Functions. This is an update to the blog post about monitoring WebJobs using Application Insights, since Microsoft is deprecating the Load Test and Performance features, this is the recommended alternative for monitoring availability. To get started you need to create an Azure function in C# with Timer Trigger. You can choose the trigger interval based on your requirement. This is one of the main advantage compared to Application Insights availability test feature. Next you need to add following packages.
Microsoft.ApplicationInsights - This package is for interacting with the Application Insights.
Microsoft.Azure.Functions.Extensions - This package is for creating a Startup class for the Azure Function.
Microsoft.Extensions.Http - This package is for creating the HttpClient which helps to interact with Web Jobs REST API.
This Startup class is required so that you can inject the HttpClient to the Azure Function - it is the recommended instead of creating the HttpClient instance every time in the Function code. Here is the Startup class code.
And here is the Function implementation.
The ExecuteTestAsync execute the business logic or test implementation. In this you will be writing the code to interact with Kudu REST endpoint and verify the response status code.
WebJobResponse class is the POCO implementation of REST endpoint response. You can convert the JSON response to POCO using json2csharp.com or using Visual Studio. Now you can run the function and verify the status of the Web Job.
This way you can create and run custom availability tests using Azure Functions. Similar to Application Insights availability tests you can configure alerts. As the location is null it is showing empty in the availability blade. If you host it on Azure Functions, the location variable will be auto populated.