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
文件提供了一个基本配置、Deployment 和 Services 的监控堆栈。
另外,您可以使用 Prometheus Operator 和 Grafana Operator。
先决条件
- oc
流程
使用 template.yaml
安装 Prometheus 和 Grafana:
为 Prometheus 和 Grafana 创建一个新项目,
监控
:$ oc new-project monitoring
在
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 ---