Prometheus는 2012년 SoundCloud가 개발한 오픈소스 모니터링 및 알림 시스템이다. 시계열 데이터를 수집·저장하며, PromQL 쿼리로 지표를 분석한다. Kubernetes 모니터링의 표준이다.
핵심 특징
| 특징 | 설명 |
|---|
| Pull 모델 | 대상에서 주기적으로 지표 수집 |
| 시계열 DB | 타임스탬프와 레이블로 데이터 저장 |
| PromQL | 강력한 쿼리 언어 |
| 알림 | AlertManager로 조건부 알림 |
python
from prometheus_client import start_http_server, Counter, Gauge, Histogram
import time
# 지표 정의
REQUEST_COUNT = Counter('http_requests_total', 'Total requests', ['method', 'endpoint'])
RESPONSE_TIME = Histogram('http_response_duration_seconds', 'Response time')
ACTIVE_USERS = Gauge('active_users', 'Currently active users')
# 지표 업데이트
REQUEST_COUNT.labels(method='GET', endpoint='/api/users').inc()
ACTIVE_USERS.set(100)
@RESPONSE_TIME.time()
def handle_request():
pass
start_http_server(8000) # /metrics 엔드포인트 노출
PromQL 예시
promql
# 초당 요청 수
rate(http_requests_total[5m])
# 99번째 백분위 응답 시간
histogram_quantile(0.99, http_response_duration_seconds_bucket)
# 알림 규칙
ALERT HighErrorRate
IF rate(http_errors_total[5m]) > 0.1
FOR 5m
LABELS { severity="critical" }
관련 개념
- •Grafana — Prometheus 데이터 시각화
- •Kubernetes — Prometheus의 주요 모니터링 대상
참고문헌
- •Prometheus 공식 문서: prometheus.io