k8s中prometheus监控k8s外mysql

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

k8s中prometheus监控k8s外mysql

 

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

k8s中prometheus监控k8s外mysql

 

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

k8s中prometheus监控k8s外mysql

 

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

k8s中prometheus监控k8s外mysql

 

prometheus中查看数据

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

k8s中prometheus监控k8s外mysql

 

请求:http://192.168.117.161:30576

target中,prometheus自动发现了mysql

k8s中prometheus监控k8s外mysql

 

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

k8s中prometheus监控k8s外mysql

 

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

mysql_global_variables_max_connections

k8s中prometheus监控k8s外mysql

 

grafana中查看数据

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

k8s中prometheus监控k8s外mysql

 

请求:http://192.168.117.161:31239/

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

k8s中prometheus监控k8s外mysql

 

然后选择数据源

k8s中prometheus监控k8s外mysql

 

效果

k8s中prometheus监控k8s外mysql

 

bak:https://www.cnblogs.com/uncleyong/p/15655032.html

原文:https://www.cnblogs.com/uncleyong/p/15507163.html

 

上一篇:Day1,记录一下Markdown的学习笔记


下一篇:【监控利器Prometheus】——Prometheus+Grafana监控服务器资源