我有一个 Munin 脚本/etc/munin/plugins/mysql_replag
,用于查询 MySQL 服务器以检查主从复制的状态:
#!/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}'
插件配置文件是/etc/munin/plugin-conf.d/mysql_replag
:(注:已编辑)
[mysql_replag]
user root
env.mysqlopts -umyuser -pmyp4ssw0rd -h 10.13.13.13
但是,运行插件时插件配置文件显然被忽略:
# munin-run mysql_replag
lag.value ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
当我从配置文件中删除 MySQL 选项并直接通过变量在插件中指定它们时,该插件即可工作$MYSQLOPTS
。为什么配置文件被忽略?
答案1
munin 中的变量是使用 env.myvariable 声明的,而不是 env.var myvariable;尝试这个:
env.mysqlopts -umyuser -pmyp4ssw0rd -h 10.13.13.13
答案2
我试图mysql_queries
使用这种格式配置插件,因为这是我在下面找到的/usr/share/munin/plugins/mysql_
[mysql*]
env.mysqluser MyUser
env.mysqlpassword MyPassword
感谢 Patrice Levesque 的回复,我意识到一些 Mysql munin 插件(例如mysql_queries
)使用这种格式:
[mysql_queries]
env.mysqlopts -uMyUser -pMyPassword