I've tried to set up Log Analytics in my Linux Virtual Machine Scale Set but it's not working. I used this as a template but to no avail.
Here is my terraform:
###############
# Log analytics
###############
resource "azurerm_virtual_machine_scale_set_extension" "AzureMonitorLinuxAgent" {
name = "AzureMonitorLinuxAgent"
publisher = "Microsoft.Azure.Monitor"
type = "AzureMonitorLinuxAgent"
type_handler_version = "1.10"
auto_upgrade_minor_version = true
virtual_machine_scale_set_id = azurerm_linux_virtual_machine_scale_set.vmss.id
depends_on = [
azurerm_linux_virtual_machine_scale_set.vmss
]
}
resource "azurerm_monitor_data_collection_rule" "example" {
name = "my ame"
resource_group_name = var.resource_group_name
location = var.location
destinations {
log_analytics {
workspace_resource_id = var.log_analytics_workspace_log_id
name = "destination-log"
}
azure_monitor_metrics {
name = "test-destination-metrics"
}
}
data_flow {
destinations = ["destination-log"]
streams = ["Microsoft-InsightsMetrics", "Microsoft-Event", "Microsoft-Syslog"]
}
data_sources {
performance_counter {
streams = ["Microsoft-InsightsMetrics"]
sampling_frequency_in_seconds = 60
counter_specifiers = ["\\VmInsights\\DetailedMetrics"]
name = "VMInsightsPerfCounters"
}
syslog {
facility_names = ["*"]
log_levels = ["*"]
name = "test-datasource-syslog"
}
}
}
# associate to a Data Collection Rule
resource "azurerm_monitor_data_collection_rule_association" "dcra" {
name = "example1-dcra"
target_resource_id = azurerm_linux_virtual_machine_scale_set.vmss.id
data_collection_rule_id = azurerm_monitor_data_collection_rule.example.id
description = "example"
}
Results:
When I go into the Logs section in my VMSS, I get the screen asking if I want to enable so I know it's not working. When I click Enable, I can see my Data Collection Rule was created properly and if I just wanted to configure. I'm not sure what I am missing on my terraform side.
I tried below code to create log analytics in VMSS:
This created workspace but did not enable logs
Tried to Include:
data_sources with syslog
to enable logs in resource "azurerm_monitor_data_collection_rule" as you didCode:
Refer :enable-vm-insights-for-azure-monitor-agent | Microsoft learn
One must also upgrade from free trial and use supported regions.
In my case even if i configure by seleting enable , logs has not created as either there are no logs yet created Aand may take several minutes or its support is limited for VMSS.
Also logs may take few minutes to show .See https://learn.microsoft.com/en-us/azure/azure-monitor/vm/vminsights-troubleshoot.
Data collection rules in Azure Monitor - Azure Monitor | Microsoft Learn