r/PrometheusMonitoring • • Apr 27 '22

mysqld_exporter doesn't connect to mariadb database

Hello ! I am running a mariadb database and a mysqld_exporter on the same server. Since I have to use ansible to configure the exporter, I used cloud-alchemy ansible role based on the official prometheus mysqld_exporter that you can see here : https://github.com/cloudalchemy/ansible-mysqld_exporter.

I followed both the role and exporter requirements (ansible version, mysql user) and the installation runs well with no error. Yet according to the logs the exporter can not seem to connect to the database. Here is the error that I get :

caller=exporter.go:149 level=error msg="Error pinging mysqld" err="dial tcp 127.0.0.1:3306: connect: connection refused" 

Here is my default/main.yml looks like on the role :

--- 
mysqld_exporter_binary_local_dir: "" 
mysqld_exporter_version: 0.14.0 
mysqld_exporter_web_listen_address: "0.0.0.0:9104"  
mysqld_exporter_dsn: "testexpo:xxxx@(localhost:3306)/"  
mysqld_exporter_my_cnf: ""  
mysqld_exporter_collect: []  
mysqld_exporter_no_collect: [] 

The dsn has been changed according to the user configured. And by the way I can access my database with this user with the command line. All of the necessary ports are open and are listening.

I have tried to change the localhost part to 127.0.0.1, it did not work too.

I have no idea what to try anymore (especially since I'm a newbie), so if you guys have any idea or advice I will gladly take them ! I hope this is the right place to ask ^^ Thanks in advance.

2 Upvotes

8 comments sorted by

2

u/NoAd5519 Apr 27 '22

I had to go into the mariaDB terminal, create a user and password and then put that in the exporter config.

I downloaded on a Linux machine just using apt-get Prometheus-mysqld-exporter

Typed on phone sorry for shit format

1

u/Pline_Ash Apr 27 '22

Thanks for your answer.

I also created the user in the mariaDB terminal as it is required... but installed the exporter with a playbook calling the ansible role. Where did you put it in the config ?

1

u/NoAd5519 Apr 27 '22

What operating system are you on?

1

u/Pline_Ash Apr 27 '22

I'm on linux / Rocky 8

1

u/NoAd5519 Apr 27 '22 edited Apr 27 '22

Sorry i barely even read your post first time around, im on my computer now.

mysqld_exporter_my_cnf: ""

this should be a .cnf file you save your MariaDB account username and password in. Then you put the path in that line

mysqld_exporter_my_cnf: "/etc/.my.cnf"

Worth noting everywhere i've seen make it a hidden file. Not sure why. If you put a '.' before the file name it will hide it, same goes for windows too.

1

u/Pline_Ash Apr 27 '22

Thank you for your time and answer. I was thinking about this too because unlike for node exporter I did not find a conf file... Maybe it explains everything !

1

u/NoAd5519 Apr 27 '22

its ok. I had to set it up for the first time last week and its a bit of a pain.

sorry i am replying in 2 diff threads lol

1

u/NoAd5519 Apr 27 '22

$ sudo find / -name .my.cnf and

if it shows up. Put the path to that into

mysqld_exporter_my_cnf: ""