下载自己解压好
https://github.com/prometheus/mysqld_exporter/releases/download/v0.15.1/mysqld_exporter-0.15.1.linux-amd64.tar.gz
在需要监控的数据库上执行
CREATE USER 'monit_test'@'*' IDENTIFIED BY 'Sfn4ZCHsK' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'monit_test'@'%';
FLUSH PRIVILEGES;
# cat >my.cnf<<EOF[client]
user=monit_test
password=Sfn4
host=im-rds-instance.ccom
prot=3306
EOF
cat >Dockerfile<<EOF
FROM alpine:latestWORKDIR /app
RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/main" > /etc/apk/repositories && \echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/latest-stable/community" >> /etc/apk/repositories && \apk update && \apk add tzdata bash-doc bash && \mkdir /lib64 && \ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2RUN mkdir /config/COPY my.cnf /config/my.cnf
COPY mysqld_exporter /app/mysqld_exporterENTRYPOINT ["/app/mysqld_exporter", "--config.my-cnf=/config/my.cnf"]
EOF
cat >mysql-monit.yaml<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:name: mysqld-exporter
spec:replicas: 1selector:matchLabels:app: mysqld-exportertemplate:metadata:labels:app: mysqld-exporterspec:containers:- name: mysqld-exporterimage: mysqld:v01ports:- containerPort: 9104resources:requests:cpu: "100m"memory: "256Mi"limits:cpu: "4000m"memory: "4096Mi"
---apiVersion: v1
kind: Service
metadata:name: mysqld-exporter
spec:selector:app: mysqld-exporterports:- protocol: TCPname: webport: 9104targetPort: 9104
EOF