Mysql – How to monitor MySQL socket using icinga2

icinga2monitoringMySQL

I would like to monitor my MySQL server using icinga2 as the title shows above. My MySQL server uses a unix socket. I tried the following:

object Service "MYSQL" {
    import "generic-service"
    check_command = "mysql"
    vars.mysql_query_hostname = "/var/run/mysqld/mysqld.sock"
    vars.mysql_ignore_auth = true
    vars.mysql_port = 6800
    host_name = "mysql.server"
    }

and I restart the icinga2 service. When I check from icinga2 web, I have the following error for the MySQL service:
Plugin Output
Can't connect to MySQL server on '192.168.2.4' (111)

It seems that icinga2 can't check the MySQL service using the unix socket. Is there something wrong with the config I'm using?

EDIT 1:
So, I've installed icinga2 on the client and configured it as a satellite. I've been reading that icinga2 agent is the elegant way to monitor services on a remote service. Since this setup will stay, I'm willing to spend time and efforts to configure everything properly.

On the server, /etc/icinga2/conf.d/services.conf

apply Service "MySQL" {
import "generic-service"
check_command = "mysql"
command_endpoint = host.vars.client_endpoint
assign where host.vars.client_endpoint == "client1.example.com"
}

/etc/icinga2/conf.d/hosts.conf

object Host "client1.example.com" {
import "generic-host"
address = "192.168.2.4"
vars.client_endpoint = "client1.example.com"
vars.mysql_hostname = "/var/run/mysqld/mysqld.sock"
}

On the client, I've installed the required plugin "check_mysql" and icinga2 is running. When I check through the icinga2 web interface, I still get the following plugin output:
Plugin Output Can't connect to MySQL server on '192.168.2.4' (111)
It seems that it is still checking through TCP. What am I doing wrong?

Best Answer

Is Icinga2 runs on the same server of your MySQL service ? In this case you would have a problem in your command. Can you paste the detail of your command in your question.

In other case, to test a Unix socket for mysql which not listen on a TCP port, you must use NRPE or SSH to connect to your mysql server and check the service. The result will be send to your icinga2 server.

EDIT 1 :

If you want to test a service which has not a listener on the network on a remote server, you can use several things :

  1. check_by_ssh

With that, you will be able to execute remote commands on your remote server and the answer of this command will be send to your icinga2 server. This solution impose a ssh configuration between yous servers.

  1. NRPE

Otherwise, you can install NRPE on the remote server and execute commands with their results will be send to your icinga2 server.

NRPE can be run on windows or linux.

I think these two solutions are more simple than install icinga2 as a satellite on all your servers to be supervised.