1

I have a Munin script /etc/munin/plugins/mysql_replag that queries a MySQL server to check the status of a master-slave replication:

#!/bin/sh
# Plugin to monitor the Seconds_Behind_Master of replication on a MySQL slave

MYSQLOPTS="$mysqlopts"
MYSQL=${mysql:-mysql}
if [ "$1" = "autoconf" ]; then
        $MYSQL --version 2>/dev/null >/dev/null
        if [ $? -eq 0 ]
        then
                $MYSQL $MYSQLOPTS -e '' 2>/dev/null >/dev/null
                if [ $? -eq 0 ]
                then
                        echo yes
                        exit 0
                else
                        echo "no (could not connect to mysql)"
                fi
        else
                echo "no (mysql not found)"
        fi
        exit 1
fi

if [ "$1" = "config" ]; then
        echo 'graph_title Replication lag'
        echo 'graph_args --base 1000 -l 0'
        echo 'graph_vlabel lag in secs'
        echo 'graph_category mysql'
        echo 'lag.label lag'
        exit 0
fi

/usr/bin/printf "lag.value "
mysql $MYSQLOPTS -e 'show slave status\G' | grep Seconds_Behind_Master | awk '{print $2}'

The plugin config file is /etc/munin/plugin-conf.d/mysql_replag: (note: edited)

[mysql_replag]
user root
env.mysqlopts -umyuser -pmyp4ssw0rd -h 10.13.13.13

However, the plugin config file is apparently ignored when running the plugin:

# munin-run mysql_replag 
lag.value ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

The plugin works when I remove the MySQL options from the config file and I specify them in the plugin directly via the $MYSQLOPTS variable. Why is the config file ignored?

2

Variables in munin are declared using env.myvariable, not env.var myvariable; try this:

env.mysqlopts -umyuser -pmyp4ssw0rd -h 10.13.13.13
  • Hmmm, strange. I now realize that my config file on the server uses the correct syntax while my question used the wrong syntax. Either I made a mistake copying or I realized my error on the server but forgot to update the question. +1 anyway as your suggestion is good even if it doesn't solve my problem. – dr01 Aug 31 '15 at 12:47
  • It is working now. It appears that I made a mistake in the config file name. Marking your answer as accepted since it allowed me to find the error. – dr01 Aug 31 '15 at 13:17
1

I was trying to configure mysql_queries plugin using this format, because that is what I found under /usr/share/munin/plugins/mysql_

[mysql*]

env.mysqluser MyUser
env.mysqlpassword MyPassword

Thanks to Patrice Levesque's response I realised that some Mysql munin plugins (e.g mysql_queries) use this format:

[mysql_queries]
env.mysqlopts -uMyUser -pMyPassword

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.