跳转至

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

阅读本文前,请先阅读:

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

为了保证数据的完整性,所采集的账单数据为采集日期前一天的数据

采集器需要在 extra_tags 中设置 billing_account_name 及 billing_account_id

首次执行采集器前需要在 亚马逊云科技控制台 / Amazon Cost Explorer / 成本管理 / 首选项 中勾选 Hourly and Resource Level Data,并等待24小时才可获取到数据

1. 配置结构

本采集器无需额外配置

2. 数据上报格式

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

上报的数据示例如下:

JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
  "measurement": "cloud_billing_by_instance",
  "tags": {
    "billing_product_code": "Amazon Elastic Compute Cloud - Compute",
    "billing_product_name": "Amazon Elastic Compute Cloud - Compute",
    "name"                : "i-xxxxxxxx",
    "billing_date"        : "2022-09-09",
    "billing_timestamp"   : "1657507021",
    "cloud_provider"      : "aws",
    "billing_account_id"  : "xxxxxx",
    "billing_account_name": "xxxxxx"
  },
  "fields": {
    "billing_amount"        : 9419.23
  },
  "timestamp": 1657507021
}

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

3. 字段说明

上报字段 API 返回字段 API 字段含义
实付金额 billing_amount BlendedCost 用户支付价格
产品代码 billing_product_code 产品代码
产品名称 billing_product_name 产品名称
实例 ID name 实例ID
账期 billing_date 资源消费记录的日期。格式:YYYY-MM-DD
账期 billing_timestamp 资源消费记录的日期。格式:YYYY-MM-DD
账号名称 billing_account_name 账号名称
账号 ID billing_account_id 账号 ID

4. 与自定义对象采集器联动

当同一个 DataFlux Func 中运行了其他自定义对象采集器(如 EC2、RDS)时,本采集器会自动根据 name 字段尝试匹配自定义对象中的 tags.name 字段。当成功匹配后,会将所匹配的自定义对象 tags 中除 name 以外的字段加入到账单数据的 tags 中。

假设账单采集到的原始数据如下:

JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
  "measurement": "cloud_billing_by_instance",
  "tags": {
    "billing_product_code": "ec2",
    "billing_product_name": "Amazon Elastic Compute Cloud - Compute",
    "name"                : "i-xxxxxxxx",
    "billing_date"        : "2022-09-09",
    "billing_timestamp"   : "1657507021",
    "cloud_provider"      : "aws",
    "billing_account_id"  : "xxxxx",
    "billing_account_name": "xxxxx"
  },
  "fields": {
    "billing_amount": 9419.23
  },
  "timestamp": 1657507021
}

同时,AWS EC2 采集器采集到的自定义对象数据如下:

JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
  "measurement": "aws_ec2",
  "tags": {
    "name"       : "i-xxxxxxxx",
    "InstanceId" : "i-xxxxxxxx",
    "RegionId"   : "cn-hangzhou",
    "{其他字段}" : "{略}"
  },
  "fields": {
    "{其他字段}": "{略}"
  }
}

那么,最终上报的账单数据如下:

JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
{
"measurement": "cloud_billing_by_instance",
  "tags": {
    "InstanceId"          : "i-xxxxxxxx",
    "RegionId"            : "cn-hangzhou",
    "billing_product_code": "ec2",
    "billing_product_name": "Amazon Elastic Compute Cloud - Compute",
    "name"                : "i-xxxxxxxx",
    "billing_date"        : "2022-09-09",
    "cloud_provider"      : "aws",
    "billing_account_id"  : "xxxxx",
    "billing_account_name": "xxxxx",
    "{其他字段}"          : "{略}"
  },
  "fields": {
    "billing_amount": 9419.23,
  },
  "timestamp": 1657507021
}

5. 云账单调用次数说明

AWS Cost Explorer API 调用收费为每个分页收费 $0.01。以下对脚本集调用次数做出详细解释:

. 通过查看任务执行日志,找到真实调用次数:

采集器对任务每次执行结果所调用的 API 次数有统计,可以在日志中查看,例:

Bash
1
2
3
4
[2023-07-04 11:35:18.497] [+0ms] 第【1】个账号采集完毕,共执行【759毫秒】,期间调用API【2次】
[2023-07-04 11:35:18.498] [+0ms] 详细调用如下:
[2023-07-04 11:35:18.498] [+0ms] -> ce.cn-northwest-1.amazonaws.com.cn/?Action=get_dimension_values: 1[2023-07-04 11:35:18.498] [+0ms] -> ce.cn-northwest-1.amazonaws.com.cn/?Action=get_cost_and_usage_with_resources: 1

6. IAM 策略权限

如果用户使用带入 IAM 角色的方式采集资源,需要开启一定的操作权限

该采集器需要如下操作权限:

ce:GetDimensionValues

ce:GetCostAndUsageWithResources

附录

AWS-账单管理「查询实例账单服务」