「翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。」
Prometheus を使用したプレーンメトリクスのコントロール
Kubernetes API サーバーは、モニタリングと分析に役立つ多数のメトリクスを公開します。これらのメトリクスは、/metrics
HTTP API を参照するメトリクスエンドポイントを介して内部的に公開されます。他のエンドポイントと同様に、このエンドポイントは Amazon EKS コントロールプレーンに公開されます。このトピックでは、このエンドポイントを使用してクラスターの動作を表示および分析する方法をいくつか説明します。
未加工メトリクスの表示
未加工メトリクスの出力を表示するには、--raw
フラグを付けて kubectl
を使用します。このコマンドを使用すると、任意の HTTP パスを渡して未加工のレスポンスを返すことができます。
kubectl get --raw /metrics
出力例:
... # HELP rest_client_requests_total Number of HTTP requests, partitioned by status code, method, and host. # TYPE rest_client_requests_total counter rest_client_requests_total{code="200",host="127.0.0.1:21362",method="POST"} 4994 rest_client_requests_total{code="200",host="127.0.0.1:443",method="DELETE"} 1 rest_client_requests_total{code="200",host="127.0.0.1:443",method="GET"} 1.326086e+06 rest_client_requests_total{code="200",host="127.0.0.1:443",method="PUT"} 862173 rest_client_requests_total{code="404",host="127.0.0.1:443",method="GET"} 2 rest_client_requests_total{code="409",host="127.0.0.1:443",method="POST"} 3 rest_client_requests_total{code="409",host="127.0.0.1:443",method="PUT"} 8 # HELP ssh_tunnel_open_count Counter of ssh tunnel total open attempts # TYPE ssh_tunnel_open_count counter ssh_tunnel_open_count 0 # HELP ssh_tunnel_open_fail_count Counter of ssh tunnel failed open attempts # TYPE ssh_tunnel_open_fail_count counter ssh_tunnel_open_fail_count 0
この未加工出力は、API サーバーが公開する内容をそのまま返します。これらのメトリクスは Prometheus 形式
<metric_name>{"<tag>"="<value>"[<,...>]} <value>
このエンドポイントは特定のメトリクスを探している場合に役立ちますが、通常はこれらのメトリクスを経時分析する必要があります。分析するには、Prometheus
Prometheus のデプロイ
このトピックは、Helm V3 を使用して Prometheus をクラスターにデプロイする際に役立ちます。既に Helm がインストールされている場合は、helm version
コマンドでバージョンを確認できます。Helm は Kubernetes クラスターのパッケージマネージャーです。Helm の詳細およびインストール方法については、「Amazon EKS での Helm の使用」を参照してください。
Amazon EKS クラスター用に Helm を設定した後、以下の手順でそれを使用して Prometheus をデプロイできます。
Helm を使用して Prometheus をデプロイするには
-
Prometheus 名前空間を作成します。
kubectl create namespace prometheus
-
Prometheus をデプロイします。
helm install prometheus prometheus-community/prometheus \ --namespace prometheus \ --set alertmanager.persistentVolume.storageClass="gp2",server.persistentVolume.storageClass="gp2"
注記 このコマンドの実行時に
Error: failed to download "stable/prometheus" (hint: running `helm repo update` may help)
エラーが発生した場合は、helm repo update
を実行し、ステップ 2 コマンドを再度実行してみてください。エラー
Error: rendered manifests contain a resource that already exists
が発生した場合、helm uninstall your-release-name -n namespace
を実行して、ステップ 2 コマンドを再度実行してみてください。 -
prometheus
名前空間のすべてのポッドがREADY
状態になっていることを確認します。kubectl get pods -n prometheus
出力:
NAME READY STATUS RESTARTS AGE prometheus-alertmanager-59b4c8c744-r7bgp 1/2 Running 0 48s prometheus-kube-state-metrics-7cfd87cf99-jkz2f 1/1 Running 0 48s prometheus-node-exporter-jcjqz 1/1 Running 0 48s prometheus-node-exporter-jxv2h 1/1 Running 0 48s prometheus-node-exporter-vbdks 1/1 Running 0 48s prometheus-pushgateway-76c444b68c-82tnw 1/1 Running 0 48s prometheus-server-775957f748-mmht9 1/2 Running 0 48s
-
kubectl
を使用して、Prometheus コンソールをローカルマシンにポート転送します。kubectl --namespace=prometheus port-forward deploy/prometheus-server 9090
-
ウェブブラウザで localhost:9090
にアクセスして、Prometheus コンソールを表示します。 -
[- insert metric at cursor (カーソルの位置のメトリクスを挿入)] メニューからメトリクスを選択し、[実行] を選択します。[グラフ] タブを選択して、一定期間のメトリクスを表示します。次の図では、一定期間の
container_memory_usage_bytes
を示します。 -
上部のナビゲーションバーから、[ステータス]、[ターゲット] の順に選択します。
サービス検出を使用して Prometheus に接続されているすべての Kubernetes エンドポイントが表示されます。