Module: check_mk
Branch: master
Commit: 9230a05fd5bb01cfe076560bb2228ddfc6350577
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9230a05fd5bb01…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Wed Apr 17 15:13:46 2019 +0200
mk_mysql: Filter after mysqld when detecting instance names
- Remove too unnecessary grep regex trick as ps already filters after process
- Fix queries to instances specifying socket input
Change-Id: I72c96ea227ab3dd065939ce202524499778a8100
---
agents/plugins/mk_mysql | 28 ++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)
diff --git a/agents/plugins/mk_mysql b/agents/plugins/mk_mysql
index 117fc6c..31f781b 100755
--- a/agents/plugins/mk_mysql
+++ b/agents/plugins/mk_mysql
@@ -25,14 +25,14 @@
# gets optional socket as argument
function do_query() {
- SOCKET="$1"
- COUNT=$(ps -fww -C mysqld | grep socket | wc -l)
+ MYSQLDPS=$(ps -fww -C mysqld | grep -- --socket=$1)
+ COUNT=$(echo $MYSQLDPS | wc -l)
if [ $COUNT -gt 1 ]
then
- INSTANCE_NAME=$(ps -efww|grep socket|grep "${SOCKET}"|grep
"[u]ser" | sed -ne 's/.*socket=\([^.]*\).*/\1/p')
+ INSTANCE_NAME=$(echo $MYSQLDPS | sed -ne 's/.*socket=\([^.]*\).*/\1/p')
INSTANCE_NAME="[[${INSTANCE_NAME##*/}]]"
else
- INSTANCE_NAME="[[$(ps -efww|grep socket|grep "${SOCKET}"|grep
"[u]ser" | sed -ne 's/.*user=\([^ ]*\).*/\1/p')]]"
+ INSTANCE_NAME="[[$(echo $MYSQLDPS | sed -ne 's/.*user=\([^
]*\).*/\1/p')]]"
fi
@@ -40,24 +40,24 @@ function do_query() {
# Check if mysqld is running and root password setup
echo "<<<mysql_ping>>>"
echo $INSTANCE_NAME
- mysqladmin --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 ping 2>&1
+ mysqladmin --defaults-extra-file=$MK_CONFDIR/mysql.cfg --socket=$1 ping 2>&1
if [ $? -eq 0 ]; then
echo "<<<mysql>>>"
echo $INSTANCE_NAME
- mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 -sN \
+ mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg --socket=$1 -sN \
-e "show global status ; show global variables ;"
echo "<<<mysql_capacity>>>"
echo $INSTANCE_NAME
- mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 -sN \
+ mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg --socket=$1 -sN \
-e "SELECT table_schema, sum(data_length + index_length), sum(data_free)
FROM information_schema.TABLES GROUP BY table_schema"
echo "<<<mysql_slave>>>"
echo $INSTANCE_NAME
- mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 -s \
+ mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg --socket=$1 -s \
-e "show slave status\G"
fi
@@ -68,7 +68,7 @@ if which mysqladmin >/dev/null
then
mysql_sockets=$(fgrep socket $MK_CONFDIR/mysql.cfg|sed -ne 's/.*socket=\([^
]*\).*/\1/p')
if [ -z "$mysql_sockets" ] ; then
- mysql_sockets=$(ps -fww -C mysqld | grep "[s]ocket" | sed -ne
's/.*socket=\([^ ]*\).*/\1/p')
+ mysql_sockets=$(ps -fww -C mysqld | grep "socket" | sed -ne
's/.*socket=\([^ ]*\).*/\1/p')
fi
if [ -z "$mysql_sockets" ] ; then
do_query ""
@@ -77,16 +77,8 @@ then
do_query "$socket"
done
fi
- #echo "<<<mysql_version>>>"
- #mysql -V
echo "<<<mysql_port>>>"
- ps -fww -C mysqld |while read LINE; do echo $LINE|grep "[u]ser" | sed -ne
's/.*user=\([^ ]*\).*/\1/p'; echo $LINE|grep mysqld | grep "[p]ort"|sed
-ne 's/.*port=\([^ ]*\).*/\1/p' ; done|xargs -n2
-
- #echo "<<<mysql_instances>>>"
- #mysql --defaults-extra-file=$MK_CONFDIR/mysql.cfg $1 -s \
- # -e "show INSTANCES"
+ ps -fww -C mysqld |while read LINE; do echo $LINE| sed -ne 's/.*user=\([^
]*\).*/\1/p'; echo $LINE|sed -ne 's/.*port=\([^ ]*\).*/\1/p' ; done|xargs -n2
fi
-
-