Post

Mysql Monitor

操作步骤如下

  • mysql 设置
1
2
  CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3;
  GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
  • mysqld_exporter
  • prometheus
  • grafana

mysqld_exporter 启动

GitHub

  • 在机器对应目录下创建目录和文件

    • mkdir -p /home/save/mysqld_exporter/conf
    • touch config.my-cnf

      1
      2
      3
      4
      5
      6
      7
      8
      9
      
      [client]
      host=mysql-address
      port=3306
      # socket=/var/run/mysqld/mysqld.sock
      user=root
      password=password-you
      [client.server1]
      user = bar
      password = bar123
      
  • docker-compose

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
    version: "3"
    services:
      mysqld-exporter:
        container_name: mysqld-exporter
        image: prom/mysqld-exporter
        hostname: mysqld_exporter
        ports:
          - 9104:9104
        volumes:
          - ${PWD}/conf/config.my-cnf:/config.my-cnf
        command:
          - "--config.my-cnf=/config.my-cnf"
          - "--collect.binlog_size"
          - "--collect.info_schema.replica_host"
        restart: always
    
  • 启动

    • docker-compose up -d
    • docker-compose ps
    • docker-compose logs

prometheus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["prometheus:9991"]

  - job_name: "mysql"
    params:
      auth_module: [client.servers]
    static_configs:
      - targets:
          - mysql-address:3306
          # - unix:///run/mysqld/mysqld.sock 本机也可以使用sock 文件
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: mysql-exporter-server:9104

grafana

最后结果

  • GitHub 推荐 Success
This post is licensed under CC BY 4.0 by the author.