기본적으로 prometheus는 pulling 방식으로 사용합니다.
즉, prometheus에서 scrape target 정보를 가지고 있어서, target에게 메트릭을 요청하고 그에 대해 답변을 받아서 메트릭을 수집하는 방식입니다.
하지만, prometheus도 pushing 방식으로 사용할 수 있습니다.
push 방식이란, agent(scrape target)측에서 일방적으로 prometheus에게 메트릭을 보내는 것입니다.
prometheus가 굳이 target 정보를 알지 못해도 메트릭을 수집할 수 있는 것입니다.
push 방식으로 사용하는 방법은 크게 두 가지입니다.
- pushgateway라는 component를 사용
- remote_write API 사용
pushgateway

Metric을 노출시키는 주체가 pushgateway에 메트릭을 push하기 때문에,
scrape target(agent, application) ↔ pushgateway는 push 방식이고,
prometheus는 pushgateway에 scrape 요청을 통해 메트릭을 받기 때문에
pushgateway ↔ prometheus는 pull 방식입니다.
장점
- 컨테이너 생성, 삭제 주기가 짧은 것들에 대한 수집이 가능 : prometheus scrape 주기와 상관 없이 agent가 pushgateway에게 원할 때 메트릭을 push하기 때문에 주기가 짧아도 놓치는 메트릭이 없습니다.
- pushgateway HTTP API를 이용하므로 push 방식을 써야할 때 해야하는 복잡한 구성이 불필요
- Prometheus server 부하 감소 : prometheus가 메트릭을 수집할 때 pushgateway에만 요청하면 되기 때문입니다. (pushgateway를 이용하여 수집 단계에서의 부하를 줄이면, 메트릭 데이터를 쿼리할 때의 리소스 여유분이 더 생겨서 도움이 될 것 같습니다.)
- prometheus 서버 다운 시 메트릭 손실 방지 : pushgateway에서 메트릭을 임시로 보관하기 때문에, 짧은 다운 타임에 대해서 손실 방지를 할 수 있습니다.
remote_write API
prometheus에서 지원하는 remote_write api를 push용 api로 사용할 수 있습니다.
https://prometheus.io/docs/prometheus/latest/querying/api/#remote-write-receiver
application에서의 메트릭을 prometheus에 remote write 하기 위해서는 prometheus client 라이브러리를 사용하여 메트릭 데이터를 생성하고 remote write API를 호출하여 prometheus에 메트릭을 전송하는 설정이 필요합니다.
'Monitoring' 카테고리의 다른 글
LGTM 특장점 (0) | 2023.09.04 |
---|---|
Prometheus alertmanager (0) | 2023.08.31 |
Grafana-agent for uploading PrometheusRule to mimir (0) | 2023.08.31 |
Grafana mimir overview (0) | 2023.08.29 |
Opentelemetry - Collector filtering span (0) | 2023.08.28 |