When it comes to monitoring your virtual machines in Azure, Application Insights provides a powerful and scalable solution for collecting telemetry data. In this blog post, I’ll walk you through how to enable VM Insights on an Azure Virtual Machine using 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, ensuring you have comprehensive monitoring and diagnostics. With the telemetry routed to Application Insights, you gain real-time insights into your VM’s health and performance.
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