Giới thiệu Stack Grafana Loki Syslog

📘 Giới thiệu

Dự án grafana‑loki‑syslog‑aio là một stack All-In-One đơn giản, mạnh mẽ để thu thập và quan sát log từ giao thức Syslog kiểu cũ (RFC 3164) vào Grafana Loki. Nó tích hợp cùng lúc các thành phần:

  • syslog‑ng: lắng nghe log RFC 3164 từ thiết bị mạng
  • Promtail: nhận log từ syslog‑ng theo định dạng RFC 5424
  • Loki: lưu trữ immutable log
  • Grafana: hiển thị, search log, tạo dashboard, chuyển log thành metrics

Ngoài ra còn có tùy chọn tích hợp monitoring (Prometheus, cAdvisor, node_exporter) và syslog‐generator để tạo log demo https://www.syslog-ng.com/community/b/blog/posts/grafana-loki-syslog-ng-jump-starting-a-new-logging-stack, https://github.com/lux4rd0/grafana-loki-syslog-aio.

🛠 Kiến trúc tổng quát

     +---------------+
     | Syslog-Device |
     | (RFC3164 via UDP:514) |
     +-------+-------+
             |
       UDP:514
             |
     +-------v-------+
     |  syslog-ng     |
     | (TCP:1514)     |
     +-------+-------+
             |
        TCP:1514
             |
     +-------v-------+
     |   Promtail     |
     | (HTTP → Loki) |
     +-------+-------+
             |
        HTTP:3100
             |
     +-------v-------+
     |     Loki       |
     +-------+-------+
             |
        UI/API
             |
     +-------v-------+
     |    Grafana     |
     | (port=3000)    |
     +---------------+

🚀 Triển khai nhanh trên Linux

Clone repository hoặc tải zip:

wget https://github.com/lux4rd0/grafana-loki-syslog-aio/archive/main.zip
unzip main.zip
cd grafana-loki-syslog-aio-main/

Khởi động full stack (bao có MinIO, monitoring):

docker-compose -f ./docker-compose.yml up -d

Các tùy chọn khác:

Truy cập Grafana tại http://<host>:3000, dashboard mặc định là Loki Syslog AIO – Overview

⚙️ Cấu hình chi tiết

File syslog‑ng.conf

syslog‑ng lắng nghe và chuyển log sang Promtail:

source s_local { internal(); };
source s_network { default-network-drivers(); };

destination d_loki {
    syslog("promtail" transport("tcp") port("1514"));
};

log {
    source(s_local);
    source(s_network);
    destination(d_loki);
};

Giúp chuyển từ RFC 3164 sang RFC 5424 để Promtail, xem tại đây.

File promtail-config.yml

server:
  http_listen_port: 9080
positions:
  filename: /tmp/positions.yaml
clients:
 - url: http://loki:3100/loki/api/v1/push

scrape_configs:
- job_name: syslog
  syslog:
    listen_address: 0.0.0.0:1514
    idle_timeout: 60s
    label_structured_data: yes
    labels:
      job: "syslog"
  relabel_configs:
    - source_labels: ['__syslog_message_hostname']
      target_label: 'host'
  • scrape_configs.syslog.listen_address: port 1514
  • label_structured_data: cho phép parse structured data
  • relabel_configs: ánh hostname từ message thành label host (dùng cho Loki indexing), xem tại đây.

📊 Dashboard & LogQL

Ví dụ truy vấn LogQL dùng trong Grafana:

count_over_time({host=~"$hostname", job="syslog"}[$__interval] |= "$filter")
  • đếm log theo host, lọc theo biến $filter, hiển thị số log theo thời gian (xem tại đây).

Cho phép tạo dropdown filter, xem dạng free‑form filter, chọn host,… rất tiện.

📈 Monitoring stack

Stack còn tích hợp các service monitoring:

🧪 Tạo log ví dụ (tùy chọn)

Nếu chưa có device gửi log, bạn có thể sử dụng container syslog-generator trong docker-compose-with-generator.yml, giúp sinh log INFO/WARN/ERROR giả định từ nhiều host khác nhau.

✅ Tóm tắt

Thành phầnVai trò
syslog-ngChuyển RFC 3164 sang RFC 5424
PromtailNhận syslog, đính nhãn, đẩy log vào Loki
LokiLưu trữ log không biến đổi
GrafanaHiển thị, search, dashboard, alert
Prometheus stack (tùy)Giám sát hiệu suất và container

Bạn dễ dàng tuỳ biến:

  • Thay MinIO bằng file system
  • Thay đổi cấu hình access key
  • Thêm monitoring hoặc generator theo nhu cầu

📝 Kết luận

Dự án grafana‑loki‑syslog‑aio là giải pháp tuyệt vời cho môi trường homelab hoặc POC:

  • Cài đặt nhanh chóng, config sẵn
  • Hỗ trợ cả log cũ và mới
  • Cho phép tích hợp monitoring đầy đủ
  • Có syslog-generator để demo
  • Đáp ứng nhu cầu log→metrics, alert…

Bạn có thể dùng trực tiếp hoặc làm nền tảng để mở rộng (thêm alert rules, lưu trữ lâu dài, High Availability, bảo mật,…).

Bài viết gần đây

spot_img

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Đăng ký nhận thông tin bài viết qua email