promethus operator監控擴展之serviceMonitor


serviceMonitor 是通過對service 獲取數據的一種方式。

  1. promethus-operator可以通過serviceMonitor 自動識別帶有某些 label 的service ,並從這些service 獲取數據。
  2. serviceMonitor 也是由promethus-operator 自動發現的。

以下是mysql 監控 的實例

1. 下載 mysql-exprotor

git clone https://github.com/helm/charts.git
在 stab 中有很多的exporter, mysql 官方的也在里面

2.部署 mysql-exprotor

創建數據庫賬號 並 賦權

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

3.部署 serviceMonitor

serviceMonitor 的 labbels 非常的關鍵,promethus 通過標簽發現serviceMonitor。
執行

kubectl get prometheus ack-prometheus-operator-prometheus  -n monitoring -o yaml

找到以下配置信息

serviceMonitorSelector:
    matchLabels:
      release: ack-prometheus-operator

release: ack-prometheus-operator 就是serviceMonitor 需要配置的label

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM