3.6.4. Prometheus と Grafana を使用した OpenShift Dev Spaces のモニターリング

クラスター上で実行中の Prometheus および Grafana のインスタンスを使用して、OpenShift Dev Spaces メトリクスを収集および表示できます。

3.6.4.1. Prometheus と Grafana のインストール

template.yaml を適用して Prometheus および Grafana をインストールできます。この例の template.yaml ファイルは、Prometheus および Grafana を使い始めるための基本的な設定、Deployments および Services のモニタリングスタックを提供します。

または、Prometheus OperatorGrafana Operator を使用することもできます。

前提条件

  • oc

手順

template.yaml を使用して Prometheus と Grafana をインストールするには、以下を実行します。

  1. Prometheus および Grafana の新規プロジェクト monitoring を作成します。

    $ oc new-project monitoring
  2. monitoring プロジェクトで template.yaml を適用します。

    $ oc apply -f template.yaml -n monitoring

例3.30 template.yaml

---
apiVersion: v1
kind: Service
metadata:
  name: grafana
  labels:
    app: grafana
spec:
  ports:
  - name: 3000-tcp
    port: 3000
    protocol: TCP
    targetPort: 3000
  selector:
    app: grafana
---
apiVersion: v1
kind: Service
metadata:
  name: prometheus
  labels:
    app: prometheus
spec:
  ports:
  - name: 9090-tcp
    port: 9090
    protocol: TCP
    targetPort: 9090
  selector:
    app: prometheus
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: grafana
  name: grafana
spec:
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
    spec:
      containers:
      - image: registry.redhat.io/rhel8/grafana:7
        name: grafana
        ports:
        - containerPort: 3000
          protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: prometheus
  name: prometheus
spec:
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      labels:
        app: prometheus
    spec:
      serviceAccountName: prometheus
      containers:
      - image: quay.io/prometheus/prometheus:v2.36.0
        name: prometheus
        ports:
        - containerPort: 9090
          protocol: TCP
        volumeMounts:
        - mountPath: /prometheus
          name: volume-data
        - mountPath: /etc/prometheus/prometheus.yml
          name: volume-config
          subPath: prometheus.yml
      volumes:
      - emptyDir: {}
        name: volume-data
      - configMap:
          defaultMode: 420
          name: prometheus-config
        name: volume-config
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-config
data:
  prometheus.yml: ""
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus
---