longview icon indicating copy to clipboard operation
longview copied to clipboard

MySQL agent does not work if using non-standard socket

Open tmcallaghan opened this issue 11 years ago • 7 comments

My server's socket is /tmp/mysql.sock, Perl DBI:MySQL is hard coded to '/var/lib/mysql/mysql.sock'.

Rather than create a symlink, I modified line 69 in DataGetter/Applications/MySQL.pm, adding my specific socket.

my $dbh = DBI->connect_cached( "DBI:mysql:host=localhost;mysql_socket=/tmp/mysql.sock;", $creds->{username}, $creds->{password} ) or do {

It would be better if I could provide a non-default socket in the Longview MySQL configuration file.

tmcallaghan avatar Aug 08 '14 12:08 tmcallaghan

Just a thought on this from a sysadmin perspective... MySQL servers usually contain the MySQL client for management and have their root unix users configured with the root MySQL credentials and connection information under /root/.my.cnf. Could this root MySQL client be used to dynamically determine the socket location if no defaults exist e.g. /tmp/mysql.sock, /var/lib/mysql/mysql.sock?

jowy avatar Aug 13 '14 19:08 jowy

From what I've read, DBD:Perl uses /var/lib/mysql/mysql.sock if you don't specify otherwise. It does not look for /etc/my.cnf to figure out the socket. For now, patching the MySQL.pm file in Longview works for me.

tmcallaghan avatar Aug 13 '14 21:08 tmcallaghan

The best solution would be to just use 'mysql_read_default_group' to tell libmysqlclient to read the my.cnf file for settings, which can be done with the following DBI connection string:

DBI:mysql:mysql_read_default_group=client

dwfreed avatar Aug 13 '14 21:08 dwfreed

I agree that anything is better than me having to patch the Longview code myself. It seems appropriate to me that the app should figure out the socket from the usual my.cnf locations and/or allow me to specify the socket in the Longview mysql config file.

tmcallaghan avatar Aug 13 '14 23:08 tmcallaghan

Ideally host config var could be supported in /etc/linode/longview.d/MySQL.conf

I run my infra on docker and needed to make the following change to get Longview to pick up data:

sed -i -e '/s/DBI:mysql:host=localhost/DBI:mysql:host=0.0.0.0/g' /opt/linode/longview/Linode/Longview/DataGetter/Applications/MySQL.pm

There is no shared socket for docker, so localhost (a special alias for the socket) doesn't work

buley avatar Jan 21 '15 07:01 buley

Same problem, should i correct like this ?

sed -i -e '/s/DBI:mysql:host=localhost/DBI:mysql:mysql_read_default_group=client:host=localhost/g' /opt/linode/longview/Linode/Longview/DataGetter/Applications/MySQL.pm

akh1 avatar Apr 13 '16 16:04 akh1

I think it'd be neat if it used the my.cnf config for this. Would be nice if it checked a longview group first before checking client so you can give longview it's own thing. Or at the very least have it so you can specify a config file to use (ala defaults-extra-file)

tarqd avatar Jul 27 '17 01:07 tarqd