gpt4 book ai didi

mysql - 无法使用 Prometheus、Docker 和 prom/mysqld-exporter 镜像监控 MySQL

转载 作者:行者123 更新时间:2023-11-29 15:43:17 27 4
gpt4 key购买 nike

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

有两个主要问题:

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

错误是:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

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

  • 每当我设置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命令时,我都没有遇到任何错误。

    最佳答案

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

    mostafa:ghadimi@(mysql:3306)/db

    关于mysql - 无法使用 Prometheus、Docker 和 prom/mysqld-exporter 镜像监控 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57347415/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com