promethus operator to monitor the expansion of serviceMonitor

serviceMonitor is acquired by way of the data service.

  1. promethus-operator may be provided with service by some serviceMonitor automatic identification label, and retrieve data from the service.
  2. serviceMonitor is automatically discovered by the promethus-operator.

The following are examples of mysql monitor

1. Download mysql-exprotor

git clone https://github.com/helm/charts.git
have a lot of exporter in the stab, mysql official also inside

2. Deploy mysql-exprotor

Create a database account and empowerment

CREATE USER '<用户名>'@'localhost' IDENTIFIED BY '<密码>' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';

Use helm to create mysql-exprotor

helm install --name  mysql-moneyfeed-master  stable/prometheus-mysql-exporter --set mysql.user="<用户名>",mysql.pass="<密码>",mysql.host="<主机名>",mysql.port="<端口>" --namespace monitoring

3. Deploy serviceMonitor

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

Create a resource
serviceMonitor.yaml

kubectl apply -f serviceMonitor.yaml

Guess you like

Origin www.cnblogs.com/pythonPath/p/12505457.html