遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

性能测试实战系列(13):监控搭建 - prometheus监控k8s外部mysql

 

本系列汇总,请查看这里https://www.cnblogs.com/uncleyong/p/15475614.html

k8s外安装mysql

https://www.cnblogs.com/uncleyong/p/10739530.html

 

配置MySQL Exporter采集MySQL监控数据

创建yaml文件:vim mysql-exporter.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-exporter
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: mysql-exporter
  template:
    metadata:
      labels:
        k8s-app: mysql-exporter
    spec:
      containers:
      - name: mysql-exporter
        image: registry.cn-chengdu.aliyuncs.com/qzcsbj/mysqld-exporter:v0.12.1
        env:
         - name: DATA_SOURCE_NAME
           value: "root:123456@(192.168.117.160:3306)/"
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9104
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-exporter
  namespace: monitoring
  labels:
    k8s-app: mysql-exporter
spec:
  type: ClusterIP
  selector:
    k8s-app: mysql-exporter
  ports:
  - name: mysql-exporter-api
    port: 9104
    protocol: TCP

 

创建exporter:kubectl create -f mysql-exporter.yaml

查看资源:kubectl get -f mysql-exporter.yaml

 

查看pod:kubectl get po -n monitoring |grep mysql-exporter

 

查看svc:kubectl get svc -n monitoring |grep mysql-exporter

 

查看是否获取到监控数据:curl 10.109.182.129:9104/metrics | grep max_connections

 

创建sm

 

 

prometheus中查看数据

查看prometheus的svc:kubectl get svc -n monitoring | grep prometheus

 

请求:http://192.168.117.161:30576

target中,prometheus自动发现了mysql

 

config中,自动生成了配置文件

 

查询数据:max_connections(要手动输入,不能复制粘贴)

mysql_global_variables_max_connections

 

grafana中查看数据

查看grafana的svc:kubectl get svc -n monitoring | grep grafana

 

请求:http://192.168.117.161:31239/

导入模板:https://grafana.com/grafana/dashboards/7362

 

然后选择数据源

 

效果

 

开启慢查询及设置阈值

数据库查询不超过50ms

开启慢查询及设置阈值

vim my.cnf

开启慢查询

slow_query_log=1
slow_query_log_file=/mysql/logs/slow.log
设置阈值
long_query_time=0.05
 

【bak】

 

posted @ 2021-12-07 12:48  全栈测试笔记  阅读(1183)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end