MongoDB学习札记 第五篇 监控

对数据库的监控对于数据库管理人员(包括开发人员排查问题也是)来说是一项很重要的工作。

Mongodb提供了三种监控策略:

  • mongodb提供的工具集合,实时监听数据库的活动。
  • database commands 返回当前数据库的状态
  • MongoDB Management Service(MMS) 提供可视化的监控结果。

MongoDB Utilities

mongostat

mongostat显示每秒钟插入,查询,更新,删除,连接数 的统计信息。

root@ubuntu:~# mongostat
insert query update delete getmore command flushes mapped  vsize   res faults qr|qw ar|aw netIn netOut conn     time
    *0    *0     *0     *0       0     1|0       0 160.0M 527.0M 69.0M      0   0|0   0|0   79b    10k    2 17:37:15
    *0    *0     *0     *0       0     1|0       0 160.0M 527.0M 69.0M      0   0|0   0|0   79b    10k    2 17:37:16
    *0    *0     *0     *0       0     1|0       0 160.0M 527.0M 69.0M      0   0|0   0|0   79b    10k    2 17:37:17
    *0    *0     *0     *0       0     1|0       0 160.0M 527.0M 69.0M      0   0|0   0|0   79b    10k    2 17:37:18
    *0    *0     *0     *0       0     2|0       1 160.0M 527.0M 69.0M      0   0|0   0|0  133b    10k    2 17:37:19
    *0    *0     *0     *0       0     1|0       0 160.0M 527.0M 69.0M      0   0|0   0|0   79b    10k    2 17:37:20
    *0    *0     *0     *0       0     1|0       0 160.0M 527.0M 69.0M      0   0|0   0|0   79b    10k    2 17:37:21
^Croot@ubuntu:~#

mongotop
mongotop 统计当前活动的mongodb实例的集合读写时长,可以用来验证是否我们的mongodb实例还活着或者验证操作时长是否达到我们的要求。

root@ubuntu:~# mongotop
2015-06-07T17:48:58.772-0700    connected to: 127.0.0.1
                     ns    total    read    write    2015-06-07T17:52:03-07:00
             test.pages     65ms    65ms      0ms
     admin.system.roles      0ms     0ms      0ms
   admin.system.version      0ms     0ms      0ms
      local.startup_log      0ms     0ms      0ms
   local.system.indexes      0ms     0ms      0ms
local.system.namespaces      0ms     0ms      0ms
   local.system.replset      0ms     0ms      0ms
    test.system.indexes      0ms     0ms      0ms
 test.system.namespaces      0ms     0ms      0ms
              test.user      0ms     0ms      0ms

Http控制台

我用的mongodb是3.0.3版本,默认没有开启28017端口,所以你访问 http://yourhost:28017 是访问不了的, 如果要访问28017端口的应用, 需要在启动monogd的时候加入 –rest 参数
./mongod --dbpath ../data/db/ --rest

MongoDB Command

db.serverStatus()

返回的结果是数据库的状态信息,包含磁盘,内存的使用情况,连接数,索引访问情况等。 db.serverStatus()返回结果非常快速,并不会影响到mongoDB的性能。

> db.serverStatus()
{
        "host" : "ubuntu",
        "version" : "3.0.3",
        "process" : "mongod",
        "pid" : NumberLong(2354),
        "uptime" : 13191,

        ... ...

        "ok" : 1
}

db.stats()

返回当前数据库的存储的内存大小,集合数量,索引占用内存大小等情况。

> db.stats()
{
        "db" : "test",
        "collections" : 4,
        "objects" : 42,
        "avgObjSize" : 67.80952380952381,
        "dataSize" : 2848,
        "storageSize" : 28672,
        "numExtents" : 4,
        "indexes" : 2,
        "indexSize" : 16352,

        ... ...

        "ok" : 1
}

db.collection.stats()

相对于db.stats(),db.collection.stats()返回的是集合的统计信息。

> db.pages.stats()
{
        "ns" : "test.pages",
        "count" : 30,
        "size" : 1440,
        "avgObjSize" : 48,
        "numExtents" : 1,
        "storageSize" : 8192,
        "lastExtentSize" : 8192,
        "paddingFactor" : 1,

        ... ...

        "ok" : 1
}
>

其他工具

来源官网manual手册

Third Party Tools
A number of third party monitoring tools have support for MongoDB, either directly, or through their own plugins.

Self Hosted Monitoring Tools
These are monitoring tools that you must install, configure and maintain on your own servers. Most are open source.

<<< 捐赠 >>>

转载请注明出处! 原文地址: http://webinglin.github.io

References

http://docs.mongodb.org/manual/administration/monitoring/

留言

2015-06-07