mysql cacti_cacti 监控 mysql 的几种方法 _ 参考用

插件一(可用,推荐):

来源:http://code.google.com/p/mysql-cacti-templates/

一,脚本下载以及设置

wget http://mysql-cacti-templates.googlecode.com/files/mysql-cacti-templates-1.1.2.tar.gz

tar -xzvf mysql-cacti-templates-1.1.2.tar.gz

cd mysql-cacti-templates-1.1.2

cp ss_get_mysql_stats.php /xok.la/cacti/scripts

可以看到里面有多个监控项目,报告监控apache和nginx.我这只测试mysql,mysql相关的就2个文件:

模板文件:cacti_host_template_x_db_server_ht_0.8.6i.xml

插件:ss_get_mysql_stats.php

修改ss_get_mysql_stats.php 文件 第30行

$mysql_user = 'cacti';

$mysql_pass = 'cacti';

$cache_dir = "/xok.la/cacti/cache/";

设置准备监控的数据库的账户相关信息

mkdir /xok.la/cacti/cache/

chown -R vhost.vhost /xok.la/cacti/cache/

chmod 777 -R /xok.la/cacti/cache/

默认在获取的数据/tmp/下,会有cacti不能读取的情况。所以放在cacti目录来。

二,创建监控Mysql需要的账户以及权限

配置MySQL服务器,让cacti所在机器能够访问MySQL服务器的状态信息,必须拥有”process”权限。如果要监控InnoDB状态,还必须有”SUPER”权限。

mysql> grant process,super on *.* to 'cacti'@'%' identified by 'cacti';

mysql> grant all privileges on cacti.* to cacti@"%" identified by "cacti";

三,模板导入

在cacti管理界面(Import Templates)导入cacti_host_template_x_db_server_ht_0.8.6i.xml。

四,添加设备

创建Graph。在Console选项卡下的左侧菜单栏中选择Devices,为要监控的主机新建一个Devices或选择已有Devices。在Associated Graph Templates中添加想要监控MySQL状态的Graph Templates(如X MySQL Connections GT模板)。并点击最上面的Create Graphs for this Host链接,在Graph Templates的选择框中选择X MySQL Connections GT,然后点击Create按钮,出现以下WEB页。

监控的对象有:

X InnoDB Buffer Pool Activity GT

X InnoDB Buffer Pool GT

X InnoDB I/O GT

X InnoDB I/O Pending GT

X InnoDB Insert Buffer GT

X InnoDB Log GT

X InnoDB Row Operations GT

X InnoDB Semaphores GT

X InnoDB Transactions GT

X MyISAM Indexes GT

X MySQL Binary/Relay Logs GT

X MySQL Command Counters GT

X MySQL Connections GT

X MySQL Files and Tables GT

X MySQL Handlers GT

X MySQL Network Traffic GT

X MySQL Processlist GT

X MySQL Query Cache GT

X MySQL Query Cache Memory GT

X MySQL Replication GT

X MySQL Select Types GT

X MySQL Sorts GT

X MySQL Table Locks GT

X MySQL Temporary Objects GT

X MySQL Threads GT

X MySQL Transaction Handler GT

插件二(可用):

一,脚本下载

wget http://www.faemalia.net/mysqlUtils/teMySQLcacti-20060810.tar.gz

tar -xzvf teMySQLcacti-20060810.tar.gz

cd teMySQLcacti

cp mysql_stats.php /xok.la/cacti/scripts/

cp dumpMemcachedStats.php /xok.la/cacti/scripts/

二,模板导入

在cacti管理界面(Import Templates)导入cacti_host_template_temysql_host-step300-heartbeat600.xml 与cacti_host_template_memcached_host-step300-heartbeat600.xml模板文件。

三,创建监控Mysql需要的账户以及权限

配置MySQL服务器,让cacti所在机器能够访问MySQL服务器的状态信息,必须拥有”process”权限。如果要监控InnoDB状态,还必须有”SUPER”权限。

mysql> grant process,super on *.* to 'cacti'@'%' identified by 'cacti';

mysql> grant all privileges on cacti.* to cacti@"%" identified by "cacti";

四,添加设备

创建Graph。在Console选项卡下的左侧菜单栏中选择Devices,为要监控的主机新建一个Devices或选择已有Devices。在Associated Graph Templates中添加想要监控MySQL状态的Graph Templates(如teMySQL – Index Usage模板,此套模板是以teMySQL开头的一系列模板)。并点击最上面的Create Graphs for this Host链接,在Graph Templates的选择框中选择teMySQL - Locking and Slow,然后点击Create按钮,出现以下WEB页。

监控的对象有:

teMySQL - CPU Usage

teMySQL - Index Usage

teMySQL - InnoDB Buffers Pages/Mem

teMySQL - InnoDB File I/O

teMySQL - InnoDB InsBuffer

teMySQL - InnoDB Locks

teMySQL - InnoDB Row

teMySQL - Load Average

teMySQL - Locking and Slow

teMySQL - Network Usage

teMySQL - Old Command Stats

teMySQL - Old Handler Stats

teMySQL - Query Cache

teMySQL - Replication

teMySQL - Select Handler

teMySQL - Select Queries

teMySQL - Sorts

teMySQL - Temporary Objects

teMySQL - Threads/Abends

teMySQL - Volatile Handler

teMySQL - Volatile Queries

插件三(测试未成功):

来源:http://forums.cacti.net/about6108-0-asc-0.html

下载地址:

http:///xok.la/file/2009/05/mysql_stats.zip

http:///xok.la/file/2009/05/mysqli_stats.zip

方法同上。

我只用了2个模板:

cacti_graph_template_mysql_connections.xml

cacti_graph_template_mysql_thread_statistics.xml

function ss_get_mysql_stats( $options ) {

# Process connection options and connect to MySQL.

global $debug, $mysql_user, $mysql_pass, $heartbeat, $cache_dir, $poll_time,

$chk_options;

# Connect to MySQL.

$user = isset($options['user']) ? $options['user'] : $mysql_user;

$pass = isset($options['pass']) ? $options['pass'] : $mysql_pass;

$heartbeat = isset($options['heartbeat']) ? $options['heartbeat'] : $heartbeat;

$conn = @mysql_connect($options['host'], $user, $pass);

if ( !$conn ) {

$conn = @mysql_connect($options['host'].":3307", $user, $pass);

}

$sanitized_host

= str_replace(array(":", "/"), array("", "_"), $options['host']);

$cache_file = "$cache_dir/$sanitized_host-mysql_cacti_stats.txt";

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值