将不同LogStore的日志数据汇总到一个LogStore

更新时间:
复制为 MD 格式

日志服务支持对每一个源LogStore配置一个数据加工任务,实现多源LogStore的数据汇总到同一个LogStore。本文介绍多源LogStore数据汇总的典型应用场景和操作步骤。

背景信息

某资讯网站业务分布全球,不同资讯频道的用户访问日志被采集存储在阿里云不同账号中的LogStore,如果需要将日志数据汇总到一个LogStore,便于后续的查询与分析,可以使用e_output函数进行数据加工。

本文以同一目标区域英国(伦敦)的不同LogStore的日志为例,介绍汇总LogStore数据的操作步骤:

  • 账号1中的原始日志,其Project地域位于英国(伦敦),Project名称为Project_1,LogStore名称为LogStore_1。

    "日志1"
    request_id: 1
    http_host:  example.com
    http_status:  200
    request_method:  GET
    request_uri:  /pic/icon.jpg
    
    "日志2"
    request_id: 2
    http_host:  aliyundoc.com
    http_status:  301
    request_method:  POST
    request_uri:  /data/data.php
  • 账号2中的日志,其Project地域为英国(伦敦),Project名称为Project_2,LogStore名称为LogStore_2。

    "日志1"
    request_id: 3
    host:  example.edu
    status:  404
    request_method:  GET
    request_uri:  /category/abc/product_id
    
    "日志2"
    request_id: 4
    host:  example.net
    status:  200
    request_method:  GET
    request_uri:  /data/index.html
  • 加工目标

    • 将账号1LogStore_1中所有http_status200的日志事件,输出到账号3LogStore_3中。

    • 对于账号2LogStore_2中所有http_status200的日志事件,将字段名称host改为http_host、字段名称status改为http_status(与LogStore1统一),然后输出到账号3LogStore_3中。

步骤一:配置LogStore1的数据加工规则

  1. 进入账号1LogStore_1的数据加工页面,控制台操作步骤请参见创建数据加工任务

  2. 在数据加工页面,配置如下加工规则,将账号1LogStore_1中所有http_status200的日志事件,输出到账号3LogStore_3中。

    e_if(e_match("http_status", "200"), e_output("target_logstore"))
  3. 创建数据加工任务,在存储目标区域,配置目标名称目标Region目标Project目标LogStore等参数如下,授权方式参数说明请参见创建数据加工任务

    加工规则

步骤二:配置LogStore2的数据加工规则

  1. 进入账号2LogStore_2的数据加工页面,控制台操作步骤请参见创建数据加工任务

  2. 在数据加工页面,配置如下加工规则。对于LogStore_2中所有http_status200的日志事件,将字段名称host改为http_host、字段名称status改为http_status(与LogStore1统一),然后输出到账号3LogStore_3中。

    e_if(e_match("status", "200"), e_compose(e_rename("status", "http_status", "host", "http_host"), e_output("target_logstore")))

    预览结果

    image

  3. 创建数据加工任务,在存储目标区域,配置目标名称目标Region目标Project目标LogStore等参数如下,授权方式参数说明请参见创建数据加工任务

    image

查看汇总结果

在英国(伦敦)地域的LogStore_3查询与分析快速指引,日志示例如下。

"日志1"
request_id: 1
http_host:  example.com
http_status:  200
request_method:  GET
request_uri:  /pic/icon.jpg

"日志2"
request_id: 4
http_host:  example.net
http_status:  200
request_method:  GET
request_uri:  /data/index.html