Prometheus 플러그인으로 Kong Gateway 메트릭 수집하기
Prometheus 플러그인으로 Kong Gateway 메트릭 수집하기 (Prometheus plugin)
이 문서는 Prometheus 플러그인을 사용해서 Kong Gateway의 성능 지표와 프록시된 업스트림 서비스 메트릭을 수집하는 방법을 안내해요. 플러그인을 활성화하면 /metrics 엔드포인트에서 메트릭을 노출할 수 있고, prometheus.yml 파일을 설정한 뒤 Prometheus 서버를 실행하면 돼요. Konnect 배포 환경과 온프레미스 배포 환경 두 가지 경우에 맞춘 절차를 각각 설명해요
출처: 문서
본문
TL;DR
Prometheus 플러그인으로 Kong Gateway 메트릭을 수집하려면 어떻게 해야 하나요?
Kong Gateway는 Prometheus 플러그인으로 Prometheus를 지원해요. 이 플러그인은 /metrics 엔드포인트에서 Kong Gateway 성능 및 프록시되는 업스트림 서비스 메트릭을 노출해요. 메트릭을 수집하려면 Prometheus 플러그인을 활성화하고, Kong Gateway 메트릭을 노출하도록 prometheus.yml 파일을 구성한 다음, Prometheus 서버를 실행하세요.
필수 조건
Konnect 배포: Kong Konnect
이 튜토리얼은 Konnect용 튜토리얼로, Konnect 개인 액세스 토큰이 필요해요.
-
Konnect PAT 페이지를 열고 Generate Token을 선택해서 새 개인 액세스 토큰을 생성하세요.
-
토큰을 환경 변수로 내보내세요:
export KONNECT_TOKEN='YOUR_KONNECT_PAT' -
quickstart 스크립트를 실행해서 Control Plane과 Data Plane을 자동으로 프로비저닝하고 환경을 구성하세요:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -k $KONNECT_TOKEN \ -e KONG_STATUS_LISTEN=0.0.0.0:8100 --deck-output이 명령은
quickstart라는 이름의 Konnect Control Plane을 설정하고, 로컬 Data Plane을 프로비저닝하며, 다음 환경 변수 export 문을 출력해요:export DECK_KONNECT_TOKEN=$KONNECT_TOKEN export DECK_KONNECT_CONTROL_PLANE_NAME=quickstart export DECK_KONNECT_ADDR=https://us.api.konghq.com export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com export KONNECT_PROXY_URL='http://localhost:8000'세션을 구성하려면 이 내용을 복사해서 터미널에 붙여넣으세요.
온프레미스 배포: 실행 중인 Kong Gateway
이 튜토리얼에는 Kong Gateway Enterprise가 필요해요. 아직 Kong Gateway를 설정하지 않았다면, 엔터프라이즈 라이선스와 함께 quickstart 스크립트를 사용해서 거의 즉시 Kong Gateway 인스턴스를 실행할 수 있어요.
-
라이선스를 환경 변수로 내보내세요:
export KONG_LICENSE_DATA='LICENSE-CONTENTS-GO-HERE' -
quickstart 스크립트를 실행하세요:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -e KONG_LICENSE_DATAKong Gateway가 준비되면 다음 메시지가 표시돼요:
Kong Gateway Ready{:.no-copy-code}
decK v1.68.0+
이 튜토리얼을 완료하려면 decK를 설치하세요. 최신 버전(1.68.0)으로 decK를 업데이트한 상태로 유지하는 것을 추천해요.
decK는 상태 파일로 Kong Gateway를 선언적으로 관리하는 CLI 도구예요.
이 가이드는 엔티티 구성을 Gateway 인스턴스에 직접 적용하는 deck gateway apply를 사용해요.
현재 decK 버전은 deck version으로 확인할 수 있어요.
필수 엔티티
이 튜토리얼에서는 Gateway Services와 Routes 같은 Kong Gateway 엔티티가 미리 구성되어 있어야 해요. 이 엔티티들은 Kong Gateway가 동작하는 데 필수적이지만, 설치 자체는 이 가이드의 초점이 아니에요. 다음 단계에 따라 미리 구성하세요:
-
다음 명령을 실행하세요:
echo ' _format_version: "3.0" services: - name: example-service url: http://httpbin.konghq.com/anything routes: - name: example-route paths: - "/anything" service: name: example-service protocols: - http - https ' | deck gateway apply -{: data-test-prereq="block" }
엔티티에 대해 더 알아보려면 엔티티 문서를 읽어보세요.
Prometheus 플러그인 활성화
Prometheus를 구성하기 전에 Kong Gateway에서 Prometheus 플러그인을 활성화하세요:
echo '
_format_version: "3.0"
plugins:
- name: prometheus
config:
status_code_metrics: true
' | deck gateway apply -
{: data-test-step="block" }
Prometheus 구성
Kong Gateway 메트릭을 스크랩하도록 Prometheus를 구성하는 prometheus.yml 파일을 생성하세요:
온프레미스 배포
cat <<EOF > prometheus.yml
scrape_configs:
- job_name: 'kong'
scrape_interval: 5s
static_configs:
- targets: ['kong-quickstart-gateway:8001']
EOF
Konnect 배포
cat <<EOF > prometheus.yml
scrape_configs:
- job_name: 'kong'
scrape_interval: 5s
static_configs:
- targets: ['kong-quickstart-gateway:8100']
EOF
Prometheus 서버를 실행하고, 이전 단계에서 만든 구성 파일을 전달하세요:
docker run -d --name kong-quickstart-prometheus \
--network=kong-quickstart-net -p 9090:9090 \
-v $(PWD)/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus:latest
Prometheus가 Kong Gateway에서 메트릭 데이터 스크랩을 시작할 거예요.
검증
예제 Service로 트래픽을 생성해서 플러그인이 메트릭을 수집하고 있는지 검증할 수 있어요.
같은 터미널에서 다음을 실행하세요:
Konnect 배포
sleep 1 && for _ in {1..60}; do
curl "$KONNECT_PROXY_URL/anything" \
--no-progress-meter --fail-with-body \
; done
온프레미스 배포
sleep 1 && for _ in {1..60}; do
curl "http://localhost:8000/anything" \
--no-progress-meter --fail-with-body \
; done
수집된 kong_http_requests_total 메트릭 데이터를 쿼리하려면 다음을 실행하세요:
curl -s 'localhost:9090/api/v1/query?query=kong_http_requests_total'
다음과 비슷한 결과가 반환될 거예요:
{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"kong_http_requests_total","code":"200","instance":"kong-quickstart-gateway:8001","job":"kong","route":"example-route","service":"example-service","source":"service","workspace":"default"},"value":[1749000790.826,"42"]}]}}
브라우저에서 http://localhost:9090/graph를 열면 Prometheus 표현식 뷰어도 볼 수 있어요.
정리
Prometheus
Prometheus 실험을 마쳤다면, 다음 명령을 사용해서 이 가이드에서 만든 Prometheus 서버를 중지할 수 있어요:
docker stop kong-quickstart-prometheus
Kong Gateway 컨테이너 삭제
curl -Ls https://get.konghq.com/quickstart | bash -s -- -d
Konnect 환경 정리
새 컨트롤 플레인을 만들었고 무료 체험 크레딧을 아끼거나 불필요한 요금을 피하고 싶다면, 이 튜토리얼에서 사용한 새 컨트롤 플레인을 삭제하세요.
관련 리소스
다음 단계
더 알아보기 (Learn more)
- Prometheus 플러그인의 개요와 제공하는 메트릭을 소개하는 문서예요 — Prometheus plugin
- Kong Gateway 모니터링과 메트릭 전반을 다루는 가이드예요 — Kong Gateway monitoring and metrics
- Prometheus 플러그인의 모든 설정 옵션을 정리한 레퍼런스예요 — Review the Prometheus plugin configuration reference
- 이 튜토리얼에서 요구하는 선언형 설정 도구 decK의 설치와 사용법을 확인할 수 있어요 — decK
- Datadog과 함께 메트릭을 수집하는 유사한 튜토리얼이에요 — Collect metrics with Datadog and the Prometheus plugin
- Kubernetes 환경에서 Prometheus와 Grafana로 메트릭을 모니터링하는 방법이에요 — Monitor metrics with Prometheus and Grafana with KIC