Zabbix3.0.4监控Mysql
2017-12-07 16:05
429 查看
环境是CentOS 7.2 x86_64系统
Zabbix版本:3.0.4
MySQL Server 版本:5.6.29 二进制安装
zabbix_agentd.conf的配置文件如下:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# cat /usr/local/zabbix/etc/zabbix_agentd.conf | grep -v '^#' | grep -v '^$'
LogFile=/tmp/zabbix_agentd.log
EnableRemoteCommands=1
Server=10.18.3.193
ListenPort=10050
ServerActive=10.18.3.193
Hostname=10.18.3.191
AllowRoot=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/.conf
UnsafeUserParameters=1
#下面两行是自定义的key
UserParameter=mysql.slave,/usr/local/zabbix/share/zabbix/alertscripts/check_mysql_slave.sh | grep -c 'ok'
UserParameter=mysql.status[],/usr/local/zabbix/share/zabbix/alertscripts/mysql_server_status.sh $1
查看mysql授权:
mysql授权需要密码才能访问,但是使用密码mysql会提示明文密码,就会有下面的提示:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# sh check_mysql_slave.sh
Warning: Using a password on the command line interface can be insecure.
ok -slave is running
解决办法如下:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# cat /etc/my.cnf | tail -4
[client]
user = root
host = localhost
password = 1qaz@WSX
再次运行脚本:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# sh check_mysql_slave.sh
ok -slave is running
mysql主从监控脚本,脚本中去掉用户,密码直接使用命令。
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# cat check_mysql_slave.sh
#!/bin/bash
declare -a slave_is
slave_is=($(/data/mysql/bin/mysql -e "show slave status\G"|grep -E "Slave_IO_Running|Slave_SQL_Running:"|awk '{print $2}'))
if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ];then
echo "ok -slave is running"
exit 0
else
echo "down -slave is not running"
exit 2
fi
mysql_server_status脚本,这块上面my.cnf填写以后,使用mysqladmin也就不提示了:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# cat mysql_server_status.sh
#!/bin/bash
source /etc/profile
mysqladmin=
case $1 in
Uptime)
result=
echo $result
;;
Com_update)
result=
echo $result
;;
Slow_queries)
result=
echo $result
;;
Com_select)
result=
echo $result
;;
Com_rollback)
result=
echo $result
;;
Questions)
result=
echo $result
;;
Com_insert)
result=
echo $result
;;
Com_delete)
result=
echo $result
;;
Com_commit)
result=
echo $result
;;
Bytes_sent)
result=
echo $result
;;
Bytes_received)
result=
echo $result
;;
Com_begin)
result=
echo $result
;;
esac
在zabbix_server获取key值,或是查看zabbix_server.log文件都可以排错。
[root@iZuf67iz9o3i4wixgtwybmZ bin]# ./zabbix_get -s 10.18.3.191 -k mysql.status[Uptime]
ZBX_NOTSUPPORTED: Unsupported item key.
[root@iZuf67iz9o3i4wixgtwybmZ bin]# ./zabbix_get -s 10.18.3.191 -k mysql.status[Uptime]
/usr/local/zabbix/share/zabbix/alertscripts/mysql_server_status.sh: line 4: mysqladmin: command not found
[root@iZuf67iz9o3i4wixgtwybmZ bin]# ./zabbix_get -s 10.18.3.191 -k mysql.status[Uptime]
414242
zabbix_agent.log可以看到已经获取到自定义的key:
添加自定义模板,模板名称随意给个和mysql相关的:
创建应用集:
添加监控项,一个key一个key添加,把脚本的key都添加进去。
如下所示:
mysql 状态这块只做了图形查看,并没有做触发器,只做了主从的触发器,需要的可以自己添加:
添加完成后可以添加一台mysql数据库查看下最新数据,是否成功了。
查看图形监控数据:
Zabbix版本:3.0.4
MySQL Server 版本:5.6.29 二进制安装
zabbix_agentd.conf的配置文件如下:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# cat /usr/local/zabbix/etc/zabbix_agentd.conf | grep -v '^#' | grep -v '^$'
LogFile=/tmp/zabbix_agentd.log
EnableRemoteCommands=1
Server=10.18.3.193
ListenPort=10050
ServerActive=10.18.3.193
Hostname=10.18.3.191
AllowRoot=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/.conf
UnsafeUserParameters=1
#下面两行是自定义的key
UserParameter=mysql.slave,/usr/local/zabbix/share/zabbix/alertscripts/check_mysql_slave.sh | grep -c 'ok'
UserParameter=mysql.status[],/usr/local/zabbix/share/zabbix/alertscripts/mysql_server_status.sh $1
查看mysql授权:
mysql授权需要密码才能访问,但是使用密码mysql会提示明文密码,就会有下面的提示:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# sh check_mysql_slave.sh
Warning: Using a password on the command line interface can be insecure.
ok -slave is running
解决办法如下:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# cat /etc/my.cnf | tail -4
[client]
user = root
host = localhost
password = 1qaz@WSX
再次运行脚本:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# sh check_mysql_slave.sh
ok -slave is running
mysql主从监控脚本,脚本中去掉用户,密码直接使用命令。
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# cat check_mysql_slave.sh
#!/bin/bash
declare -a slave_is
slave_is=($(/data/mysql/bin/mysql -e "show slave status\G"|grep -E "Slave_IO_Running|Slave_SQL_Running:"|awk '{print $2}'))
if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ];then
echo "ok -slave is running"
exit 0
else
echo "down -slave is not running"
exit 2
fi
mysql_server_status脚本,这块上面my.cnf填写以后,使用mysqladmin也就不提示了:
[root@iZuf67iz9o3i4wixgtwybnZ alertscripts]# cat mysql_server_status.sh
#!/bin/bash
source /etc/profile
mysqladmin=
which mysqladmin
case $1 in
Uptime)
result=
${mysqladmin} status|cut -f2 -d":"|cut -f1 -d"T"
echo $result
;;
Com_update)
result=
${mysqladmin} extended-status |grep -w "Com_update"|cut -d"|" -f3
echo $result
;;
Slow_queries)
result=
${mysqladmin} status |cut -f5 -d":"|cut -f1 -d"O"
echo $result
;;
Com_select)
result=
${mysqladmin} extended-status |grep -w "Com_select"|cut -d"|" -f3
echo $result
;;
Com_rollback)
result=
${mysqladmin} extended-status |grep -w "Com_rollback"|cut -d"|" -f3
echo $result
;;
Questions)
result=
${mysqladmin} status|cut -f4 -d":"|cut -f1 -d"S"
echo $result
;;
Com_insert)
result=
${mysqladmin} extended-status |grep -w "Com_insert"|cut -d"|" -f3
echo $result
;;
Com_delete)
result=
${mysqladmin} extended-status |grep -w "Com_delete"|cut -d"|" -f3
echo $result
;;
Com_commit)
result=
${mysqladmin} extended-status |grep -w "Com_commit"|cut -d"|" -f3
echo $result
;;
Bytes_sent)
result=
${mysqladmin} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3
echo $result
;;
Bytes_received)
result=
${mysqladmin} extended-status |grep -w "Bytes_received" |cut -d"|" -f3
echo $result
;;
Com_begin)
result=
${mysqladmin} extended-status |grep -w "Com_begin"|cut -d"|" -f3
echo $result
;;
*) echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)" ;;
esac
在zabbix_server获取key值,或是查看zabbix_server.log文件都可以排错。
[root@iZuf67iz9o3i4wixgtwybmZ bin]# ./zabbix_get -s 10.18.3.191 -k mysql.status[Uptime]
ZBX_NOTSUPPORTED: Unsupported item key.
[root@iZuf67iz9o3i4wixgtwybmZ bin]# ./zabbix_get -s 10.18.3.191 -k mysql.status[Uptime]
/usr/local/zabbix/share/zabbix/alertscripts/mysql_server_status.sh: line 4: mysqladmin: command not found
[root@iZuf67iz9o3i4wixgtwybmZ bin]# ./zabbix_get -s 10.18.3.191 -k mysql.status[Uptime]
414242
zabbix_agent.log可以看到已经获取到自定义的key:
添加自定义模板,模板名称随意给个和mysql相关的:
创建应用集:
添加监控项,一个key一个key添加,把脚本的key都添加进去。
如下所示:
mysql 状态这块只做了图形查看,并没有做触发器,只做了主从的触发器,需要的可以自己添加:
添加完成后可以添加一台mysql数据库查看下最新数据,是否成功了。
查看图形监控数据:
相关文章推荐
- zabbix3.0.4监控mysql主从同步
- zabbix3.0.4使用percona-monitoring-plugins插件来监控mysql5.6的详细实现过程
- zabbix3.0.4监控mysql主从同步
- CentOS 6.5 zabbix 3.0.4 监控MySQL性能
- zabbix3.0.4使用percona-monitoring-plugins插件来监控mysql5.6的详细实现过程
- zabbix 3.0.4 监控windows 服务
- zabbix监控mysql主从复制
- zabbix监控mysql客户端
- zabbix开源监控系列二(mysql+redis 模板)
- 借助zabbix和mysql performance monitor模板实现mysql数据库的监控 推荐
- Zabbix-agent使用自带模板监控 MySQL
- zabbix监控nginx,Mysqld,Php状态,MySQL主从复制状态
- 第二次部署Zabbix 3.0使用percona模板监控MySQL,遇到的问题和解决过程
- zabbix自动发现mysql端口并监控 推荐
- zabbix监控parameter mysql的状态
- zabbix笔记--监控MySQL
- zabbix监控parameter mysql的状态
- Zabbix3.0.4监控Windows的CPU使用百分比并在CPU使用率超过90%触发报警
- Zabbix 的 MySQL 监控客户端配置
- zabbix通过percona插件监控mysql的方法