builder.Services.AddSingleton<OrderMetrics>();
// OpenTelemetry sẽ tự collect từ Meter name đã đăng ký
builder.Services.AddOpenTelemetry()
.WithMetrics(m => m.AddMeter("OrderService.Metrics"));
Grafana vs Azure Dashboard
Tiêu chí
Grafana
Azure Dashboard
Data sources
50+ (Prometheus, Loki, Tempo, SQL...)
Azure Monitor, Log Analytics
Flexibility
Rất cao - custom panels, plugins
Trung bình - limited widgets
Cost
Free (self-host) / Grafana Cloud
Included với Azure subscription
Alerting
Grafana Alerting - powerful routing
Azure Monitor Alerts
Learning curve
PromQL/LogQL cần thời gian
KQL dễ hơn cho Azure users
Team collab
Dashboard as Code (JSON)
ARM templates / Bicep
Best for
Multi-cloud, complex dashboards
Azure-native stacks
Dashboard Design Principles
Level 1: Business KPIs → Revenue, Active Users, Conversion Rate
Level 2: Service Health → Latency P99, Error Rate, Throughput
Level 3: Infrastructure → CPU, Memory, Disk, Network
Level 4: Debug → Individual traces, logs, spans
Alert Design - Tránh Alert Fatigue
Phân loại Alerts
Severity
Response Time
Ví dụ
Action
P1 - Critical
< 15 phút
Service down, data loss
Page on-call engineer
P2 - High
< 1 giờ
Error rate > 5%, latency degraded
Page during business hours
P3 - Medium
< 4 giờ
Disk > 80%, cert expiring 7 days
Slack notification
P4 - Low
Next business day
Non-critical warnings
Email / ticket
Nguyên tắc Alert Hiệu quả
yaml
# Mỗi alert PHẢI có:alert_name:"OrderService High Error Rate"description:"Error rate vượt 5% trong 5 phút liên tục"severity:P2runbook_url:"https://wiki.internal/runbooks/order-high-error-rate"dashboard_url:"https://grafana.internal/d/order-service"escalation_policy:"backend-oncall"