mysqld_exporter使用

下载自己解压好

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:latest

WORKDIR /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.2


RUN   mkdir /config/

COPY my.cnf /config/my.cnf
COPY  mysqld_exporter /app/mysqld_exporter

ENTRYPOINT ["/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: 1
  selector:
    matchLabels:
      app: mysqld-exporter
  template:
    metadata:
      labels:
        app: mysqld-exporter
    spec:
      containers:
      - name: mysqld-exporter
        image: mysqld:v01
        ports:
          - containerPort: 9104
        resources:
          requests:
            cpu: "100m"
            memory: "256Mi"
          limits:
            cpu: "4000m"
            memory: "4096Mi"
---

apiVersion: v1
kind: Service
metadata:
  name: mysqld-exporter
spec:
  selector:
    app: mysqld-exporter
  ports:
  - protocol: TCP
    name: web
    port: 9104
    targetPort: 9104
EOF

你可能感兴趣的:(Prometheus,docker)