serviceMonitor 是通过对service 获取数据的一种方式。
以下是mysql 监控 的实例
git clone https://github.com/helm/charts.git
在 stab 中有很多的exporter, mysql 官方的也在里面
创建数据库账号 并 赋权
CREATE USER '<用户名>'@'localhost' IDENTIFIED BY '<密码>' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
使用helm 创建 mysql-exprotor
helm install --name mysql-moneyfeed-master stable/prometheus-mysql-exporter --set mysql.user="<用户名>",mysql.pass="<密码>",mysql.host="<主机名>",mysql.port="<端口>" --namespace monitoring
serviceMonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app: ack-prometheus-operator-mysql-exporter
heritage: Tiller
release: ack-prometheus-operator # prometheus 通过该label 来发现该serviceMonitor
name: ack-prometheus-operator-mysql-exporter
namespace: monitoring
spec:
jobLabel: RDS-exporter
selector:
matchLabels:
app: prometheus-mysql-exporter # 该serviceMonitor 通过标签选择器 来自动发现exporter 的sevice
namespaceSelector:
matchNames:
- monitoring
endpoints:
- port: mysql-exporter # service 端口
interval: 30s
honorLabels: true
创建资源
serviceMonitor.yaml
kubectl apply -f serviceMonitor.yaml
promethus operator监控扩展之serviceMonitor
原文:https://www.cnblogs.com/pythonPath/p/12505457.html