Skip to content

Lab: Docker Compose ile Cache Observability Stack

Lokal olarak Prometheus + Grafana + custom exporter stack'ini Docker Compose ile kuruyoruz. Production-ready bir başlangıç noktası.

Şükrü Yusuf KAYA
14 min read
Intermediate

Lab #13: Cache Observability Stack

Bu lab uçtan uca bir monitoring stack kuruyor.
Bileşenler:
  • LLM app + Prometheus exporter
  • Prometheus (metrics scrape)
  • Grafana (dashboard)
  • AlertManager (notification)

Adım 1 — docker-compose.yml#

yaml
version: "3"
services:
app:
build: ./app
ports:
- "8000:8000"
- "9100:9100" # Prometheus exporter
environment:
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
 
prometheus:
image: prom/prometheus:latest
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./alerts.yml:/etc/prometheus/alerts.yml
 
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
volumes:
- ./grafana-provisioning:/etc/grafana/provisioning
- grafana-data:/var/lib/grafana
 
alertmanager:
image: prom/alertmanager:latest
ports:
- "9093:9093"
volumes:
- ./alertmanager.yml:/etc/alertmanager/alertmanager.yml
 
volumes:
grafana-data:
docker-compose.yml

Adım 2 — prometheus.yml#

yaml
global:
scrape_interval: 15s
evaluation_interval: 15s
 
rule_files:
- "/etc/prometheus/alerts.yml"
 
alerting:
alertmanagers:
- static_configs:
- targets: ["alertmanager:9093"]
 
scrape_configs:
- job_name: "llm-app"
static_configs:
- targets: ["app:9100"]
prometheus.yml

Adım 3 — alerts.yml#

yaml
groups:
- name: llm_cache
interval: 30s
rules:
- alert: LowCacheHitRate
expr: |
sum(rate(llm_cache_hits_total[10m]))
/ (sum(rate(llm_cache_hits_total[10m])) + sum(rate(llm_cache_writes_total[10m])))
< 0.85
for: 5m
labels:
severity: warning
annotations:
summary: "LLM cache hit rate düştü"
description: "Son 10dk'da hit rate < 85%"
 
- alert: HighRequestLatency
expr: histogram_quantile(0.95, rate(llm_request_latency_seconds_bucket[5m])) > 5
for: 5m
labels:
severity: warning
 
- alert: CostSpike
expr: rate(llm_request_cost_usd[5m]) > 0.5 # USD/saniye
labels:
severity: critical
alerts.yml

Adım 4 — Grafana Provisioning#

yaml
# grafana-provisioning/datasources/prometheus.yml
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: http://prometheus:9090
access: proxy
isDefault: true
 
# grafana-provisioning/dashboards/main.yml
apiVersion: 1
providers:
- name: "LLM Cache"
type: file
options:
path: /var/lib/grafana/dashboards
Grafana datasource + dashboard provisioning

Adım 5 — Kalkış#

bash
# Stack'i başlat
docker compose up -d
 
# Loglar
docker compose logs -f app
 
# Grafana: http://localhost:3000 (admin/admin)
# Prometheus: http://localhost:9090
# AlertManager: http://localhost:9093
Stack'i çalıştır
Production'a Yol
Bu stack'i CI'da reusable Helm chart'a dönüştürebilirsin. Kubernetes'e deploy edip multi-environment monitoring kur.

✓ Pekiştir#

Bir Sonraki Derste#

A/B testing — caching stratejilerini production'da kıyaslama.

Yorumlar & Soru-Cevap

(0)
Yorum yazmak için giriş yap.
Yorumlar yükleniyor...

Related Content