MySQL数据监控案例_zabbix 监控mysql实例

监控mysql

zabbix自带mysql模板监控mariadb,更全面的监控可以自行编写脚本或才通过第三方模板,如http://www.fromdual.com/mpm-installation-guide

在要监控的mysql主机上

1.安装zabbix客户端

2.创建具有监控权限的数据库用户

GRANT USAGE ON *.* TO

'zabbix'@'localhost' IDENTIFIED BY 'zabbix';

FLUSH PRIVILEGES;

3.创建数据库连接配置文件

root@jlive:~#cat

>/usr/local/zabbix/etc/.my.cnf <

[mysql]

host  = localhost

user  = zabbix

password = zabbix

socket  =

/tmp/mysql.sock

[mysqladmin]

host  = localhost

user  = zabbix

password = zabbix

socket  =

/tmp/mysql.sock

HERE

可根据环境不同作相应调整

4.使用zabbix

mysql模板配置文件userparameter_mysql.conf

cp

/usr/local/src/zabbix-3.0.2/conf/zabbix_agentd/userparameter_mysql.conf

/usr/local/zabbix/etc/zabbix_agentd.conf.d

sed -i

's#/var/lib/zabbix#/usr/local/zabbix/etc#g'

/usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf

在agentd主配置文件中Include进来

sed -i '$ a

Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d'

/usr/local/zabbix/etc/zabbix_agentd.conf

5.重启zabbix_agentd

/etc/init.d/zabbix_agentd restart

6.测试

root@jlive:~#zabbix_agentd

-c /usr/local/zabbix/etc/zabbix_agentd.conf -t

mysql.status[uptime]

mysql.status[uptime] [t|11914]

root@jlive:~#zabbix_get

-s localhost -p 10050 -k 'mysql.status[Bytes_received]'

sh: mysql: command not found

日志里也一直提示mysql命令not found

61652:20160430:223023.549

item "Zabbix server:mysql.status[Bytes_received]" became not

supported: Received value [sh: mysql: command not found] is not

suitable for value type [Numeric (float)]

61650:20160430:223024.550

item "Zabbix server:mysql.status[Bytes_sent]" became not supported:

Received value [sh: mysql: command not found] is not suitable for

value type [Numeric (float)]

61652:20160430:223025.552

item "Zabbix server:mysql.status[Com_begin]" became not supported:

Received value [sh: mysql: command not found] is not suitable for

value type [Numeric (float)]

61653:20160430:223026.552

item "Zabbix server:mysql.status[Com_commit]" became not supported:

Received value [sh: mysql: command not found] is not suitable for

value type [Numeric (float)]

61650:20160430:223027.554

item "Zabbix server:mysql.status[Com_delete]" became not supported:

Received value [sh: mysql: command not found] is not suitable for

value type [Numeric (float)]

61653:20160430:223028.555

item "Zabbix server:mysql.status[Com_insert]" became not supported:

Received value [sh: mysql: command not found] is not suitable for

value type [Numeric (float)]

61652:20160430:223029.557

item "Zabbix server:mysql.status[Com_rollback]" became not

supported: Received value [sh: mysql: command not found] is not

suitable for value type [Numeric (float)]

61646:20160430:223501.719

executing housekeeper

61646:20160430:223501.742

housekeeper [deleted 0 hist/trends, 1 items, 0 events, 0 sessions,

0 alarms, 0 audit items in 0.021534 sec, idle for 1

hour(s)]

但实际上mysql命令是存在的,只是非标准路径,mariadb安装在/opt/mariadb下,故mysql命令的绝对路径是/opt/mariadb/bin/mysql,但我己经在/etc/profile中作了全局申明,export

PATH=/opt/mariadb/bin:$PATH,但还是报mysql  not

found,于是百度了下,还真有朋友碰到相同的问题,试了下

解决方案

A./usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf中的所有mysql,mysqladmin替换为绝对路径

或者

B.将mysql,mysqladmin软链到/usr/bin下

ln -s

/opt/mariadb/bin/{mysql,mysqladmin} /usr/bin

注意:软链到/usr/local/bin下无效,只能呵呵了

推荐B方案,软链后立马就生效了

root@jlive:~#zabbix_get

-s localhost -p 10050 -k 'mysql.status[Bytes_received]'

17963712

61653:20160430:223522.880

item "Zabbix server:mysql.ping" became supported

61650:20160430:223523.882

item "Zabbix server:mysql.status[Bytes_received]" became

supported

61651:20160430:223524.883

item "Zabbix server:mysql.status[Bytes_sent]" became

supported

61652:20160430:223525.884

item "Zabbix server:mysql.status[Com_begin]" became

supported

61650:20160430:223526.887

item "Zabbix server:mysql.status[Com_commit]" became

supported

61651:20160430:223527.888

item "Zabbix server:mysql.status[Com_delete]" became

supported

61653:20160430:223528.889

item "Zabbix server:mysql.status[Com_insert]" became

supported

61652:20160430:223529.891

item "Zabbix server:mysql.status[Com_rollback]" became

supported

61653:20160430:223530.892

item "Zabbix server:mysql.status[Com_select]" became

supported

61650:20160430:223531.894

item "Zabbix server:mysql.status[Com_update]" became

supported

61651:20160430:223532.895

item "Zabbix server:mysql.status[Questions]" became

supported

61652:20160430:223533.895

item "Zabbix server:mysql.status[Slow_queries]" became

supported

61653:20160430:223534.896

item "Zabbix server:mysql.status[Uptime]" became

supported

a4c26d1e5885305701be709a3d33442f.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值