4 Golden Signals
Google SRE đề xuất 4 tín hiệu vàng cần giám sát cho mọi service:
| Signal | Đo gì | Ví dụ cảnh báo |
|---|---|---|
| Latency | Thời gian phản hồi | p95 > 500ms trong 5 phút |
| Traffic | Lượng request | RPS giảm 50% so với cùng giờ hôm qua |
| Errors | Tỷ lệ lỗi | 5xx > 1% tổng request |
| Saturation | Mức sử dụng tài nguyên | CPU > 80% trong 10 phút |
Prometheus + Grafana
Prometheus thu thập metrics từ ứng dụng theo kiểu pull (kéo dữ liệu). Grafana vẽ dashboard từ metrics đó. Combo này miễn phí, mạnh, và là tiêu chuẩn ngành.
// File: metrics.js
import promClient from 'prom-client'
// Đếm số request theo route và status
const httpRequests = new promClient.Counter({
name: 'http_requests_total',
help: 'Total HTTP requests',
labelNames: ['method', 'route', 'status'],
})
// Đo thời gian phản hồi
const httpDuration = new promClient.Histogram({
name: 'http_request_duration_seconds',
help: 'HTTP request duration in seconds',
labelNames: ['method', 'route'],
buckets: [0.01, 0.05, 0.1, 0.5, 1, 5],
})
// Middleware đo metrics
app.use((req, res, next) => {
const end = httpDuration.startTimer({ method: req.method, route: req.path })
res.on('finish', () => {
end()
httpRequests.inc({ method: req.method, route: req.path, status: res.statusCode })
})
next()
})
Alerting: cảnh báo đúng lúc, không spam
Alert phải actionable: nhận được → biết phải làm gì. Alert quá nhiều = alert fatigue → bỏ qua hết. Phân level: Critical (gọi điện), Warning (Slack), Info (dashboard).
CPU > 50% → KHÔNG alert (bình thường). CPU > 90% trong 10 phút → WARNING. Service chết → CRITICAL. Quy tắc: nếu nhận alert mà không cần làm gì → xoá alert đó.
❓ Trong 4 Golden Signals, "Saturation" đo gì?
- Nói được 4 Golden Signals
- Thiết lập Prometheus metrics trong Node.js
- Hiểu Grafana dashboard cơ bản
- Thiết kế alert không spam