콘텐츠로 이동

2026 01 28

2026-01-28

ELK 수집 지연 개선

  • 개요
    • Filebeat(Sidecar) -> Logstash -> Elasticsearch
    • 어플리케이션에서 로그 찍히고 30~60초 후에 키바나에서 조회 가능 -> 개선 후 2~3초 조회로 개선
    • 준 실시간성으로 해당 로그를 확인해야 하는 요구사항
    • @timestamp vs logstashTimestamp vs ES 조회시점 비교하여 병목 지점 개선
  • 병목 1. 수집
    • Filebeat의 수집 및 전송 지연
    • Polling 주기: scan_frequency 설정 값이 없으면 기본 10초마다 로그 파일을 감지
    • Buffering: 로그 양이 적은 경우, queue 찰 때까지 기다리거나 타임아웃 될 때 까지 전송 대기
    • configmap 내 filebeat.yml 수정
      data:
        filebeat.yml: |
          filebeat.inputs:
      
          - type: log
            paths:
      
              - /app/logs/application.log
            json.keys_under_root: true
            json.overwrite_keys: true
            json.add_error_key: true
            tail_files: true
            scan_frequency: 1s   # 파일 변경 감지 주기
          queue.mem:
            events: 4096
            flush.min_events: 0  # 0개여도 즉시 전송
            flush.timeout: 0.5s  # 0.5초 경과시 무조건 전송
      
  • 병목 2. 조회

    • 검색 갱신 주기 refresh_interval 1초로 단축 (기존 60초)
    • 현재 인덱스는 바로 변경
      PUT /application-*/_settings
      {
        "index": { "refresh_interval": "1s" }
      }
      
    • 인덱스 템플릿 수정
      PUT /_template/application
      {
        "order": 9,
        "index_patterns": ["application-*"],
        "settings": {
          "index": { "refresh_interval": "1s" }
        },
        # ... (기존 mappings 유지)
      }