3.6.4. 使用 Prometheus 和 Grafana 监控 OpenShift Dev Spaces
您可以使用在集群中运行 Prometheus 和 Grafana 实例来收集和查看 OpenShift Dev Spaces 指标。
3.6.4.1. 安装 Prometheus 和 Grafana
您可以通过应用由 Prometheus 和 Grafana 的 Deployment 和 Service 组成的 template.yaml 来安装 Prometheus 和 Grafana。
另外,您可以使用 Prometheus Operator 和 Grafana Operator。
先决条件
- oc
流程
使用 template.yaml 安装 Prometheus 和 Grafana:
-
通过运行
oc apply -f将 template.yaml 应用到集群。template.yaml
例 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:
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: |
---