我正在尝试使用Prometheus,Docker和prom / mysqld-exporter监视MySQL。我已经搜索了许多站点并逐步跟踪所有站点,但是不幸的是我没有得到想要的结果。
主要有两个问题:
错误是:
错误1045(28000):用户'root'@'localhost'的访问被拒绝(使用密码:是)
我还检查了stackoverflow中的常见问题,例如this,并尝试了所有问题,但仍然无法正常工作。我也将command: mysqld --default-authentication-plugin=mysql_native_password
添加到docker-compose文件中的mysql配置中。
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
命令时,我都不会遇到任何错误。
答案 0 :(得分:0)
在docker-compose的mysql导出器环境中将“ localhost”更改为
mostafa:ghadimi @(mysql:3306)/ db