To monitor your virtual machines in Azure, Application Insights gives you a solid way to collect telemetry data. In this post, I’ll show you how to enable VM Insights on an Azure Virtual Machine with a Bicep module I recently worked on.
The Goal
We aim to:
- Enable diagnostics on an Azure VM.
- Send logs and performance metrics to Application Insights.
- Use a Bicep module to automate the setup.
The Solution: A Bicep Module
Below is the Bicep module I crafted to enable VM Insights:
| |
Key Components
- Application Insights
The appInsights resource is defined as an existing resource. Make sure to create an Application Insights instance before using this module.
- Storage Account
Used for storing diagnostic logs and data. The storage account is also referenced as an existing resource.
- Virtual Machine
The target VM must exist before deploying this module. The Bicep code references the VM as an existing resource.
- VM Extension
The IaaSDiagnostics extension is the critical piece that connects the VM to Application Insights. It configures various settings, including performance counters, logs, and event logs.
How It Works
Diagnostics Configuration (WadCfg) Defines settings for logs, performance counters, and event logs that are collected from the VM.
Sinks Configuration Routes the collected telemetry data to both Azure Monitor and Application Insights.
Protected Settings Includes sensitive data such as the storage account key to securely connect to the storage account.
Conclusion
This Bicep module simplifies enabling VM Insights on Azure Virtual Machines, so you get detailed monitoring and diagnostics without manual setup. With telemetry routed to Application Insights, you can watch your VM’s health and performance in real time.
Do you have a different approach to enabling VM Insights? Let me know in the comments!
References:
- Azure Monitor Overview
- Application Insights Documentation
- Azure Virtual Machines Extensions
- Bicep Language Documentation
- Azure Diagnostics Extension
- Manage Virtual Machines with Azure CLI
- How to Configure VM Insights
- Install and configure the Azure Diagnostics extension for Windows (WAD)
- Troubleshooting Azure Diagnostics extension - Azure Monitor
- Windows diagnostics extension schema
