当前位置:   article > 正文

Prometheus 监控 Mysql_prometheus servicemonitor 监控mysql容器

prometheus servicemonitor 监控mysql容器

1、安装mysql服务

kubectl create deploy mysql --image=registry.cn-beijing.aliyuncs.com/dotbalo/mysql:5.7.23
  • 1

1.1、使用变量设置mysql密码

kubectl set env deploy/mysql MYSQL_ROOT_PASSWORD=mysql
  • 1

1.2、暴露mysql端口

kubectl expose deploy mysql --port 3306
  • 1

1.3、授权mysql账户

CREATE USER 'exporter'@'%' IDENTIFIED BY 'exporter' WITH MAX_USER_CONNECTIONS 3;
Query OK, 0 rows affected (0.01 sec)
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
Query OK, 0 rows affected (0.00 sec)
  • 1
  • 2
  • 3
  • 4

2、创建mysql-exporter服务

[root@master ~]# cat mysql-exporter.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-exporter
  namespace: kuboard
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: mysql-exporter
  template:
    metadata:
      labels:
        k8s-app: mysql-exporter
    spec:
      containers:
      - name: mysql-exporter
        image: registry.cn-beijing.aliyuncs.com/dotbalo/mysqld-exporter
        env:
        - name: DATA_SOURCE_NAME
          value: "root:123456@(192.168.122.222:30295)/"    # 要监控的mysql账号信息
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9104
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-exporter
  namespace: kuboard
  labels:
    k8s-app: mysql-exporter
spec:
  type: ClusterIP
  selector:
    k8s-app: mysql-exporter
  ports:
  - name: api
    port: 9104
    protocol: TCP
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

2.1、部署mysql-exporter

kubectl apply -f mysql-exporter.yaml 
  • 1

2.2、验证是否部署成功

[root@master ~]# kubectl get pod,svc  -n kuboard
mysql-exporter-7cff6b6759-q7djh          1/1     Running   0                 17h
mysql-exporter          ClusterIP   10.108.108.48    <none>        9104/TCP                                       17h
  • 1
  • 2
  • 3

2.3、查看 ENDPOINTS

[root@master ~]# kubectl get ep -n kuboard
mysql-exporter          10.244.1.93:9104                                                 17h
  • 1
  • 2

2.4、部署servicemonitor

[root@master ~]# cat mysql-sm.yanl 
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    k8s-app: mysql-exporter
  name: mysql-exporter
  namespace: kuboard
spec:
  endpoints:
  - interval: 15s
    port: api
    scheme: http
  selector:
    matchLabels:
      k8s-app: mysql-exporter
  namespaceSelector:
    matchNames:
    - kuboard
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

2.4.1、查看 servicemonitor是否部署成功

[root@master ~]# kubectl get servicemonitor -n kuboard
NAME                      AGE
mysql-exporter            17h
  • 1
  • 2
  • 3

3、prometheus 界面查看
在这里插入图片描述
4、granfana 图形化展示(导入6239模板)
在这里插入图片描述

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号