Link Search Menu Expand Document Documentation Menu

从日志中派生指标

您可以使用 OpenSearch Data Prepper 从日志中派生指标。

以下示例管道使用 http 源插件grok 处理器接收传入日志。然后它使用 aggregate 处理器提取在 30 秒窗口内聚合的指标字节,并从结果中派生直方图。

此管道将数据写入两个不同的 OpenSearch 索引:

  • logs:此索引存储经过 grok 处理器处理后的原始、未聚合的日志事件。
  • histogram_metrics:此索引存储使用 aggregate 处理器从日志事件中提取的派生直方图指标。

该管道包含两个子管道:

  • apache-log-pipeline-with-metrics:通过 FluentBit 等 HTTP 客户端接收日志,使用 grok 通过将日志键中的值与 Apache Common Log Format 匹配,从日志中提取重要值。然后它将经过 grok 处理的日志转发到两个目的地:

  • 一个名为 logs 的 OpenSearch 索引,用于存储原始日志事件。
  • 名为 log-to-metrics-pipeline 的子管道,用于进一步聚合和指标派生。

  • log-to-metrics-pipeline:从 apache-log-pipeline-with-metrics 管道接收经过 grok 处理的日志,聚合这些日志,并根据 clientiprequest 键中的值派生字节的直方图指标。最后,它将派生的直方图指标发送到名为 histogram_metrics 的 OpenSearch 索引。

示例管道

apache-log-pipeline-with-metrics:
  source:
    http:
      # Provide the path for ingestion. ${pipelineName} will be replaced with pipeline name configured for this pipeline.
      # In this case it would be "/apache-log-pipeline-with-metrics/logs". This will be the FluentBit output URI value.
      path: "/${pipelineName}/logs"
  processor:
    - grok:
        match:
          log: [ "%{COMMONAPACHELOG_DATATYPED}" ]
  sink:
    - opensearch:
        ...
        index: "logs"
    - pipeline:
        name: "log-to-metrics-pipeline"
        
log-to-metrics-pipeline:
  source:
    pipeline:
      name: "apache-log-pipeline-with-metrics"
  processor:
    - aggregate:
        # Specify the required identification keys
        identification_keys: ["clientip", "request"]
        action:
          histogram:
            # Specify the appropriate values for each of the following fields
            key: "bytes"
            record_minmax: true
            units: "bytes"
            buckets: [0, 25000000, 50000000, 75000000, 100000000]
        # Pick the required aggregation period
        group_duration: "30s"
  sink:
    - opensearch:
        ...
        index: "histogram_metrics"

剩余 350 字符

有问题?

想贡献代码?