Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6861897
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类: 系统运维

2014-06-08 22:08:43

最近公司数据库新增加了几台mongodb数据库,为了能实时了解运行的状态,需要增加zabbix对mongodb的运行状态监控。
mongodb默认安装情况下可以运行echo "db.serverStatus()" | mongo 来获取mongodb的运行状态,但是公司数据库安装的时候修改了默认的连接端口,这样一来运行这个命令就报错了
[root@localhost ~]# echo "db.serverStatus()" | mongo
MongoDB shell version: 2.x.x
connecting to: test
Wed Jun  4 14:39:37 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91
exception: connect failed
默认的27017端口显示连接不上,这就需要我们在mongo后面加上服务器地址及端口号比如
[root@localhost ~]# echo "db.serverStatus()" | mongo 10.0.0.12:40000

点击(此处)折叠或打开

  1. MongoDB shell version: 2.x.x
  2.     connecting to: 10.0.0.12:40000/test
  3.     {
  4.             "host" : "localhost.localdomain:30000",
  5.             "version" : "2.x.x",
  6.             "process" : "mongos",
  7.             "uptime" : 1659778,
  8.             "localTime" : ISODate("2014-06-04T06:45:05.691Z"),
  9.             "mem" : {
  10.                     "resident" : 14,
  11.                     "virtual" : 280,
  12.                     "supported" : true
  13.             },
  14.             "connections" : {
  15.                     "current" : 107,
  16.                     "available" : 8085
  17.             },
  18.             "extra_info" : {
  19.                     "note" : "fields vary by platform",
  20.                     "heap_usage_bytes" : 902192,
  21.                     "page_faults" : 0
  22.             },
  23.             "opcounters" : {
  24.                     "insert" : 5228846,
  25.                     "query" : 833941,
  26.                     "update" : 15,
  27.                     "delete" : 13,
  28.                     "getmore" : 93,
  29.                     "command" : 35558
  30.             },
  31.             "ops" : {
  32.                     "sharded" : {
  33.                             "insert" : 0,
  34.                             "query" : 0,
  35.                             "update" : 0,
  36.                             "delete" : 0,
  37.                             "getmore" : 0,
  38.                             "command" : 0
  39.                     },
  40.                     "notSharded" : {
  41.                             "insert" : 5228846,
  42.                             "query" : 833941,
  43.                             "update" : 15,
  44.                             "delete" : 13,
  45.                             "getmore" : 93,
  46.                             "command" : 35558
  47.                     }
  48.             },
  49.             "shardCursorType" : {
  50.                     "ParallelSort" : 833942
  51.             },
  52.             "asserts" : {
  53.                     "regular" : 0,
  54.                     "warning" : 0,
  55.                     "msg" : 0,
  56.                     "user" : 0,
  57.                     "rollovers" : 0
  58.             },
  59.             "network" : {
  60.                     "bytesIn" : 2218644824,
  61.                     "bytesOut" : 540032120,
  62.                     "numRequests" : 6101134
  63.             },
  64.             "ok" : 1
  65.     }
  66.     bye

因此可以考虑使用zabbix的UserParameter自定义监控,对MongoDB进行监控

添加MongoDB监控

1、zabbix客户端配置文件zabbix_agentd.conf文件,添加如下内容:

UserParameter=MongoDB.Status[*],/bin/echo "db.serverStatus().$1" | /usr/local/sbin/mongo  10.0.0.12:40000 | grep "$2"|awk -F: '{print $$2}'|awk -F, '{print $$1}'

2、重新启动zabbix客户端

/etc/init.d/zabbix_agentd restart

3添加MongoDB监控模板
导入模板
选择configuration-template 右上角import,导入模板“zbx_mongodb-monitor_templates.xml”,稍后会放在文章的最下面附件中供大家下载

点击导入import选择模板的存放位置,点击下面的导入

导入成功后可以到configuration-templete里查看新导入的模板MongoDB Moniting

4.模板关联mongodb主机
在装有MongoDB的服务器上应用该模板:

configuration->host,选择一台装有MongoDB的服务器,在右边的“Linked templates”,添加MongoDB监控模板,然后保存


导入成功以后可以在monitoring-lastdata里查看最新数据。稍等几分钟在monitoring的graph里可以看到关联主机的出图

具体出图图例如下






好了,今天先到这。文中如有失误之处,还请大家多多批评指正。
如需转载请标明出处:http://blog.chinaunix.net/uid-29179844-id-4287403.html  谢谢。
阅读(1301) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

nescafer2016-09-11 20:25:19

同问

wshxgxiaoli2015-04-03 14:35:22

说好的模板呢