Giám sát hệ thống vận hành với Prometheus và Grafana

Xây dựng hệ thống monitoring toàn diện cho hạ tầng sản xuất: từ cài đặt Prometheus, viết PromQL đến thiết kế dashboard Grafana và cấu hình cảnh báo.

DevOps 10 phút đọc
#prometheus #grafana #monitoring #observability
Trang Chủ / Blog /Giám sát hệ thống vận hành với Prometheus và Grafana
ANSOL 10 phút đọc

Vì sao Monitoring quan trọng

Một hệ thống vận hành không có monitoring giống như lái xe ban đêm không có đèn pha. Bạn chỉ biết có vấn đề khi đã va chạm.

Kiến trúc tổng quan

[Application] → [Prometheus Exporter] → [Prometheus] → [Grafana]
                                               ↓
                                        [Alertmanager] → [Slack/PagerDuty]

Cài đặt Prometheus với Docker Compose

services:
  prometheus:
    image: prom/prometheus:latest
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"
  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"

PromQL hữu ích

# Request rate trong 5 phút qua
rate(http_requests_total[5m])

# 95th percentile latency
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))

# Error rate
sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m]))

Kết luận

Hãy bắt đầu với 4 golden signals: Latency, Traffic, Errors, Saturation. Đây là nền tảng mọi hệ thống monitoring production cần có.

Vận hành hiệu quả bắt đầu từ việc nhìn thấy thực tế rõ ràng.