跳转至

采集器「Azure - 云账单(实例维度)」配置手册

阅读本文前,请先阅读:

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

为了保证数据的完整性,所采集的的账单日期为当前日期前一天,例如:2022-07-03 00:00:00 ~ 23:59:59 期间采集的都是 2022-07-02 的数据

1. 配置结构

本采集器无需配置

2. 数据上报格式

数据正常同步后,可以在观测云的「云账单查看器」中查看数据。

上报的数据示例如下:

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
[
  {
    "category": "cloud_billing",
    "fields": {
      "amount": 0.000362931030000001,
      "message": "[0.000362931030000001, 0.000362931030000001, 20241126, \"func-resource\", \"/subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/resourcegroups/func-resource/providers/microsoft.storage/storageaccounts/dffunc\", \"Storage\", \"us east\", \"ZP57-7TMW-BG7-PGB\", \"HM LU\", \"63a4a998-bd43-4cca-bd86-c4e7ed33a643\", \"Azure \\u8ba2\\u9605 1\", \"CNY\"]",
      "pre_tax_amount": 0.000362931030000001
    },
    "measurement": "cloud_billing",
    "tags": {
      "account_id": "ZP57-7TMW-BG7-PGB",
      "account_name": "HM LU",
      "billing_date": "2024-11-26",
      "billing_id": "2dcc4b206fe5b90a86540261b9aab7c103e7bff4204e2c54c022132cc7569b80",
      "billing_timestamp": "1732636799",
      "instance_id": "/subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/resourcegroups/func-resource/providers/microsoft.storage/storageaccounts/dffunc",
      "name": "/subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/resourcegroups/func-resource/providers/microsoft.storage/storageaccounts/dffunc",
      "product_code": "Storage",
      "product_name": "Storage",
      "region_id": "us east",
      "region_name": "us east",
      "resource_id": "/subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/resourcegroups/func-resource/providers/microsoft.storage/storageaccounts/dffunc",
      "subscription_id": "63a4a998-bd43-4cca-bd86-c4e7ed33a643",
      "subscription_name": "Azure 订阅 1"
    },
    "timestamp": 1732636799
  }
]

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

3. 字段说明

上报字段 API 返回字段 API 字段含义 说明
账单 ID billing_id 账单唯一 ID
产品代码 product_code ServiceName 云服务类型编码
产品名称 product_name ServiceName 云服务类型名称
实付金额 amount Cost 用户支付含税金额
实付金额(不含税) pre_tax_amount PreTaxCost 用户支付不含税金额
账期 billing_date UsageDate 资源消费记录的日期。格式:YYYYMMDD
地域 ID region_id ResourceLocation 地域 ID
地域 region_name ResourceLocation 地域名称
实例 ID instance_id ResourceId 实例 ID/ 资源 ID
消费者 ID account_id BillingProfileId 计费档案ID,用于生成独立发票。
消费者名称 account_name BillingProfileName 计费档案的名称,便于用户识别。
订阅 ID subscription_id SubscriptionId 订阅的唯一标识符,用于细分订阅级别的成本。
订阅名称 subscription_name SubscriptionName 订阅的友好名称,便于用户识别具体订阅。

脚本每次运行时数据统计颗粒度为 资源(实例)id:ResourceId;相同实例的账单消费金额会合并计算,具体可以查看下面Azure API 原始数据脚本汇总后的数据对比

Azure API 接口原始数据

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{
  "id": "subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/providers/Microsoft.CostManagement/query/3d4323d5-4408-4b3a-b81b-7f0b76679a7e",
  "name": "3d4323d5-4408-4b3a-b81b-7f0b76679a7e",
  "type": "Microsoft.CostManagement/query",
  "location": null,
  "sku": null,
  "eTag": null,
  "properties": {
    "nextLink": null,
    "columns": [
      {
        "name": "PreTaxCost",
        "type": "Number"
      },
      {
        "name": "Cost",
        "type": "Number"
      },
      {
        "name": "UsageDate",
        "type": "Number"
      },
      {
        "name": "ResourceId",
        "type": "String"
      },
      {
        "name": "ServiceName",
        "type": "String"
      },
      {
        "name": "ResourceLocation",
        "type": "String"
      },
      {
        "name": "BillingProfileId",
        "type": "String"
      },
      {
        "name": "BillingProfileName",
        "type": "String"
      },
      {
        "name": "SubscriptionId",
        "type": "String"
      },
      {
        "name": "SubscriptionName",
        "type": "String"
      },
      {
        "name": "Currency",
        "type": "String"
      }
    ],
    "rows": [
      [
        0,
        0,
        20241001,
        "/subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/providers/microsoft.insights/pricings/metricsquery",
        "Azure Monitor",
        "us east",
        "ZP57-7TMW-BG7-PGB",
        "HM LU",
        "63a4a998-bd43-4cca-bd86-c4e7ed33a643",
        "Azure 订阅 1",
        "CNY"
      ]
    ]
  }
}

脚本汇总后

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
[
  {
    "category": "cloud_billing",
    "fields": {
      "amount": 0.000362931030000001,
      "message": "[0.000362931030000001, 0.000362931030000001, 20241126, \"func-resource\", \"/subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/resourcegroups/func-resource/providers/microsoft.storage/storageaccounts/dffunc\", \"Storage\", \"us east\", \"ZP57-7TMW-BG7-PGB\", \"HM LU\", \"63a4a998-bd43-4cca-bd86-c4e7ed33a643\", \"Azure \\u8ba2\\u9605 1\", \"CNY\"]",
      "pre_tax_amount": 0.000362931030000001
    },
    "measurement": "cloud_billing",
    "tags": {
      "account_id": "ZP57-7TMW-BG7-PGB",
      "account_name": "HM LU",
      "billing_date": "2024-11-26",
      "billing_id": "2dcc4b206fe5b90a86540261b9aab7c103e7bff4204e2c54c022132cc7569b80",
      "billing_timestamp": "1732636799",
      "instance_id": "/subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/resourcegroups/func-resource/providers/microsoft.storage/storageaccounts/dffunc",
      "name": "/subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/resourcegroups/func-resource/providers/microsoft.storage/storageaccounts/dffunc",
      "product_code": "Storage",
      "product_name": "Storage",
      "region_id": "us east",
      "region_name": "us east",
      "resource_id": "/subscriptions/63a4a998-bd43-4cca-bd86-c4e7ed33a643/resourcegroups/func-resource/providers/microsoft.storage/storageaccounts/dffunc",
      "subscription_id": "63a4a998-bd43-4cca-bd86-c4e7ed33a643",
      "subscription_name": "Azure 订阅 1"
    },
    "timestamp": 1732636799
  }
]

X. 附录

Azure - 账单管理「查询资源使用记录」

请参考Azure官方文档: