采集器「Azure-Virtual Machine 采集」配置手册¶
阅读本文前,请先阅读:
Tip
使用本采集器前,必须安装「集成 Core 核心包」及其配套的第三方依赖包
1. 配置结构¶
本采集器配置结构如下:
字段 | 类型 | 是否必须 | 说明 |
---|---|---|---|
subscriptions |
list | 非必填 | 所需采集的订阅 ID 列表 |
subscriptions[#] |
str | 订阅 ID | |
locations |
list | 非必须 | 地域列表 |
locations[#] |
str | 地域,例:westus2 |
2. 配置示例¶
无配置¶
不需要额外配置,自动获取已授权订阅下的所有目标资源
指定订阅¶
采集订阅 ID 为:xxxx1
下的所有实例对象
指定订阅和地域¶
采集订阅 ID 为:xxxx1 且在 westus2
,westus
地域下的所有实例对象
配置过滤器(可选项)¶
本采集器脚本支持用户自定义过滤器,让用户通过对象属性筛选出目标资源。过滤器函数返回值为 True|False
-
True:目标资源需要被采集。
-
False 目标资源不需要被采集
支持筛选的对象属性:
属性 | 描述 |
---|---|
name | 资源 ID |
resourceId | 资源 ID (同 name 字段) |
resourceName | 资源名称 |
resourceGroup | 资源组名称 |
location | 资源位置 |
vmId | 指定 VM 唯一 ID,该 ID 是一个 128 位标识符 |
computerName | 指定虚拟机的主机 OS 名称 |
zone | 虚拟机区域 |
publicipAddress | 公网 IP |
# 示例:开启过滤器,根据对象的 computerName 和 provisioningState 属性过滤,配置格式如下:
def filter_instance(instance):
'''
采集 computerName 为 xxx 并且 provisioningState 为 Succeeded 的实例
'''
# return True
computer_name = instance['computerName']
provisioning_state = instance['provisioningState']
if computer_name in ['xxx'] and provisioning_state == 'Succeeded':
return True
return False
@DFF.API('Azure-Virtual Machines Collection', timeout=3600, fixed_crontab='*/15 * * * *')
def run():
Runner(main.DataCollector(account, collector_configs, filters=[filter_instance])).run()
3. 数据上报格式¶
数据正常同步后,可以在 观测云 的「基础设施-资源目录」中查看数据。
上报的数据示例如下:
{
"measurement": "azure_compute_virtualmachines",
"tags": {
"location" : "eastus",
"RegionId" : "westus2",
"name" : "/subscriptions/sss/resourcegroups/aaa/providers/microsoft.compute/virtualmachines/xxx",
"public_ip_address": "52.170.218.114",
"resource_group" : "aaa",
"resource_id" : "/subscriptions/sss/resourcegroups/aaa/providers/microsoft.compute/virtualmachines/xxx",
"resource_name" : "xxx",
"subscription_id" : "sss",
"subscription_name": "xxx",
"tenant_id" : "ce9fe5b4-xxxxx",
"vm_id" : "64913e31-xxxxx",
"zone" : "1"
},
"fields": {
"power_state" : "running",
"provisioning_state" : "Succeeded",
"public_ip_address_version": "IPv4",
"storage_profile" : "{存储配置}",
"time_created" : "2023-10-11T07:20:06.8185073+00:00",
"network_interfaces" : "{网络 JSON 数据}",
"instance_view" : "{运行状态 JSON 数据}",
"message" : "{实例 JSON 数据}",
"admin_username" : "rrr",
"hardware_profile" : "{硬件配置}",
"tags" : "{Azure 控制台配置的 tags}"
}
}
Note
tags、fields 中的字段可能会随后续更新有所变动
Tip
tags.name 值为实例 ID,作为唯一标识
Tip
以下字段均为 JSON 序列化后字符串
fields.message
fields.network_interfaces
fields.storage_profile
fields.hardware_profile
fields.tags
fields.instance_view
X. 附录¶
Azure 相关文档: