From f18e2078470ae21aa3ae6c1adace4cd2fc187f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Weigert?= Date: Fri, 23 May 2025 10:34:46 +0200 Subject: [PATCH] Enforce socket protocol in mk_mysql With multiple instances per host the plugin may or may not show the correct data for each instance. It may happen, that all graphs show the same instance. This depends on the mysql client tool. It has some builtin logic to decide if it prefers TCP Port connctions or socket connections. E.g. on debian 12, mariadb-client-10.11.11 the behaviour depends on how the host is specified. With host=localhost, the socket is used, with host=127.0.0.1 the (default) TCP port 3306 is used. When setting up the plugin in the agent bakery, the prefilled host field reads 127.0.0.1 and thus caused me to see false data for my second instance (as both were queried at the same default TCP port). I suggest to always use the --protocol=socket option together with the --socket=.... option. This enforces that the specified socket parameter is actually used. The --protocol=socket option exists with all mysql mysaladmin tools since version 4.1 (and also in mariadb / mariadbadmin) --- agents/plugins/mk_mysql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/agents/plugins/mk_mysql b/agents/plugins/mk_mysql index 00e1f41a745..1c8e8cdb9e9 100755 --- a/agents/plugins/mk_mysql +++ b/agents/plugins/mk_mysql @@ -23,21 +23,21 @@ do_query() { # Check if mysqld is running and root password setup echo "<<>>" echo "$INSTANCE_HEADER" - $MYSQLADMIN --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--socket="$1"} ping 2>&1 || return + $MYSQLADMIN --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--protocol=socket --socket="$1"} ping 2>&1 || return echo "<<>>" echo "$INSTANCE_HEADER" - $MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--socket="$1"} -sN \ + $MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--protocol=socket --socket="$1"} -sN \ -e "show global status ; show global variables ;" echo "<<>>" echo "$INSTANCE_HEADER" - $MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--socket="$1"} -sN \ + $MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--protocol=socket --socket="$1"} -sN \ -e "SELECT table_schema, sum(data_length + index_length), sum(data_free) FROM information_schema.TABLES GROUP BY table_schema" - MYSQL_VERSION=$($MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--socket="$1"} -s -e "SELECT VERSION();" | grep -o '^[0-9]\+') - MYSQL_FULL_VERSION=$($MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--socket="$1"} -s -e "SELECT VERSION();") + MYSQL_VERSION=$($MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--protocol=socket --socket="$1"} -s -e "SELECT VERSION();" | grep -o '^[0-9]\+') + MYSQL_FULL_VERSION=$($MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--protocol=socket --socket="$1"} -s -e "SELECT VERSION();") echo "<<>>" echo "$INSTANCE_HEADER" @@ -49,7 +49,7 @@ do_query() { else STATUS_COMMAND="SHOW SLAVE STATUS\G" fi - $MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--socket="$1"} -s \ + $MYSQL --defaults-file="$MK_CONFDIR"/mysql.cfg ${1:+--protocol=socket --socket="$1"} -s \ -e "$STATUS_COMMAND" }