设为首页 加入收藏

TOP

[Cacti]cacti监控mongodb性能实战(一)
2015-07-24 11:35:38 来源: 作者: 【 】 浏览:9
Tags:Cacti cacti 监控 mongodb 性能 实战
前言:

为了更好的使用mongodb,需要监控出mongodb的一些基础使用情况,比如Flush数、连接数、内存使用率、Index操作,Slave延迟等等,这些可以通过配置cacti监控mongodb的模板来完成。

1,在cacti界面导入模板

在计算机本地,下载此tgz包:http://mysql-cacti-templates.googlecode.com/files/better-cacti-templates-1.1.8.tar.gz

解压到任意目录,然后打开cacti的web界面,选择"Import/Export" — "Improt Templates",点击"选择文件",将cacti_host_template_x_mongodb_server_ht_0.8.6i-sver1.1.8.xml,导入到cacti里,这样,cacti的图形模板里就可以选择使用mongodb的图形项目了。

2,在cacti服务器端配置监控脚本

[root@squid-2 soft]# wget http://mysql-cacti-templates.googlecode.com/files/better-cacti-templates-1.1.8.tar.gz

[root@squid-2 soft]# tar zxvf better-cacti-templates-1.1.8.tar.gz

[root@squid-2 soft]# cd better-cacti-templates-1.1.8

[root@squid-2 better-cacti-templates-1.1.8]# cp scripts/ss_get_by_ssh.php /var/www/html/cacti/scripts/ss_get_by_ssh.php

[root@squid-2 better-cacti-templates-1.1.8]# chown –R apache /var/www/html/cacti/scripts/ss_get_by_ssh.php

修改监控脚本ss_get_by_ssh.php

[root@squid-2 better-cacti-templates-1.1.8]# vim /var/www/html/cacti/scripts/ss_get_by_ssh.php

$ssh_user = 'root'; # SSH username

$ssh_port = 22; # SSH port

$ssh_iden = '-i /var/www/html/cacti/id_rsa'; # SSH identity

这里mongodb由于使用了30000端口不是默认端口27018,所以还需要修改端口配置

function mongodb_cmdline ( $options ) {

return “echo \”db._adminCommand({serverStatus:1, repl:2})\” | /usr/local/mongo/mongodb/bin/mongo --port 30000″;

}

之后,重启cacti服务

[root@squid-2 templates]# service httpd restart

停止 httpd: [确定]

正在启动 httpd: [确定]

[root@squid-2 templates]#

3,使用SSH的方式登录监控

(1):创建SSH远曾登录账号

使用ssh-keygen命令生成秘钥,回车后输入key的路径/var/www/html/cacti/id_rsa,然后2个回车,密码为空,如下:

[root@ squid-2 soft]# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): /var/www/html/cacti/id_rsa

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /var/www/html/cacti/id_rsa.

Your public key has been saved in /var/www/html/cacti/id_rsa.pub.

The key fingerprint is:

73:8e:77:45:a0:54:ef:c8:a4:2d:62:50:8d:da:d8:e4 root@name01

The key's randomart image is:

+--[ RSA 2048]----+

| .o..o |

| .o... o |

| .B . . o |

| o.E = + |

| S + + o |

| . * . . |

| . o . |

| . . |

| |

+-----------------+

把key文件权限改成cacti的使用用户可以访问的权限:

[root@ squid-2 soft]# chown -R cacti_user /var/www/html/cacti/id_rsa*

[root@ squid-2 soft]#

将key加入到远程mongodb服务器上,也可在远程服务器建立一个cacti_user用户,将key加上到cactiuser目录下

[root@ squid-2 soft]# ssh-copy-id -i /var/www/html/cacti/id_rsa root@10.254.3.62

(2):配置各种参数

修改ss_get_by_ssh.php,设置好私钥文件路径:

$ssh_user = 'root'; # SSH username

$ssh_port = 22; # SSH port

$ssh_iden = '-i /var/www/html/cacti/id_rsa'; # SSH identity

如果mongodb不使用默认端口,需要修改下面一段,把端口加上即可:

function mongodb_cmdline ( $options ) {

return “echo \”db._adminCommand({serverStatus:1, repl:2})\” | /usr/local/mongo/mongodb/bin/mongo --port 30000″;

}

(3)检测监控脚本

[root@squid-2 templates]# php /var/www/html/cacti/scripts/ss_get_by_ssh.php --type mongodb --host 10.254.3.62 --items dc,de,df,dg,dh,di,dj,dk,dl,dm,dn,do,dp,dq,dr,ds,dt,du

dc:57 de:0 df:401604608 dg:-1 dh:-1 di:-1 dj:-1 dk:-1 dl:-1 dm:-1 dn:-1 do:46268320 dp:5245 dq:0 dr:6 ds:52 dt:46697435 du:-1[root@squid-2 templates]#

[root@squid-2 templates]#

看到有数据了,检测OK。

4,使用Mongodb远程连接的方式来监控

4.1. 修改mongodb_cmdline函数,通过授权帐号密码、指定端口进行登录。

fu

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ORACLE创建表空间、用户、授权 下一篇关于RelayLog无法自动删除的问题..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)
·索引堆及其优化 - 菜 (2025-12-24 20:18:50)
·Shell 中各种括号的 (2025-12-24 19:50:39)
·Shell 变量 - 菜鸟教 (2025-12-24 19:50:37)