Learn why Azure VMInsights is an essential tool for monitoring Azure VMs and how to deploy it using Bicep.
Azure VMInsights is a must-have tool for anyone looking to optimize visibility into virtual machine performance and health in Azure. Whether managing a single VM or scaling up to hundreds, VMInsights provides the insights needed to monitor, diagnose, and optimize your workloads.
In this blog, we’ll explore why VMInsights is invaluable and guide you through deploying it using Bicep.
Why Use VMInsights?
Managing virtual machines in the cloud comes with unique challenges. Basic metrics like CPU and memory usage aren’t enough to maintain optimal performance at scale. VMInsights addresses this gap with features such as:
1. Comprehensive Monitoring
VMInsights integrates with Azure Monitor to provide unified insights into key metrics like CPU, memory, disk, and network usage.
2. Dependency Mapping
Its dependency map visualizes interactions between VMs and external resources, making it easy to identify bottlenecks and dependencies.
3. Actionable Insights
Pre-built workbooks turn raw data into actionable insights, enabling quick identification of issues like resource contention or underperforming VMs.
4. Scalability
VMInsights scales effortlessly across production, development, and testing environments, ensuring consistent monitoring.
Prerequisites for Deployment
Before deploying VMInsights, ensure the following resources are in place:
targetScope='subscription'// Please Update this based on deploymentScope Variable//// Imported Parameters@description('Azure Location')paramlocationstring@description('Azure Location Short Code')paramlocationShortCodestring@description('Environment Type')paramenvironmentTypestring@description('User Deployment Name')paramdeployedBystring@description('Azure Metadata Tags')paramtagsobject={environmentType:environmentTypedeployedBy:deployedBydeployedDate:utcNow('yyyy-MM-dd')}@description('The Data Collection Rule Name')paramwindowsDataCollectionRuleNamestring='MSVMI-vminsights-windows'@description('The Data Collection Rule Name')paramlinuxDataCollectionRuleNamestring='MSVMI-vminsights-linux'//// Bicep Deployment VariablesparamprojectNamestring='vminsights'varresourceGroupName='rg-${projectName}-${environmentType}-${locationShortCode}'varlogAnalyticsName='log-${projectName}-${environmentType}-${locationShortCode}'//// Azure Verified Modules - No Hard Coded Values below this line!modulecreateResourceGroup'br/public:avm/res/resources/resource-group:0.4.0'={name:'create-resource-group'params:{name:resourceGroupNamelocation:locationtags:tags}}modulecreateLogAnalyticsWorkspace'br/public:avm/res/operational-insights/workspace:0.9.1'={name:'create-log-analytics-workspace'scope:resourceGroup(resourceGroupName)params:{name:logAnalyticsNamelocation:locationskuName:'PerGB2018'dataRetention:90tags:tags}dependsOn:[createResourceGroup]}modulecreateWindowsDataCollectionRule'br/public:avm/res/insights/data-collection-rule:0.4.2'={scope:resourceGroup(resourceGroupName)name:'create-windows-data-collection-rule'params:{name:windowsDataCollectionRuleNamelocation:locationdataCollectionRuleProperties:{kind:'Windows'description:'Data collection rule for VM Insights.'dataFlows:[{streams:['Microsoft-InsightsMetrics']destinations:[createLogAnalyticsWorkspace.outputs.name]}{streams:['Microsoft-ServiceMap']destinations:[createLogAnalyticsWorkspace.outputs.name]}]dataSources:{performanceCounters:[{streams:['Microsoft-InsightsMetrics']samplingFrequencyInSeconds:60counterSpecifiers:['\\VmInsights\\DetailedMetrics']name:'VMInsightsPerfCounters'}]extensions:[{streams:['Microsoft-ServiceMap']extensionName:'DependencyAgent'extensionSettings:{}name:'DependencyAgentDataSource'}]}destinations:{logAnalytics:[{workspaceResourceId:createLogAnalyticsWorkspace.outputs.resourceIdworkspaceId:createLogAnalyticsWorkspace.outputs.logAnalyticsWorkspaceIdname:createLogAnalyticsWorkspace.outputs.name}]}}}dependsOn:[createLogAnalyticsWorkspace]}modulecreateLinuxDataCollectionRule'br/public:avm/res/insights/data-collection-rule:0.4.2'={name:'create-linux-data-collection-rule'scope:resourceGroup(resourceGroupName)params:{name:linuxDataCollectionRuleNamelocation:locationdataCollectionRuleProperties:{kind:'Linux'description:'Data collection rule for VM Insights.'dataFlows:[{streams:['Microsoft-InsightsMetrics']destinations:[createLogAnalyticsWorkspace.outputs.name]}{streams:['Microsoft-ServiceMap']destinations:[createLogAnalyticsWorkspace.outputs.name]}]dataSources:{performanceCounters:[{streams:['Microsoft-InsightsMetrics']samplingFrequencyInSeconds:60counterSpecifiers:['\\VmInsights\\DetailedMetrics']name:'VMInsightsPerfCounters'}]extensions:[{streams:['Microsoft-ServiceMap']extensionName:'DependencyAgent'extensionSettings:{}name:'DependencyAgentDataSource'}]}destinations:{logAnalytics:[{workspaceResourceId:createLogAnalyticsWorkspace.outputs.resourceIdworkspaceId:createLogAnalyticsWorkspace.outputs.logAnalyticsWorkspaceIdname:createLogAnalyticsWorkspace.outputs.name}]}}}dependsOn:[createLogAnalyticsWorkspace]}
Once your Bicep template is ready, You can either use the Invoke-AzDeployment.ps1 wrapper deploy it
To configure on the Virtual Machine, From the settings pain click on Insights then Monitoring Configuration
Wait 30 minutes and you’ll start seeing metrics reporting.
Wrap Up
VMInsights is a powerful solution for optimizing the performance and health of your Azure VMs. By leveraging Bicep for deployment, you gain a scalable, consistent, and efficient setup process. Explore the provided repository to get started quickly and unlock the full potential of VMInsights in your Azure environment.