본문 바로가기
WIKI 기술 지식 베이스

Deriving metrics from logs

원문 보기 위키 갱신

출처: 문서

본문

로그에서 메트릭 도출하기

OpenSearch Data Prepper를 사용하면 로그에서 메트릭을 도출할 수 있어요.

다음 예제 파이프라인은 http 소스 플러그인과 grok 프로세서를 사용해 들어오는 로그를 받아요. 그다음 aggregate 프로세서를 사용해 30초 윈도우 동안 집계된 메트릭 바이트를 추출하고, 그 결과로부터 히스토그램을 도출해요.

이 파이프라인은 서로 다른 두 개의 OpenSearch 인덱스에 데이터를 기록해요:

  • logs: 이 인덱스는 grok 프로세서로 처리된 이후의, 집계되지 않은 원본 로그 이벤트를 저장해요.
  • histogram_metrics: 이 인덱스는 aggregate 프로세서를 사용해 로그 이벤트에서 추출한 도출된 히스토그램 메트릭을 저장해요.

파이프라인은 두 개의 서브 파이프라인으로 구성돼요:

  • apache-log-pipeline-with-metrics: FluentBit 같은 HTTP 클라이언트를 통해 로그를 받고, 로그 키의 값을 Apache Common Log Format과 대조하는 방식으로 grok을 사용해 로그에서 중요한 값을 추출해요. 그다음 그루킹된 로그를 두 곳으로 전달해요:

  • 원본 로그 이벤트를 저장하는 logs라는 이름의 OpenSearch 인덱스.

  • 추가 집계와 메트릭 도출을 담당하는 log-to-metrics-pipeline.

  • log-to-metrics-pipeline: apache-log-pipeline-with-metrics 파이프라인에서 그루킹된 로그를 받아 로그를 집계하고, clientip과 request 키의 값을 기반으로 바이트에 대한 히스토그램 메트릭을 도출해요. 마지막으로 도출된 히스토그램 메트릭을 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"

{% include copy-curl.html %}

더 알아보기 (Learn more)