跳转至

采集器「阿里云-账单」配置手册

阅读本文前,请先阅读:

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

为了保证数据的完整性,所采集的的账单日期为当前日期 - 2 天,即:2022-07-03 00:00:00 ~ 23:59:59 期间采集的都是 2022-07-01 的数据。,建议本脚本每天运行一次

程序已内置防重复采集处理,同一天内反复运行时,除当天第一次运行,后续执行都会自动跳过

1. 配置结构

本采集器无需配置

2. 数据上报格式

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

上报的数据示例如下:

JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
  "measurement": "cloud_bill",
  "tags": {
    "product_code": "ecs",
    "product_name": "云服务器 ECS",
    "account_id"  : "1234xxxxxx999",
    "account_name": "xxxxx",
  },
  "fields": {
    "amount"        : 9419.23,
    "offical_amount": 18843.258604
  },
  "timestamp": 1657507021
}

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

3. 统计说明

字段 上报字段 阿里云 API 返回字段 说明
产品代码 product_code ProductCode
产品名称 product_name ProductName
账号名称 account_name AccountName
账号ID account_id AccountID
原价 offical_amount PretaxGrossAmount 相同产品代码的PretaxGrossAmount 累加所得
应付金额 amount PretaxAmount 相同产品代码的 PretaxAmount 累加所得
账单日期 timestamp BillingDate

数据统计颗粒度为 产品代码:ProductCode;相同类型的账单消费金额会合并计算,具体可以参考阿里云 API 原始数据脚本汇总后的数据对比

为了保证数据的完整上报,采集器采集的的日期为两天前,比如采集器运行日期为 2022-07-03,采集器采集 2022-07-01 的数据

阿里云 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
[
  {
    "BillingDate"      : "2022-xx-xx",
    "ProductCode"      : "oss",
    "ProductName"      : "块存储",
    "PretaxAmount"     : 0.12,
    "PretaxGrossAmount": 0.22,
    "account_id"       : "1234xxxxxx999",
    "account_name"     : "xxxxx",
    "{其他字段}"       : "{略}"
  },
  {
    "BillingDate"      : "2022-xx-xx",
    "ProductCode"      : "oss",
    "ProductName"      : "块存储",
    "PretaxAmount"     : 0.22,
    "PretaxGrossAmount": 0.32,
    "account_id"       : "1234xxxxxx999",
    "account_name"     : "xxxxx",
    "{其他字段}"       : "{略}"
  },
  {
    "BillingDate"      : "2022-xx-xx",
    "ProductCode"      : "snapshot",
    "ProductName"      : "块存储",
    "account_id"       : "1234xxxxxx999",
    "account_name"     : "xxxxx",
    "PretaxAmount"     : 0.02,
    "PretaxGrossAmount": 0.02,
    "{其他字段}"       : "{略}"
  }
]

脚本汇总后

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
[
  {
    "measurement": "cloud_bill",
    "tags": {
      "product_code": "oss",
      "product_name": "块存储",
      "account_id"  : "1234xxxxxx999",
      "account_name": "xxxxx",
    },
    "fields": {
      "amount"        : 0.34,
      "offical_amount": 0.54,
      "account_id"    : "1234xxxxxx999",
      "account_name"  : "xxxxx",
    },
    "timestamp": 1657507021
  },
  {
    "measurement": "cloud_bill",
    "tags": {
      "product_code": "snapshot",
      "product_name": "块存储",
      "account_id"  : "1234xxxxxx999",
      "account_name": "xxxxx",
    },
    "fields": {
      "amount"        : 0.02,
      "offical_amount": 0.02
    },
    "timestamp": 1657507021
  }
]

附录

阿里云-账单管理「查询实例账单服务」