- prometheus使用的配置文件在
openshift-monitoring/secret/prometheus-k8s
中。
有添加ServiceMonitor
时会动态更新该文件 - 为
system:serviceaccount:openshift-monitoring:prometheus-k8s
添加应用所在project的view
权限
$ oc policy add-role-to-user view system:serviceaccount:openshift-monitoring:prometheus-k8s -n myproject
- 查看prometheus的配置,查看对于servicemonitor的过滤器
$ oc get prometheus k8s -o yaml
...
serviceMonitorSelector:
matchExpressions:
- key: k8s-app
operator: Exists
-
serviceMonitorSelector
表示,只有设置了k8s-app
的Label的serviceMonitor的状态才能被该prometheus监听到
- 添加
servicemonitor
按照3的说明,serviceMonitor必须设置k8s-app
Label
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: my-cluster-kafka
namespace: openshift-monitoring
labels:
k8s-app: prometheus
spec:
selector:
matchLabels:
strimzi.io/name: my-cluster-kafka-bootstrap
namespaceSelector:
any: true
endpoints:
- port: metrics
- selector:匹配的exporter的service的Label
- namespaceSelector:匹配exporter所在的namespace。any为匹配所有的namespace
- endpoints:对应为exporter服务port名
注意:经过实验serviceMonitor必须创建在prometheus相同的project下,默认为openshift-monitoring
原理部分可参考:
官方手册 Prometheus Cluster Monitoring,包含对Openshift集群etcd的监控的详细操作
使用Prometheus Operator優雅的監控Kubernetes
基于 Prometheus 的集群监控
网友评论