Cacti监控MYSQL

---cactimysql插件的安装

关于cacti 的安装配置,见之前的博文,本文接上篇cacti 短信报警http://chengchow.blog.51cto.com/1642666/1213367

1.下载插件到/downloads目录

插件见附件

2.解压缩

Cd /downloads

Tar xvf mysql-cacti-templates-1.1.2.tar

3.拷贝mysql插件到scripts目录

Cd /var/www/localhost/htdocs/cacti/

Cp /downloads/mysql-cacti-templates-1.1.2/ss_get_mysql_stats.phpscripts/.

4.修改ss_get_mysql_stats.php

Vi ss_get_mysql_stats.php

$mysql_user = 'cactiuser';

$mysql_pass = 'cactipass';

……

$cache_dir= '/var/www/localhost/htdocs/cacti/cache';

 

5.创建cach_dir目录,并赋予最大权限

Mkdir cache

Chmod 777 –R cache

Chown –R cactiuser:cactiuser cache

6.赋予cactiuser对数据库的数据采集权限

mysql -uroot -proot

Welcome to the MySQL monitor.Commands end with ; or \g.

Your MySQL connection id is 129

Server version: 5.1.62-log Gentoo Linux mysql-5.1.62-r1

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> grant process, super, replication client on *.* to 'cactiuser'@'localhost' identified by 'cactipass';

Query OK, 0 rows affected (0.00 sec)

mysql> grant process, super, replication client on *.* to 'cactiuser'@'%' identified by 'cactipass';

Query OK, 0 rows affected (0.00 sec)

mysql> \q

 

测试:

Mysql –ucactiuser –pcactipass –h localhost

PhpMyadmin下看权限

cacti关于MYSQL的监控

7.打开IE访问Cacti 网址

http://localhost/cacti

8.导入mysql监控模板

Consoleàimport templatesà浏览选择刚才解压文件中的

cacti_host_template_x_db_server_ht_0.8.6i.xml,点击import导入

cacti关于MYSQL的监控

Consoleàgraph templates,我们会看到如下图选项,导入成功。

cacti关于MYSQL的监控

9.添加一台有Mysql 服务的主机测试,主机需要安装net-snmp服务,添加方法

Console à devices àadd 出现如下界面,添加方法和普通主机一样,唯一的区别是Host Template中选择X DB Server HT(不选也行以后再添加,MYSQL监控表格比较多,以后添加比较麻烦),

cacti关于MYSQL的监控

然后将这台刚才添加的主机添加到graph tree里面,这样我们就可以去看监控图片了

时间比较短,只能贴张1小时的图片

cacti关于MYSQL的监控

10.遇到问题

10.1 日志报错

08/19/2013 11:55:05 PM - CMDPHP: Poller[0] ERROR: A DB Exec Failed!, Error:'1062', SQL:"insert into poller_output (local_data_id, rrd_name, time, output) values (7, 'proc', '2013-08-19 23:55:04', '88')' 

08/19/2013 11:55:04 PM - CMDPHP: Poller[0] ERROR: A DB Exec Failed!, Error:'1062', SQL:"insert into poller_output (local_data_id, rrd_name, time, output) values (6, 'users', '2013-08-19 23:55:04', '1')'

解决方法:

chmod 755 –R log rra

chown cactiuser:cactiuser –R log rra

不过做完以后日志的purge权限没了

10.2日志一堆警告

08/19/2013 11:45:04 PM - CMDPHP: Poller[0] Host[34] Description[MySQLtest01] DS[376] Graphs['MySQLtest01 - InnoDB Buffer Pool Activity'] WARNING: Result from CMD not valid. Partial Result: Can't connect to MyS 

08/19/2013 11:45:04 PM - CMDPHP: Poller[0] Host[34] Description[MySQLtest01] DS[381] Graphs['MySQLtest01 - MySQL Sorts'] WARNING: Result from CMD not valid. Partial Result: Can't connect to MyS

其实日志已经说得很明白了,不能连接到MYSQL服务器,可惜我还是找了大半天,原来我的/include/config.inc默认密码是cactiuser,而这里设置的是cactipass,修改一样就可以了