Monitoring/Prometheus-Grafana
[Prometheus - Grafana] - 9 Postgresql-exporter 실습
돌문어우엉
2025. 4. 19. 15:15
Docker-compose 구성
이 글은 이미 postgresql및 prometheus가 설치가 되어있다는 가정하에 진행합니다.
postgres exporter는 DB안정성을 위해 외부에 설치하여 메트릭데이터를 스크랩하도록 구성합니다.
이를 위해 db접속정보를 입력합니다. (Postgres에서는 따로 설정 필요 X)
version: "3.8"
services:
pgexporter:
container_name: pgexporter
image: prometheuscommunity/postgres-exporter
ports:
- "9187:9187"
environment:
- DATA_SOURCE_NAME=postgresql://[pg계정]:[pg계정 패스워드]@[pg접속 주소]:5432/[데이터베이스명]?sslmode=disable
# - 예시) DATA_SOURCE_NAME=postgresql://postgres:1234@10.10.10.10:5432/postgres?sslmode=disable
prometheus 연동
global:
scrape_interval: 10s
evaluation_interval: 10s
scrape_timeout: 5s
scrape_configs:
- job_name: 'pgexporter'
static_configs:
- targets: ['pgexporter:9187']
prometheus.yml에 위와같이 pgexporter job정보를 입력합니다.
prometheus 재시작 후 접속히 아래와같이 확인이 가능합니다.
※ pgexporter부분이 꼭 나와야합니다. 만약 나오지 않는다면 postgres-exporter의 설정을 다시 해야합니다.
Postgres-Exporter 메트릭 확인
Endpoint에 접속하여 새로고침하면 값들이 바뀌는것을 확인합니다.
참고적으로 go 관련 매트릭만 존재한다면 연결이 되지 않은것입니다. 잘 확인해주세요.
Grafana 시각화
먼저 그라파나에서 data source를 등록합니다.(이미 등록하였다면 상관X)
등록방법은 prometheus-grafana 연동 글을 참고해 주세요.
소스를 등록하였다면, 대시보드를 import합니다. 대시보드 ID는 다음과 같습니다.
ID 9628
결과 화면