LoginSignup
1
0

More than 5 years have passed since last update.

IBM Cloud Private (ICP) 付属のPrometheusとGrafanaでアプリケーションのメトリクスを可視化する

Last updated at Posted at 2018-03-30

目的

IBM Cloud Private (ICP) は製品付属のモニタリングツールとして、PrometheusとGrafanaがkube-systemネームスペースで動いています。通常ではノードやICP関係のサービスのメトリクスを収集しているのですが、せっかくなのでアプリケーションのメトリクスも収集して可視化してみます。

検証環境
- IBM Cloud Private 2.1.0.2 (Kubernetes 1.9.1)

手順

アプリのPrometheus用メトリクス対応

過去記事「Spring Boot 2で/actuator/prometheusを有効にする」のような方法があります。この場合、アプリのメトリクスは/actuator/prometheusで収集できます。

PrometheusのConfigMapを確認

PrometheusのConfigMapはmonitoring-prometheusという名前で定義されているので中を確認します。すると、怪しげなコメントが見つかります。

$ kubectl get configmap monitoring-prometheus -n kube-system -o yaml | more

      # Example scrape config for pods
      #
      # The relabeling allows the actual pod scrape endpoint to be configured via the
      # following annotations:
      #
      # * `prometheus.io/scrape`: Only scrape pods that have a value of `true`
      # * `prometheus.io/path`: If the metrics path is not `/metrics` override this.
      # * `prometheus.io/port`: Scrape the pod on the indicated port instead of the default of `9102`.
      - job_name: 'kubernetes-pods'

        kubernetes_sd_configs:
          - role: pod

実は、prometheus.io/scrape: "true"をPodのアノテーションで指定すると、このPrometheusは自動的にメトリクスを収集してくれます。また、収集時のパスやポートはprometheus.io/pathprometheus.io/portで変更することができます。

アプリのデプロイ

以下のようにアノテーションを指定します。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kube-sample-top
spec:
  replicas: 2
  selector:
    matchLabels:
      app: kube-sample-top
  template:
    metadata:
      labels:
        app: kube-sample-top
      annotations:
        prometheus.io/scrape: "true" # 収集の有効化
        prometheus.io/path: /actuator/prometheus # パス
        prometheus.io/port: "8080:8080" # Podのポート:コンテナポート
    spec:
      containers:
(略)

Prometheusの確認

PromethuesのUIを確認します。ポートが公開されていないのでport-forwardします。

$ kubectl get pod -n kube-system | grep monitoring-prometheus 
monitoring-prometheus-7994986858-4nwp8                    3/3       Running     0          5d
(略)

$ kubectl port-forward monitoring-prometheus-7994986858-4nwp8 9090:9090 -n kube-system

ブラウザで http://localhost:9090/ にアクセスし、メニューのStatus→Targetsを選択します。うまくいっていれば、次のようにScrapingが始まっているはずです。

image.png

Grafanaの確認

ICPのダッシュボードからPlatform→Monitoringを選択するとGrafanaが表示されます。試しに空のダッシュボードを作り、JVMのヒープ使用量をグラフ表示してみます。

次のような条件を指定します。

image.png

するとグラフが描画されました。

image.png

非常に簡単でしたね。

以上です。

1
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
1
0