Lightweight

Kịch bản 2 Multiple receivers → Single exporter

Hướng dẫn cấu hình nhiều nguồn log gửi tới một destination

Tổng quan

Kịch bản này được áp dụng khi người dùng cần thu thập đồng thời nhiều loại log khác nhau phát sinh từ các dịch vụ hoặc ứng dụng độc lập trên cùng một máy chủ, sau đó tập trung toàn bộ dữ liệu này để gửi về một điểm nhận duy nhất trên hệ thống.

Cấu hình chi tiết

1. Receivers (Bộ nhận) - Nhiều nguồn

Người dùng cần định nghĩa nhiều receiver với tên khác nhau để phân biệt loại log.

receivers:
  filelog/app:                    # Receiver 1: Application logs
    include:
      - /home/bacnt/logs/*.log    # Collect từ thư mục ứng dụng
    start_at: end
    include_file_path: true       # Thêm đường dẫn file
    include_file_name: false

  filelog/syslog:                 # Receiver 2: System logs
    include:
      - /var/log/syslog           # Collect từ syslog
    start_at: end
    include_file_path: true
    include_file_name: false

  filelog/auth:                   # Receiver 3: Authentication logs
    include:
      - /var/log/auth.log         # Collect từ auth log
    start_at: end
    include_file_path: true
    include_file_name: false

Quy tắc đặt tên Receiver:

  • Format: <loại>/<tên_logic> (ví dụ: filelog/app, syslog/windows)
  • Sử dụng tên có ý nghĩa để dễ quản lý
  • Mỗi receiver phải có tên duy nhất

2. Processors

Đọc chi tiết

3. Exporters (Bộ gửi) - Một điểm đến

exporters:
  otlphttp:
    endpoint: ${OTLP_ENDPOINT}
    logs_endpoint: ${OTLP_ENDPOINT}
    headers:
      x-api-key: ${OTLP_API_KEY}
      Content-Type: "application/json"
    timeout: 30s
    encoding: json

Lưu ý: Tất cả receiver sẽ gửi log tới một exporter này duy nhất.

4. Service Pipeline (Đường ống xử lý)

service:
  pipelines:
    logs:
      receivers: [filelog/app, filelog/syslog, filelog/auth]  # Liệt kê tất cả receiver
      exporters: [otlphttp]                                   # Một exporter

Ví dụ thực tế

Ví dụ: Collect từ 3 nguồn log khác nhau

receivers:
  filelog/app:
    include:
      - /opt/myapp/logs/*.log
    start_at: end
    include_file_path: true
    include_file_name: true

  filelog/system:
    include:
      - /var/log/syslog
      - /var/log/messages
    start_at: end
    include_file_path: true
    include_file_name: false

  filelog/auth:
    include:
      - /var/log/auth.log
      - /var/log/secure
    start_at: end
    include_file_path: true
    include_file_name: false

exporters:
  otlphttp:
    endpoint: https://secops.company.com:4317
    logs_endpoint: https://secops.company.com:4317
    headers:
      x-api-key: sk_live_multi_receiver_key
      Content-Type: "application/json"
    timeout: 30s
    encoding: json

service:
  pipelines:
    logs:
      receivers: [filelog/app, filelog/system, filelog/auth]
      exporters: [otlphttp]

Lưu ý

  • Đặt tên receiver rõ ràng: Giúp dễ debug khi có vấn đề.
  • Kiểm tra quyền file: Sensor phải có quyền đọc tất cả file log.
  • Wildcard matching: Sử dụng *.log để match nhiều file cùng lúc.
  • Performance: Nếu quá nhiều receiver/file, có thể ảnh hưởng hiệu suất; hãy tối ưu bằng filtering.
  • Backup: Nếu một receiver gặp lỗi, các receiver khác vẫn hoạt động bình thường.