Golden Signals SRE Monitoring Layer
As Sherlock, I've deduced this request pertains to implementing a robust Site Reliability Engineering (SRE) monitoring layer based on the Four Golden Signals (Latency, Traffic, Errors, Saturation), extended with alerting . This layer is designed for a typical microservices or web application stack (e.g., using Prometheus for metrics collection, Grafana for dashboards, and Alertmanager for notifications).
I'll provide:
Metric definitions (Prometheus-style queries).
Dashboard panels (Grafana-inspired).
Alert rules (Prometheus alerting rules YAML).
Integration overview .
This is production-ready, customizable, and assumes metrics like http_requests_total, http_request_duration_seconds, CPU/memory from node_exporter/cAdvisor.
1. Latency
Definition : Time taken to serve a request (e.g., p50, p95, p99 percentiles). Focus on user-perceived latency.
Key Metrics (Prometheus queries):
code Copy code
latency_p50: histogram_quantile(0.50, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))
latency_p95: histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))
latency_p99: histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))
Grafana Dashboard Panel :
Type: Time series graph.
Visualization: Multiple lines (p50 blue, p95 orange, p99 red).
Unit: Seconds.
Alert Rules (YAML snippet):
yaml Copy code
- alert: HighLatencyP99
expr: histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le)) > 2
for: 5m
labels:
severity: critical
annotations:
summary: "P99 latency high ({{ $value }}s)"
description: "Latency at 99th percentile exceeds 2s."
2. Traffic
Definition : Request volume or throughput (requests/sec or bytes/sec).
Key Metrics :
code Copy code
traffic_reqps: sum(rate(http_requests_total[5m]))
traffic_bytesps: sum(rate(http_server_bytes_total[5m])) # If tracking bytes
Grafana Dashboard Panel :
Type: Time series graph.
Visualization: Area chart (reqps).
Unit: Requests/second.
Alert Rules :
yaml Copy code
- alert: TrafficSpike
expr: sum(rate(http_requests_total[5m])) > 10000 # Threshold: 10k req/s
for: 2m
labels:
severity: warning
annotations:
summary: "Traffic spike ({{ $value }} req/s)"
- alert: TrafficDrop
expr: sum(rate(http_requests_total[5m])) < 100 # Threshold: 100 req/s
for: 10m
labels:
severity: warning
annotations:
summary: "Traffic drop ({{ $value }} req/s)"
3. Errors
Definition : Fraction of failed requests (4xx/5xx errors).
Key Metrics :
code Copy code
error_rate: sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m])) * 100
error_total: sum(increase(http_requests_total{status=~"5.."}[5m]))
Grafana Dashboard Panel :
Type: Stat panel (current error %).
Visualization: Gauge (green <1%, yellow 1-5%, red >5%).
Thresholds: 0-1% OK, 1-5% Warning, >5% Critical.
Alert Rules :
yaml Copy code
- alert: HighErrorRate
expr: sum(rate(http_requests_total{status=~"5.."}[5m])) / sum(rate(http_requests_total[5m])) * 100 > 5
for: 5m
labels:
severity: critical
annotations:
summary: "Error rate high ({{ $value }}%)"
4. Saturation
Definition : Resource utilization nearing capacity (CPU >80%, Memory >80%, Connection pool exhaustion).
Key Metrics (from node_exporter/cAdvisor):
code Copy code
cpu_saturation: 100 - (avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
memory_saturation: (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100
conn_saturation: (process_open_fds / process_max_fds) * 100 # App-specific
Grafana Dashboard Panel :
Type: Time series graph (multi-line: CPU, Mem, Conn).
Visualization: Stacked area.
Unit: Percentage.
Alert Rules :
yaml Copy code
- alert: HighCPUSaturation
expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "CPU saturation high ({{ $value }}%) on {{ $labels.instance }}"
- alert: HighMemorySaturation
expr: (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100 > 85
for: 5m
labels:
severity: critical
annotations:
summary: "Memory saturation high ({{ $value }}%)"
5. Alerts Integration
Full Prometheus Alerting Rules File (golden-signals-rules.yml):
yaml Copy code
groups:
- name: golden-signals
rules:
# Paste all alert rules from above here
Alertmanager Config (snippet for routing/notifications):
yaml Copy code
route:
group_by: ['alertname', 'job']
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
receiver: 'team-sre-slack' # e.g., Slack, PagerDuty
receivers:
- name: 'team-sre-slack'
slack_configs:
- api_url: 'https://hooks.slack.com/services/...'
channel: '#sre-alerts'
text: 'Golden Signal Alert: {{ .CommonAnnotations.summary }}'
Severity Tiers :
Critical (Page): Latency P99 >2s, Errors >5%, Mem >90%.
Warning (Ticket): Traffic anomalies, CPU >80%, other thresholds.
Info (Log): Minor blips.
Overall SRE Layer Architecture
code Copy code
App → Prometheus (scrape metrics) → Grafana (dashboards) → Alertmanager (alerts) → PagerDuty/Slack
↓
SLOs (e.g., 99.9% availability = (1 - errors) * latency SLO)
Grafana Dashboard JSON :
Create a single "Golden Signals" dashboard with 2x2 grid:
Latency Traffic Errors Saturation
SLO Computation (Prometheus query for dashboard):
code Copy code
slo_availability: (1 - sum(rate(http_requests_total{status=~"5.."}[1h])) / sum(rate(http_requests_total[1h]))) * 100
Deployment Steps :
Deploy Prometheus with these scrape configs.
Load golden-signals-rules.yml into Prometheus.
Import Grafana dashboard (use queries above).
Configure Alertmanager receivers.
Set SLO burn rates for error budgets.
This layer provides observability-first SRE : Monitor → Alert → Act. Customize thresholds for your workload. If you need full YAML/JSON exports or Kubernetes manifests (e.g., via Helm), provide more details!