码迷,mamicode.com
首页 > 数据库 > 详细

zabbix监控mysql(perl)

时间:2014-10-01 00:41:10      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:zabbix   mysql   perl   

1.

yum install perl-libwww-perl

yum install perl-File-Which 

yum install perl-DBD-MySQL

yum install perl-Digest-SHA1

yum install perl-Time-HiRes

yum install perl-Crypt-SSLeay


2.测试

#!/usr/bin/perl -w

use DBI;


my $database = "mysql";

my $hostname = "localhost";

my $data_source = "DBI:mysql:$database:$hostname";


my $username = "root";

my $password = "123";

my $dbh = DBI->connect( $data_source,$username,$password)

or die "Cant connect to $data_source";


perl test  测试成功


3.在zabbix server端导入监控模板 (13个模版)

Template_FromDual.MySQL.mpm.xml –>(必须)

Template_FromDual.MySQL.server.xml –>监控与数据库相关的Linux服务器性能模板

Template_FromDual.MySQL.process.xml –>监控各种Linux进程

Template_FromDual.MySQL.mysql.xml –>监控Mysql的常用状态变量

Template_FromDual.MySQL.myisam.xml –>监控Myisam存储引擎状态变量

Template_FromDual.MySQL.innodb.xml –>监控Innodb存储引擎状态变量

Template_FromDual.MySQL.master.xml –>监控Mysql Master状态

Template_FromDual.MySQL.slave.xml –>监控Mysql Slave状态


4.agentd

mkdir -p /usr/local/mpm

mv mysql_performance_monitor_agent-0.9 /usr/local/mpm/

cp /usr/local/mpm/etc/FromDualMySQLagent.conf.template /etc/zabbix_mpm.conf

chown zabbix /etc/zabbix_mpm.conf

#mkdir /var/log/zabbix

#touch /var/log/zabbix/FromDualMySQLagent.log

#chown -R zabbix:zabbix /var/log/zabbix

vim  /usr/local/etc/zabbix_agentd.conf

UserParameter=FromDual.MySQL.check,/usr/local/mpm/FromDualMySQLagent.pl /etc/zabbix_mpm.conf


5.配置

mpm支持监控多个实例

设置三个级别defaut-->host-->instanc


vim /etc/zabbix_mpm.conf

[default]

Type = mysqld

Debug = 2

LogFile = /tmp/FromDualMySQLagent.log


# Information for MySQL connections:

Username = root

Password = 123

MysqlHost = localhost

MysqlPort = 3306

Modules = process mysql myisam innodb


# Zabbix Server IP address

ZabbixServer = X.X.X.X


#下面的主机名需要跟Zabbix Server里面定义的主机名一致

[X.X.X.X]

Type = mysqld

Modules = mpm server process mysql myisam innodb


[mysql01-5.5.21] # This MUST match Hostname in Zabbix!

Type = mysqld

MysqlPort = 3306

Modules = process mysql myisam slave innodb master mpm server

PidFile = /data/mysql/log/mysql.pid


修改FromDualMySQLagent.pl脚本里面的zabbix_sender路径:

# This is needed to find zabbix_sender!

$ENV{PATH} .= $ENV{PATH} . ‘:/usr/local/bin’; #将/usr/local/bin修改为zabbix_sender路径

chmod 755  chown zabbix:zabbix  /usr/local/bin/zabbix_sender

本文出自 “muzinan的技术博客” 博客,请务必保留此出处http://muzinan110.blog.51cto.com/684213/1559785

zabbix监控mysql(perl)

标签:zabbix   mysql   perl   

原文地址:http://muzinan110.blog.51cto.com/684213/1559785

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!