prometheus / mysqld_exporter

Exporter for MySQL server metrics
http://prometheus.io/
Apache License 2.0
2.17k stars 759 forks source link

difficulty connecting to database in docker compose #898

Open datava-admins opened 4 days ago

datava-admins commented 4 days ago

Host operating system: output of uname -a

Linux 5.15.0-126-generic #136-Ubuntu SMP Wed Nov 6 10:38:22 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

mysqld_exporter version: output of mysqld_exporter --version

mysqld_exporter, version 0.16.0 (branch: HEAD, revision: c366424252a3140838a344a6cb0d40d44f1be91d) go version: go1.23.3 platform: linux/amd64 tags: unknown

MySQL server version

mysqld_exporter command line flags

--config.my-cnf=/opt/mysqld_exporter/.my.cnf --web.listen-address=0.0.0.0:9104 --log.level=debug --mysqld.address=db:3306

What did you do that produced an error?

I am trying to configure mysqld-exporter in a docker container. My mysql databases is in another docker container. I am using a docker compose. My mysql container is named db. I have also tried adding "Host=db Port=3306" to my .my .cnf file and adding the environment variable "DATA_SOURCE_NAME=exporter:${MYSQL_EXPORTER_USER_PASSWORD}@(db:3306)" .

What did you expect to see?

mysql_up = 1 in my metrics

What did you see instead?

in prometheus mysql_up show as 0, but from my prometheus host I can do "curl :9104" | grep mysql_up and it shows mysql_up 1

in my docker compose logs I see error: time=2024-11-26T18:48:37.386Z level=ERROR source=exporter.go:131 msg="Error opening connection to database" err="dial tcp: lookup tcp///: unknown port"

There is no mention of my db hosts fqdn in any of the configuration files and the exporter is in a docker container, so it should be trying to connect to db:3306

By the other metrics it the exporter appears to be able to connect to my database so I am super confused where/why the exporter is trying to connect to the db host at an unknown port instead of to db:3306

datava-admins commented 4 days ago

After more investigation this issue only comes up when I attempt to connect to the mysqld-exporter via an apache proxy. I had apache set up to proxy traffic to /internal/metric/path to http://db-exporter:9104 and the error listed above only comes up if I attempt to scrape the exporter via the proxy. If I expose the port on the host and scrape it directly this issue doesn't occur. There was no difference in configuration other then hitting the exposed port compared to the proxy address.