๐ฏ Problem Statement# Modern Kubernetes environments face observability challenges:
Visibility Gap - No centralized view of cluster and application healthTroubleshooting - Difficulty correlating metrics, logs, and tracesAlert Fatigue - Too many false positives or missing critical alertsCost - Expensive commercial APM solutionsScalability - Monitoring solution must scale with the cluster๐ก Solution Overview# I designed and deployed a comprehensive open-source observability stack using Prometheus, Grafana, Loki, and Tempo, providing metrics, logs, traces, and alerting in a unified platform.
๐๏ธ Architecture# โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ A / โ โ โ โ โ โ โ โ โ p m โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ p e โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ t โฌ โผ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ A r โ โ โ โ โ - - - โ โ - - โ โ โ โ โ โ โ โ โ โ ( โ โ โ โ โ โ โ โ โ i โ โ โ โ โ โ โ โ โ โ โ โ โ L โ โ - โ โ โ โ โ โ โ c โ โ โ โ โ S R A โ โ R S โ โ โ D - - - โ โ โ o โ โ โ โ โ โ โ โ โ s โ โ โ โ โ e e l โ โ o l โ โ โ a โ โ โ g โ โ C โ โ โ โ โ โ โ โ โ โ โ โ โ โ r c e โ โ u a โ โ โ t P L T โ โ โ โ โ o โ โ โ โ โ โ โ โ โ โ v o r โ โ t c โ โ โ a r o e โ โ โ L A โ โ l โ โ โ โ โ โ โ โ โ โ โ โ โ O โ i r t โ โ i k โ โ โ o k m โ โ โ o g โ โ l โ โ โ โ โ โ โ โ โ โ โ b โ c d โ โ n / โ โ โ S m i p โ โ โ k g โ โ e โ โ โ โ โ โ โ A / โ โ โ โ s โ e i R โ โ g P โ โ โ o e o โ โ โ i r โ โ P c โ โ โ โ K โ โ โ p m โ โ โ โ e โ P M n u โ โ A a โ โ โ u t ( โ โ โ e โ โ r t โ โ โ โ u โ โ โ p e โ โ โ โ r โ r o g l โ โ l g โ โ โ r h L ( โ โ โ g โ โ o s โ โ โ โ b โ โ โ t โฌ โผ โ โด โ v โ o n e โ โ e e โ โ โ c e o T โ โ โ a โ โ m โ โ โ โ e โ โ A โ B r โ โ โ โ a โ m i R s โ โ r r โ โ G โ e u g r โ โ โ t โ โ t l โ โ โ โ r โ โ p โ i โ โ โ โ b โ e t u โ โ t D โ โ r โ s s s a โ โ โ i โ โ a o โ โ โ โ n โ โ p โ c โ โ โ โ i โ t o l โ โ m u โ โ a โ : ) c โ โ โ o โ โ i g โ โ โ โ e โ โ l โ s โ โ โ โ l โ h r e โ โ a t โ โ f โ ( e โ โ โ n โ โ l s โ โ โ โ t โ โ i โ โ โ โ โ โ โ i โ e s โ โ n y โ โ a โ M s โ โ โ ) โ โ โ โ โ โ e โ โ c โ โฌ โ โผ t โ โผ u C โฌ โ โผ a โ โ n โ e ) โ โ โ โ โ โ โ โ ( f โ โ โ โ s โ โ a โ โ โ โ โ โ โ y โ s R โ โ g โ โ a โ t โ โ โ D r โ โ โ โ โ โ t โ โ โ โ โ โ D โ โ e โ โ โ r โ โ โ a o โ โ โ โ C โ โ i โ A / โ โ โ โ N โ s โ โ r โ โ โ i โ โ โ โ โ โ โ โ e m โ โ โ โ l โ โ o โ p m โ โ โ โ a โ โ โ โ โ โ c โ โ โ โ โ m โ โ โ โ u โ โ n โ p e โ โ โ โ m โ โ โ โ โ โ s โ โ โ ( โ โ o a โ โ โ โ s โ โ โ t โฌ โผ โ โด โ e โ โ โ โ โ โ ) โ โ โ D T โ โ n l โ โ โ โ t โ โ P โ C r โ โ โ โ s โ โ โ โ โ โ โ โ โ i r โ โ S l โ โ โ โ e โ โ o โ i โ โ โ โ p โ โ โ โ โ โ โ โ โ s a โ โ e โ โ โ โ r โ โ d โ c โ โ โ โ a โ โ โ โ โ โ โ โ โ t c โ โ t p โ โ โ โ โ โ s โ s โ โ โ โ c โ โ โ โ โ โ โ โ โ T r i โ โ ) o โ โ โ โ โ โ โ โ โ โ โ โ โ e โ โ โ โ โ โ โ โ โ e i n โ โ d โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ m b g โ โ s โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ p u ) โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ o t โ โ โ โ โ โ โ โ โ A / โ โ โ โ โ โ โ โ โ โ โ โ โ e โ โ โ โ โ โ โ โ โ p m โ โ โ โ โ โ โ โ โ โ โ โ โ d โ โ โ โ โ โ โ โ โ p e โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ t โฌ โผ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ D r โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ i โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ c โ โ โ โ โ โ โ โ โ โ โ s โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โค โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ
๐ ๏ธ Technologies Used# Component Technology Purpose Metrics Prometheus Time-series metrics collection Visualization Grafana Dashboards and alerting UI Logs Loki + Promtail Log aggregation Traces Tempo Distributed tracing Alerting Alertmanager Alert routing and notifications Deployment Helm + ArgoCD GitOps-based deployment Storage Thanos Long-term metrics storage
๐ Project Structure# k โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ โ 8 โ โ โ โ โ s โ โ โ โ โ - o h โ d โ โ โ โ a โ โ โ โ s โ k b e โ a โ โ โ โ l โ โ โ โ e โ u s l โ s โ โ โ โ e โ โ โ โ r โ s e m h r v t r / v โ โ โ โ b c p n a t n p a s i a o a โ โ โ โ o l o o p s o p l c p m a l โ โ โ โ a u d d p d d p o e p i b u r s - e l e - l - m l z i e p g l t d t m - i - a i a o i a l s r r o e s e e e c a l c l n c t i / o a k m / r t x a l e a e i a i t m f i p - r p t e r t r t t o y e a - o o i o i r t i t o i n / t n v - v c r o t s o s r o . h a a v e s t n s . n . s n y e - l a r . e - . y - y / - a u v u l v j r m y a a a m m s a e u i s . e a m l m o l - l s e e o j t m l e l n v u . s w n s r l r i a e y . . o i t t l s a y j n c s o u . m a s s . r e y l m o . y s s a l n j a . . m s m y y l o l a a n m m l l ๐ง Implementation Highlights# Prometheus ServiceMonitor# 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
apiVersion : monitoring.coreos.com/v1
kind : ServiceMonitor
metadata :
name : app-metrics
namespace : observability
labels :
release : prometheus
spec :
selector :
matchLabels :
app : my-application
namespaceSelector :
matchNames :
- production
- staging
endpoints :
- port : metrics
interval : 30s
path : /metrics
scrapeTimeout : 10s
Alert Rules for SLOs# 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
apiVersion : monitoring.coreos.com/v1
kind : PrometheusRule
metadata :
name : slo-alerts
namespace : observability
spec :
groups :
- name : slo.rules
rules :
- alert : HighErrorRate
expr : |
(
sum(rate(http_requests_total{status=~"5.."}[5m]))
/
sum(rate(http_requests_total[5m]))
) > 0.01
for : 5m
labels :
severity : critical
annotations :
summary : "High error rate detected"
description : "Error rate is {{ $value | humanizePercentage }} (>1% threshold)"
runbook_url : "https://runbooks.example.com/high-error-rate"
- alert : HighLatencyP99
expr : |
histogram_quantile(0.99,
sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service)
) > 0.5
for : 10m
labels :
severity : warning
annotations :
summary : "P99 latency is high"
description : "P99 latency for {{ $labels.service }} is {{ $value }}s"
Grafana Dashboard as Code# 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
apiVersion : v1
kind : ConfigMap
metadata :
name : grafana-dashboards
namespace : observability
labels :
grafana_dashboard : "1"
data :
cluster-overview.json : |
{
"dashboard": {
"title": "Cluster Overview",
"panels": [
{
"title": "CPU Usage",
"type": "graph",
"targets": [
{
"expr": "sum(rate(container_cpu_usage_seconds_total[5m])) by (namespace)",
"legendFormat": "{{namespace}}"
}
]
},
{
"title": "Memory Usage",
"type": "graph",
"targets": [
{
"expr": "sum(container_memory_usage_bytes) by (namespace) / 1024 / 1024 / 1024",
"legendFormat": "{{namespace}} (GB)"
}
]
}
]
}
}
Loki Log Queries# 1
2
3
4
5
6
7
8
# Error logs from production namespace
{namespace="production"} |= "error" | json | line_format "{{.message}}"
# Slow requests (>1s response time)
{app="api-gateway"} | json | response_time > 1000
# Failed Kubernetes events
{job="kubernetes-events"} | json | type="Warning"
๐ Dashboards Created# Dashboard Purpose Cluster Overview Node health, resource utilization, pod status Namespace Metrics Per-namespace resource consumption Application SLOs Error rates, latency percentiles, throughput Node Exporter Detailed node-level metrics Kubernetes Events Cluster events and warnings Cost Analysis Resource costs by namespace/team
๐ Alerting Strategy# Alert Severity Levels# Severity Response Time Notification Channel Critical Immediate PagerDuty + Slack Warning 1 hour Slack Info Next business day Email
SLO-Based Alerting# Availability SLO : 99.9% uptimeLatency SLO : P99 < 500msError Budget : Alert when 50% consumed in 24h๐ Results & Metrics# Metric Achievement MTTR Reduced from 2 hours to 15 minutes Alert Noise Reduced false positives by 80% Cost Savings $50k/year vs commercial APM Log Retention 30 days with 99.9% query performance Dashboard Load < 3 seconds for complex queries
๐ Key Learnings# Start with SLOs - Define SLOs first, then build alerts around themReduce Cardinality - High cardinality labels kill Prometheus performanceRetention Tiers - Different retention for different metric typesRunbooks - Every alert should link to a runbookOn-Call Experience - Invest in alert routing and escalation๐ Resources# Need help with observability? Contact me !