Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

difficulty connecting to database in docker compose #898

Open
datava-admins opened this issue Nov 26, 2024 · 2 comments
Open

difficulty connecting to database in docker compose #898

datava-admins opened this issue Nov 26, 2024 · 2 comments

Comments

@datava-admins
Copy link

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: c366424)
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
Copy link
Author

datava-admins commented Nov 27, 2024

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.

@SalehBorhani
Copy link

Could you please share your docker-compose file ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants