본문으로 건너뛰기

2.3 첫 Scrape 검증

Dashboard가 비어 있거나 숫자가 이상할 때는 데이터 경로를 앞에서부터 확인합니다. 네 단계를 건너뛰지 않으면 원인 분리가 빨라집니다.

1. Exporter endpoint

curl -fsS http://localhost:9187/metrics > /tmp/postgres.metrics
grep '^pg_up' /tmp/postgres.metrics
grep '^pg_stat_database_numbackends' /tmp/postgres.metrics | head

pg_up 1이면 exporter가 적어도 한 번 PostgreSQL 통계 수집에 성공했습니다. HTTP 200인데 pg_up 0이면 exporter process는 살아 있지만 database connection이나 collector 실행이 실패한 상태입니다.

Exporter 자신의 수집 상태도 확인합니다.

grep -E '^(pg_exporter|process_|go_)' /tmp/postgres.metrics | head

2. Prometheus target

브라우저에서 http://localhost:9090/targets를 열고 postgres job이 UP인지 확인합니다. 실패한 경우 Last Error에 원인이 표시됩니다.

명령으로 확인하려면 HTTP API를 사용합니다.

curl -s http://localhost:9090/api/v1/targets \
| jq '.data.activeTargets[] | {scrapeUrl, health, lastError}'

자주 만나는 원인은 다음과 같습니다.

오류확인할 곳
connection refusedexporter process/port/container 이름
context deadline exceededscrape timeout/collector query/DB 응답
server returned HTTP status 500exporter log/DB 인증/collector 오류
no route to hostDocker network/firewall/NetworkPolicy

3. PromQL

Prometheus Graph 화면에서 먼저 table 결과를 확인합니다.

pg_up

다음으로 실제 workload counter의 5분 증가율을 봅니다.

sum by (instance) (
rate(pg_stat_database_xact_commit{datname!~"template.*"}[5m])
)

Lab을 시작한 직후에는 5분 범위에 sample이 충분하지 않아 결과가 늦게 나타날 수 있습니다. 이때 [1m]로 줄이기보다 scrape가 두세 번 완료될 때까지 기다리고 raw counter가 증가하는지 먼저 봅니다.

pg_stat_database_xact_commit{datname="app"}

4. Grafana Explore

Grafana에 로그인한 뒤 Explore에서 provision된 Prometheus data source를 선택하고 pg_up을 실행합니다. Prometheus에는 값이 있는데 Grafana에 없다면 다음을 확인합니다.

  • data source URL이 Grafana container 관점에서 http://prometheus:9090인지
  • dashboard 시간 범위가 현재를 포함하는지
  • panel variable이 존재하지 않는 instance를 선택했는지
  • query의 label filter가 실제 series와 일치하는지

Counter reset 확인

PostgreSQL container를 재시작하고 transaction counter 변화를 봅니다.

docker compose restart postgres

Raw counter graph에는 값이 낮아지는 지점이 생길 수 있습니다. rate()는 이 reset을 감지해 음수 TPS로 계산하지 않습니다. 운영 dashboard에서 누적 counter 자체보다 rate(counter[5m])를 주로 사용하는 이유입니다.

검증 체크리스트

  • /metrics HTTP 200
  • pg_up == 1
  • Prometheus target UP
  • raw counter가 workload에 따라 증가
  • rate() 결과가 0 이상
  • Grafana Explore와 Prometheus table 결과가 일치

이 여섯 항목이 확인된 뒤 dashboard를 설계합니다.

Exporter endpoint부터 Grafana Explore까지 첫 scrape를 검증하는 네 단계