0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Konnect環境でPrometheusでメトリクスを取得する

Last updated at Posted at 2025-05-13

初歩的なところなのに時間を食ってしまったのでメモ化。
KonnectだとAnalyticsというメトリクスの分析ツールが提供されるが、自前で既にPrometheus/Grafana環境を持っている人はKonnectの分析ツールを使わずに自前の環境にメトリクスを集約したいということも多いと思う。
今回はKonnect利用時にアプリへのトラフィックのメトリクスをPrometheus/Grafanaで可視化する方法をメモ化する。

前提

以下の環境で検証する。

  • Kubernetes環境
  • Prometheus/Grafanaは同一クラスタ内に展開済み
  • スクレイプの設定はPrometheus OperatorのCRDのServiceMonitorを利用

Prometheus/Grafanaは「cert-managerとPrometheus OperatorでTLS化したPrometheus/Grafanaを立てる」の手順で構築したものを使う。

Data Planeの構築

Data Planeに設定を施す必要があるのでData Planeの構築から行う。
KonnectのUIからData Plane Nodes->Configure data planeを選択する。
Pasted image 20250513182718.png

選択後の画面でPlatformにKubernetesを選択するとKubernetes向けのセットアップ手順が表示されるので、これに従ってvalues.yamlを作るところまで進める。

values.yaml作成時、以下を追記する。

serviceMonitor:
  enabled: true
  labels:
    release: prometheus-stack

status:
  enabled: true
  http:
    enabled: true
    containerPort: 8100

メトリクスの取得にはStatus APIを利用する。
Kong Gatewayのメトリクス取得はAdmin APIの/metricsかStatus APIの/metricsを使って取得するが、Admin API経由は以下のようなデメリットがある

  • RBAC利用時に使えない(Prometheusにスクレイプさせるのが難しい)
  • Control Planeにアクセス出来る必要あり(=Konnect環境では利用不可)

Status APIだと上記のデメリットを回避でき、Konnectの場合だと選択肢はこれのみとなる。
Status APIを使うためにstatus:を記載してDeploymentにStatus API用の設定が埋め込む。
なお、コードを見る感じ、StatusAPIのためのServiceリソースは作られない模様。
あと、Prometheusが自動で/metricsを見つけてスクレイプするためのServiceMonitorリソースを作成するためにserviceMonitor:の設定を入れている。
ラベルを指定しているのはPrometheus OperatorのServiceMonitor検知ルールに従うため。
詳細は以前書いたこちらの記事を参照して欲しいが、環境によって違う場合があるので各自のものを確認の上設定して貰った方がよい。

上記設定でデプロイする。

helm upgrade -i -n kong my-kong kong/kong -f ./values.yaml --debug --wait

デプロイ後、StatusAPI用のServiceを作成する。

kubectl expose deploy my-kong-kong --port 8100 --name my-kong-kong-status --type ClusterIP -n kong -l enable-metrics="true"

なおラベルはServiceMonitorが検知するためのもので、ServiceMonitorspec.selector.matchLabelsでスクレイプ対象が定義されている。
上手く行けばPrometheusのTargetsに以下のようにDPのエンドポイントが追加される。
Pasted image 20250513185728.png

PromQLでKong関連のメトリクスが見れることも確認する。
Pasted image 20250513185811.png

動作確認

適当にService、Routeを作成し、Prometheus Pluginを適用する。
今回は以下のものを作成した。(作成手順は割愛)

  • Service
  • Route
    • /httpbin
  • Plugin
    • Prometheus PluginをRouteに設定
    • Pluginのメトリクスのチェックは全てON

作成後、DP経由でアクセスする。

watch curl dp.my.domain/httpbin/anything

アクセス後、Prometheusを見ると以下の様な感じでexported_serviceのタグに作成したサービス名が設定されたメトリクスが確認できる。

kong_http_requests_total{code="200", container="proxy", endpoint="status", exported_service="httpbin-service", instance="192.168.28.183:8100", job="my-kong-kong-proxy", namespace="kong", pod="my-kong-kong-69474c4b-mhr6t", route="d3f0119f-bfe4-480d-a681-4a7d4592e214", service="my-kong-kong-proxy", source="service", workspace="default"}

ここでは割愛するが、Grafanaのダッシュボードからもメトリクスが確認できる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?