跳转至

采集器「微软云-VM」配置手册

阅读本文前,请先阅读:

使用本采集器前,必须安装「观测云集成 Core 核心包」及其配套的第三方依赖包

1. 配置结构

本采集器配置结构如下:

字段 类型 是否必须 说明
subscriptions list 必须 所需采集的订阅 ID 列表
subscriptions[#] str 必须 订阅 ID

2. 配置示例

指定地域

采集订阅 ID 为:xxxx1下的实例数据

Python
1
2
3
collector_configs = {
    'subscriptions': ['xxxx1', ]
}

配置过滤器(可选项)

本采集器脚本支持用户自定义过滤器,让用户通过对象属性筛选出目标资源。过滤器函数返回值为 True|False

  • True:目标资源需要被采集。

  • False 目标资源不需要被采集

支持筛选的对象属性:

属性 描述
name 资源 ID
location 资源位置
vmId 指定 VM 唯一 ID,该 ID 是一个 128 位标识符
type 资源类型
hardwareProfile_vmSize 指定虚拟机的大小
storageProfile_osDisk_osType 属性允许指定从用户映像或专用 VHD 创建 VM 时磁盘中包含的 OS 类型。 可能的值包括: Windows、Linux
storageProfile_diskControllerType 指定为 VM 配置的磁盘控制器类型
computerName 指定虚拟机的主机 OS 名称
adminUsername 指定管理员帐户的名称
zone 虚拟机区域
privateIPAddress 内网 IP
privateIPAddressVersion 内网 IP 配置
ProvisioningState 预配状态
PowerState 运行状态
publicipAddress 公网 IP
publicIPAddressVersion 公网 IP 配置
Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 示例:开启过滤器,根据对象的 computerName 和 publicIPAddressVersion 属性过滤,配置格式如下:
def filter_instance(instance):
    '''
    采集 computerName 为 xxx 并且 publicIPAddressVersion 为 IPv4 的实例
    '''
    # return True
    computer_name = instance['computerName']
    public_ip = instance['publicIPAddressVersion']
    if computer_name in ['xxx'] and public_ip in ['IPv4']:
        return True
    return False


@DFF.API('Azure-vm', timeout=3600, fixed_crontab='*/15 * * * *')
def run():
    Runner(main.DataCollector(account, collector_configs, filters=[filter_instance])).run()

3. 数据上报格式

数据正常同步后,可以在观测云的「基础设施 / 自定义(对象)」中查看数据。

上报的数据示例如下:

JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
  "measurement": "azure_vm",
  "tags": {
    "PowerState"                        : "running",
    "ProvisioningState"                 : "succeeded",
    "adminUsername"                     : "zyadmin",
    "computerName"                      : "xxxx1",
    "hardwareProfile_vmSize"            : "Standard_B1s",
    "location"                          : "canadacentral",
    "name"                              : "/subscriptions/xxxx1",
    "privateIPAddress"                  : "10.0.0.5",
    "privateIPAddressVersion"           : "IPv4",
    "publicIPAddressVersion"            : "IPv4",
    "publicipAddress"                   : "20.151.160.181",
    "storageProfile_diskControllerType" : "SCSI",
    "storageProfile_osDisk_osType"      : "Linux",
    "type"                              : "Microsoft.Compute/virtualMachines",
    "vmId"                              : "xxx",
    "zone"                              : "1"
  },
  "fields": {
    "storageProfile_osDisk_diskSizeGB": 30,
    "timeCreated"                     : "2023-10-11T07:20:06.8185073+00:00",
    "networkInterfaces"               : "{网络 JSON 数据}",
    "instanceView"                    : "{运行状态 JSON 数据}",
    "message"                         : "{实例 JSON 数据}"
  }
}

tags、fields 中的字段可能会随后续更新有所变动

tags.name 值为实例 ID,作为唯一标识

fields.message、fields.networkInterfaces、fields.instanceView 均为 JSON 序列化后字符串

X. 附录

请参考 Azure 官方文档: