【问题标题】:Can't Monitor MySQL using Prometheus, Docker and prom/mysqld-exporter image无法使用 Prometheus、Docker 和 prom/mysqld-exporter 映像监控 MySQL
【发布时间】:2019-08-04 14:30:42
【问题描述】:

我正在尝试使用 Prometheus、Docker 和 prom/mysqld-exporter 监控 MySQL。我已经搜索了很多网站,并一步一步地关注它们,但不幸的是我没有得到我想要的结果。

主要有两个问题:

  1. 我什至无法使用我在 docker-compose.yml 文件中定义的用户名和密码连接到 mysql。

错误是:

ERROR 1045 (28000): 拒绝用户 'root'@'localhost' 访问(使用密码:YES)

我还检查了 stackoverflow 中的热门问题,例如 this one 并尝试了所有这些问题,但它仍然无法正常工作。我还在 docker-compose 文件中添加了 command: mysqld --default-authentication-plugin=mysql_native_password 到 mysql 的配置中。

  1. 每当我设置DATA_SOURCE_NAME 环境变量时,我都会遇到localhost:9104/metrics 上的指标的http 超时,而我可以毫无问题地获得localhost:9104,虽然我添加了一些标志但它不起作用!

这是我的文件:

docker-compose.yml:

version: '3'

services:
  mysql:
    image: mysql
    container_name: mysql
    restart: always
    volumes: 
      - mysql:/var/lib/mysql
    environment: 
      - MYSQL_ROOT_PASSWORD= password
      - MYSQL_DATABASE= db
      - MYSQL_USER= mostafa
      - MYSQL_PASSWORD= ghadimi
    command: --default-authentication-plugin=mysql_native_password
    ports: 
      - 3306:3306
      - 33060:33060

  adminer:
    image: adminer
    restart: always
    ports: 
      -  8080:8080

  prometheus:
    image: prom/prometheus
    container_name: prometheus
    ports:
      - 9090:9090
    volumes:
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    command: 
      - --config.file=/etc/prometheus/prometheus.yml

  mysql-exporter:
    image: prom/mysqld-exporter
    container_name: mysql-exporter
    ports:
      - 9104:9104
    volumes:
      - ./mysql-exporter/.my.cnf:/root/.my.cnf
    environment: 
      - DATA_SOURCE_NAME='mostafa:ghadimi@(localhost:9104)/db'
      - collect.info_schema.tablestats=true
      - collect.info_schema.userstats=true
      - collect.info_schema.query_response_time=true
      - collect.auto_increment.columns=true
      - collect.binlog_size=true
      - collect.perf_schema.eventsstatements=true
      - collect.perf_schema.eventswaits=true
      - collect.perf_schema.file_events=true
      - collect.perf_schema.indexiowaits=true
      - collect.perf_schema.tableiowaits=true
      - collect.perf_schema.tablelocks=true
    depends_on: 
      - mysql

volumes:
  mysql:

.my.cnf:

[client]
user=mostafa
password=ghadimi

和 prometheus.yml:

global:
    scrape_interval: 15s
    external_labels:
        monitor: 'my-monitor'
scrape_configs:
    # - job_name: 'prometheus'
    #   static_configs:
    #       - targets: ['localhost:9090']

    - job_name: 'mysql-exporter'
      static_configs:
          - targets: ['mysql-exporter:9104']

PS:每当我执行docker-compose up 命令时,我都没有遇到任何错误。

【问题讨论】:

    标签: mysql docker docker-compose monitoring


    【解决方案1】:

    将docker-compose中mysql导出器环境中的“localhost”更改为

    mostafa:ghadimi@(mysql:3306)/db

    【讨论】:

      猜你喜欢
      • 2020-11-14
      • 2019-03-02
      • 2020-06-18
      • 2023-01-05
      • 2019-10-23
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多