Building a simple yet robust monitoring solution for a website using Azure Application Insights
I’ve grown to use and love Azure Application Insights quite a bit in recent years. It’s a relatively simple, yet powerful monitoring, debugging, troubleshooting and analysis tool that lends itself to many use cases.
As I’ve recently migrated my personal blog to a hosted WordPress, I needed to build something simple (as time is always a scarce resource) yet powerful enough monitoring to notify me if something fails. Perhaps the hoster’s MySQL cluster is down? Or the Let’s Encrypt-based SSL certificate happens to expire without auto-renewing. As Application Insights has a nifty little capability to ping a URL to determine availability, I decided to build my solution around it.
Provisioning Application Insights
Anybody can provision anything using the Azure Portal and a few fast and furious mouse clicks. I like to spend a few extra minutes to figure out how to provision things through the keyboard, in case I want to script or automate things later. For this purpose, I primarily use Azure CLI.
First, I need to create a resource group. I’m using Windows Terminal together with Azure Cloud Shell to make running scripts convenient for me. To provision a new resource group in West Europe, I first run:
az group create --resource-group jussiroine-blog-monitor --location westeurope
Next, to provision Application Insights the documentation says I’d need to run az monitor app-insights create, but this command isn’t available. It could be an extension, but upon further investigation, I found out it doesn’t exist (yet). So to circumvent this issue, I’ll need to provision a new resource using az resource:
az resource create --resource-group jussiroine-blog-monitor --resource-type "Microsoft.Insights/components" --location westeurope --properties '{"Application_Type":"web"}' --name jussiroine-blog-appinsights
And to verify my Application Insights was provisioned, I can query the resource group to list all its resources:
az resource list --resource-group jussiroine-blog-monitor
Viewing the instance through Azure Portal it shows everything is in order:
Configuring URL ping
Now, to configure URL ping I resort to using Azure Portal, as it’s a one-time operation and often done only once or twice depending on the number of ping probes I need. Under Application Insights I’ll click on Availability and then from the top toolbar I can create a test with + Add test
I’ll create a test by defining the target URL (https://jussiroine.com), and test frequency (5 minutes). I can also parse dependent requests, which makes sense as the initial HTTP request will evidently receive a lot of dependent resources.
For test locations, I chose a few useful datacenters, including West Europe, North Europe, and France Central. And that’s it! Nothing else needed, for now.
I can verify the availability pings are working by viewing the dashboard under Availability:
Configuring alerts
The only that is still needed is to define a suitable alert. Should my blog have intermittent issues I can define what action to take in Azure. Click on the three small dots and select Edit alert to define the action:
The beauty of this is that the alert is pre-configured now. All you have to do is define the action group(s):
I had one previous action group that emails me should something fail, so I chose to reuse that. You can, of course, create your own, and then define suitable actions. These actions include running an Azure Function, calling a Logic App and other useful tasks:
In summary
Sometimes things you need to build can be simple, and you can leverage a lot of the infrastructure and services Azure already offers. I could easily extend this solution to perhaps file a ticket to my hosting company, or do other automation beyond a simple email.
I’ve only been running this solution for a brief moment, yet I already like the estimates costs: