是否有人设法通过terraforms Insights为虚拟机启用?
我可以创建虚拟机,启用日志记录,但不能启用洞察。
我看到这个问题:但找不到一个明确的答案。How to enable azure vm application insights monitoring agent using terraform
这是我用于测试的完整terraform脚本,我直接在Azure的云shell上运行它。
# Configure the Azure provider
provider "azurerm" {
# The "feature" block is required for AzureRM provider 2.x.
features {}
}
variable "prefix" {
default = "tfvmex"
}
resource "azurerm_resource_group" "main" {
name = "${var.prefix}-resources"
location = "West Europe"
}
resource "azurerm_virtual_network" "main" {
name = "${var.prefix}-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
}
resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = azurerm_resource_group.main.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_network_interface" "main" {
name = "${var.prefix}-nic"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
ip_configuration {
name = "testconfiguration1"
subnet_id = azurerm_subnet.internal.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_virtual_machine" "main" {
name = "${var.prefix}-vm"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
network_interface_ids = [azurerm_network_interface.main.id]
vm_size = "Standard_DS1_v2"
# Uncomment this line to delete the OS disk automatically when deleting the VM
# delete_os_disk_on_termination = true
# Uncomment this line to delete the data disks automatically when deleting the VM
# delete_data_disks_on_termination = true
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags = {
environment = "staging"
}
}
resource "azurerm_storage_account" "main" {
name = "omstesttest22"
resource_group_name = azurerm_resource_group.main.name
location = "westus"
account_tier = "Standard"
account_replication_type = "GRS"
tags = {
environment = "staging"
}
}
resource "azurerm_log_analytics_workspace" "law02" {
name = "${var.prefix}-logAnalytics"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
sku = "PerGB2018"
retention_in_days = 30
}
resource "azurerm_log_analytics_solution" "example" {
solution_name = "ContainerInsights"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
workspace_resource_id = azurerm_log_analytics_workspace.law02.id
workspace_name = azurerm_log_analytics_workspace.law02.name
plan {
publisher = "Microsoft"
product = "OMSGallery/ContainerInsights"
}
}
#===================================================================
# Set Monitoring and Log Analytics Workspace
#===================================================================
resource "azurerm_virtual_machine_extension" "oms_mma02" {
name = "test-OMSExtension"
virtual_machine_id = azurerm_virtual_machine.main.id
publisher = "Microsoft.EnterpriseCloud.Monitoring"
type = "OmsAgentForLinux"
type_handler_version = "1.12"
auto_upgrade_minor_version = true
settings = <<SETTINGS
{
"workspaceId" : "${azurerm_log_analytics_workspace.law02.workspace_id}"
}
SETTINGS
protected_settings = <<PROTECTED_SETTINGS
{
"workspaceKey" : "${azurerm_log_analytics_workspace.law02.primary_shared_key}"
}
PROTECTED_SETTINGS
}
希望你说清楚了。谢谢!
5条答案
按热度按时间dddzy1tm1#
根据本文档,VM洞察要求在要监视的每个虚拟机上安装以下两个代理。
*日志分析代理。从虚拟机或虚拟机规模集收集事件和性能数据,并将其提供给Log Analytics工作区。Azure资源上的Log Analytics代理的部署方法使用Windows和Linux的VM扩展。
*依赖代理。收集已发现的有关虚拟机上运行的进程和外部进程依赖项的数据,VM洞察中的Map功能使用这些数据。Dependency代理依赖Log Analytics代理将其数据传递到Azure Monitor。Azure资源上的依赖项代理的部署方法使用适用于Windows和Linux的VM扩展。
在我的验证之后,您可以将DependencyAgent扩展添加到现有代码中。
有关详细信息,请阅读配置日志分析工作区以获得VM洞察和Enable VM insights guest health (preview)
628mspwn2#
请使用产品“OMSGallery/VMInsights”(而不是“OMSGallery/ContainerInsights”)
mfpqipee3#
使用Terraform部署:
部署日志分析工作区和与该工作区关联的VMInsights解决方案。
使用OMSAgent和DependencyAgentWindows扩展照常部署VM:
适用于Windows的OMS:https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/oms-windows
Windows DA代理:https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/agent-dependency-windows
yquaqz184#
微软已经更改了MicrosoftMonitoringAgent扩展中所需的设置,@Bill指定的terraform自2022年6月起不再工作。为我工作的Terraform是:
注意“msmonitor-agent”下的扩展设置
agyaoht75#
这里有几篇关于这个主题的文章,也许你可以参考: