[Observability] Prometheus: pull 기반 메트릭, PromQL
Prometheus, PromQL, scrape, exporter, Alertmanager, Thanos, Mimir, recording rule
정의
Prometheus = pull 기반 시계열 metric 시스템. PromQL 로 쿼리. CNCF graduated. 2026 클라우드 네이티브 메트릭 표준.
아키텍처
flowchart LR
App1[App + /metrics] -.HTTP GET.-> Prom[Prometheus]
App2[App + /metrics] -.HTTP GET.-> Prom
NodeEx[node-exporter] -.HTTP GET.-> Prom
KSM[kube-state-metrics] -.HTTP GET.-> Prom
Prom --> TSDB[(Time Series DB)]
Prom --> AM[Alertmanager]
AM --> Slack[Slack / PagerDuty / Email]
Prom --> Grafana
Pull 모델: Prometheus 가 각 target 의
/metrics정기 scrape. Push 가 아닌 이유: target healthy 자동 확인, scrape interval 통제.
Exposition Format
# HELP http_requests_total Total HTTP requests
# TYPE http_requests_total counter
http_requests_total{method="GET",status="200",path="/api/users"} 1234
http_requests_total{method="POST",status="201",path="/api/orders"} 567
# HELP http_request_duration_seconds Request duration
# TYPE http_request_duration_seconds histogram
http_request_duration_seconds_bucket{le="0.1"} 5000
http_request_duration_seconds_bucket{le="0.5"} 5800
http_request_duration_seconds_bucket{le="1.0"} 5900
http_request_duration_seconds_bucket{le="+Inf"} 6000
http_request_duration_seconds_sum 412.5
http_request_duration_seconds_count 6000
4가지 메트릭 타입
| 타입 | 의미 | 예 |
|---|---|---|
| Counter | 단조 증가 | requests_total |
| Gauge | 임의 변동 | memory_usage_bytes |
| Histogram | 분포 (bucket) | request_duration_seconds |
| Summary | quantile (클라이언트 계산) | request_duration_quantile |
PromQL 예시
# 요청률 (5분)
rate(http_requests_total[5m])
# 에러 비율
sum(rate(http_requests_total{status=~"5.."}[5m]))
/ sum(rate(http_requests_total[5m]))
# 평균 응답 시간
rate(http_request_duration_seconds_sum[5m])
/ rate(http_request_duration_seconds_count[5m])
# p95 latency (histogram_quantile)
histogram_quantile(0.95,
sum by (le, service) (rate(http_request_duration_seconds_bucket[5m]))
)
# 메모리 사용량 (gauge)
process_resident_memory_bytes
# CPU 사용률
rate(process_cpu_seconds_total[1m])
# 가용성 (up)
avg_over_time(up{job="api"}[5m])
Exporter
| Exporter | 메트릭 |
|---|---|
| node-exporter | Linux node (CPU, RAM, disk, network) |
| kube-state-metrics | K8s 객체 상태 |
| cAdvisor | container metric (K8s 기본 포함) |
| postgres_exporter | PG 통계 |
| redis_exporter | Redis |
| blackbox_exporter | HTTP/TCP probe |
| nginx-exporter | nginx |
4 Golden Signals (Google SRE)
flowchart TD
G[4 Golden Signals]
G --> Lat[Latency]
G --> Tra[Traffic]
G --> Err[Errors]
G --> Sat[Saturation]
모든 서비스 대시보드의 기본 4. 이 4 가지면 대부분의 문제 발견.
Alertmanager
# Alert rule
groups:
- name: api
rules:
- alert: HighErrorRate
expr: |
sum(rate(http_requests_total{status=~"5.."}[5m]))
/ sum(rate(http_requests_total[5m])) > 0.05
for: 5m
labels: { severity: page }
annotations:
summary: "5xx rate > 5%"
# Alertmanager 설정
route:
group_by: [alertname, severity]
receiver: slack
routes:
- match: { severity: page }
receiver: pagerduty
receivers:
- name: slack
slack_configs:
- api_url: https://hooks.slack.com/...
- name: pagerduty
pagerduty_configs:
- service_key: ...
Long-Term Storage
| Local TSDB | Thanos | Mimir | Cortex | |
|---|---|---|---|---|
| Retention | 15일 기본 | 무제한 (S3) | 무제한 | 무제한 |
| HA | 없음 | 있음 | 있음 | 있음 |
| Multi-tenancy | 없음 | 있음 | 있음 | 있음 |
수년 retention + 다중 cluster = Thanos / Mimir.
Recording Rule
- record: job:http_requests:rate5m
expr: sum by (job) (rate(http_requests_total[5m]))
자주 쓰는 쿼리 결과 미리 계산. 대시보드 속도 ↑.
흔한 함정
WARNING
- Label cardinality 폭증 = user_id, request_id 같은 고유 값 을 label 로. 메모리 / disk 폭발.
rate()의 짧은 range = scrape interval 보다 작으면 NaN.- Counter reset 인식 못함 =
rate()가 자동.increase()와 차이. - Push 가 필요한 경우 = Pushgateway 사용 (batch job 등). 일반 service 는 pull.
관련 위키
이 글의 용어 (4개)
- [AWS] CloudWatch: 메트릭, 로그, 알람cloud
- 정의 CloudWatch = AWS 의 모니터링 + 로그 + 알람 통합 서비스. 4가지 구성 Metrics | 종류 | 의미 | |---|---| | Standard resolu…
- [K8s] Pod: 컨테이너의 최소 단위, sidecar, lifecyclekubernetes
- 정의 Pod = K8s 의 가장 작은 배포 단위. 1개 이상의 컨테이너 + 공유 네트워크 + 공유 스토리지. [!IMPORTANT] Pod 는 컨테이너의 wrapping 이 아니…
- [Observability] OpenTelemetry: 표준화된 trace/metric/logdevops
- 정의 OpenTelemetry (OTel) = observability 의 vendor-neutral 표준. CNCF. trace + metric + log 의 SDK + pro…
- [Observability] SLI / SLO / SLA / Error Budgetdevops
- 정의 | | 의미 | |---|---| | SLI (Indicator) | 측정 값 (예: 5xx 비율) | | SLO (Objective) | 목표 (예: 99.9% 가용성) …
이 개념을 다룬 위키 페이지 (9)
- wiki[AWS] CloudWatch: 메트릭, 로그, 알람
- wiki[Voice AI] P50/P95/P99: latency 분포와 SLO
- wiki[Observability] OpenTelemetry: 표준화된 trace/metric/log
- wiki[Observability] SLI / SLO / SLA / Error Budget
- wiki[K8s] DaemonSet: 모든 노드에 한 pod
- wiki[K8s] HPA / VPA / KEDA: 자동 확장
- wiki[K8s] Job / CronJob: 일회성 + 스케줄 작업
- wiki[Search] ElasticSearch: Lucene 위 분산 검색 엔진
- wiki[Search] ES 인프라: cluster, shard, replica, ELK
💬 댓글