MongoDB性能监控(3)—数据库命令


  • 註冊用戶

    1、概述

    • 前面两个帖子有介绍MongoDB的监控命令mongostat和mongotop命令,接下来将会介绍三个MongoDB内部状态的数据库命令,它们是所有MongoDB监控应用程序的基础。

    2、serverStatus

    • serverStatus命令的输出内容非常的丰富,统计的所有信息中包含页错误、B树访问率、打开连接数,以及总的插入、更新、查询和删除等信息内容。
    • 执行命令如下(由于内容过多,只选取部分内容):
    MongoDB Enterprise testrs:PRIMARY> use admin
    switched to db admin
    MongoDB Enterprise testrs:PRIMARY> db.runCommand({serverStatus: 1})
    {
            "host" : "ggtest1:27018",
            "advisoryHostFQDNs" : [ ],
            "version" : "3.2.8",
            "process" : "mongod",
            "pid" : NumberLong(20984),
            "uptime" : 1303366,
            "uptimeMillis" : NumberLong(1303365659),
            "uptimeEstimate" : 1250796,
            "localTime" : ISODate("2016-11-03T07:48:29.207Z"),
            "asserts" : {
                    "regular" : 0,
                    "warning" : 0,
                    "msg" : 0,
                    "user" : 3,
                    "rollovers" : 0
            },
            "connections" : {
                    "current" : 9,
                    "available" : 810,
                    "totalCreated" : NumberLong(4509)
            },
            "extra_info" : {
                    "note" : "fields vary by platform",
                    "heap_usage_bytes" : 337442568,
                    "page_faults" : 16
            },
            "globalLock" : {
                    "totalTime" : NumberLong("1303365668000"),
                    "currentQueue" : {
                            "total" : 0,
                            "readers" : 0,
                            "writers" : 0
                    },
                    "activeClients" : {
                            "total" : 24,
                            "readers" : 0,
                            "writers" : 0
                    }
            },
            "locks" : {
                    "Global" : {
                            "acquireCount" : {
                                    "r" : NumberLong(21674384),
                                    "w" : NumberLong(666709),
                                    "R" : NumberLong(5),
                                    "W" : NumberLong(7)
                            }
                    },
                    "Database" : {
    
    • 其中,globalLock:部分很重要,因它揭示了服务器花在写锁上的总时间。

    • currentQueue:的统计信息中,如果有大量的读或写等在队列中,那么就意味着需要进行某种优化了。

    • mem:部分显示了mongod进程是如何使用内存的。bits字段说明这是一台64位或是32位的机器;resident是MongoDB所占用的物理内存数量;virtual是进程所映射的虚拟内存的兆字节数;mapped是virtual的子集,标明那些内存里有多少是只用来映射文件的。

    • 每个版本的MongoDB里,serverStatus的输出结果都会有所变化并得以改进。

    3、top

    • top命令会显示每个数据库的操作计数器。如果应用程序使用了多个物理数据库,或者想看看操作的平均耗时,那么这是一个很有用的命令。

    • 下面是一些输出内容:

    MongoDB Enterprise testrs:PRIMARY> db.runCommand({top: 1})
    {
            "totals" : {
                    "note" : "all times in microseconds",
                    "admin.person3" : {
                            "total" : {
                                    "time" : 44166108,
                                    "count" : 284542
                            },
                            "readLock" : {
                                    "time" : 3279,
                                    "count" : 339
                            },
                            "writeLock" : {
                                    "time" : 44162829,
                                    "count" : 284203
                            },
                            "queries" : {
                                    "time" : 123,
                                    "count" : 1
                            },
                            "getmore" : {
                                    "time" : 0,
                                    "count" : 0
                            },
                            "insert" : {
                                    "time" : 44162829,
                                    "count" : 284203
                            },
                            "update" : {
                                    "time" : 0,
                                    "count" : 0
                            },
                            "remove" : {
                                    "time" : 0,
                                    "count" : 0
                            },
                            "commands" : {
                                    "time" : 0,
                                    "count" : 0
                            }
                    },
                    "admin.person4" : {
                            "total" : {
                                    "time" : 13055754,
                                    "count" : 49141
                            },
                            "readLock" : {
                                    "time" : 30908,
                                    "count" : 254
                            },
                            "writeLock" : {
                                    "time" : 13024846,
    
    • 此处可以发现写锁花费的时间很多,这样就可以查看是否需要对写操作进行优化了。

    4、db.currentOp()

    • db.currentOp()命令可以查看MongoDB当前正在运行的所有操作,以及正在等待运行的操作信息。

    • 下面是该命令的输出内容:

    MongoDB Enterprise testrs:PRIMARY> db.currentOp()
    {
            "inprog" : [
                    {
                            "desc" : "conn4499",
                            "threadId" : "1638234432",
                            "connectionId" : 4499,
                            "client" : "10.130.170.12:54230",
                            "active" : true,
                            "opid" : 5677478,
                            "secs_running" : 1,
                            "microsecs_running" : NumberLong(1937503),
                            "op" : "getmore",
                            "ns" : "local.oplog.rs",
                            "query" : {
                                    "getMore" : NumberLong("15148536861"),
                                    "collection" : "oplog.rs",
                                    "maxTimeMS" : NumberLong(5000),
                                    "term" : NumberLong(111),
                                    "lastKnownCommittedOpTime" : {
                                            "ts" : Timestamp(1478159326, 293),
                                            "t" : NumberLong(111)
                                    }
                            },
                            "numYields" : 0,
                            "locks" : {
    
                            },
                            "waitingForLock" : false,
                            "lockStats" : {
                                    "Global" : {
                                            "acquireCount" : {
                                                    "r" : NumberLong(2)
                                            }
                                    },
                                    "Database" : {
                                            "acquireCount" : {
                                                    "r" : NumberLong(1)
                                            }
                                    },
                                    "oplog" : {
                                            "acquireCount" : {
                                                    "r" : NumberLong(1)
                                            }
                                    }
                            }
                    },
                    {
                            "desc" : "rsSync",
                            "threadId" : "1289922880",
                            "active" : true,
                            "opid" : 8,
                            "secs_running" : 1304727,
                            "microsecs_running" : NumberLong("1304727618937"),
                            "op" : "none",
                            "ns" : "local.replset.minvalid",
                            "query" : {
    
                            },
                            "numYields" : 0,
                            "locks" : {
    
                            },
                            "waitingForLock" : false,
                            "lockStats" : {
                                    "Global" : {
                                            "acquireCount" : {
                                                    "r" : NumberLong(26),
                                                    "w" : NumberLong(4),
                                                    "R" : NumberLong(5),
                                                    "W" : NumberLong(2)
                                            }
                                    },
                                    "Database" : {
                                            "acquireCount" : {
                                                    "r" : NumberLong(8),
                                                    "w" : NumberLong(1),
                                                    "W" : NumberLong(3)
                                            }
                                    },
                                    "Collection" : {
                                            "acquireCount" : {
                                                    "r" : NumberLong(7)
                                            }
                                    },
                                    "Metadata" : {
                                            "acquireCount" : {
                                                    "w" : NumberLong(1)
                                            }
                                    },
                                    "oplog" : {
                                            "acquireCount" : {
                                                    "r" : NumberLong(1),
                                                    "w" : NumberLong(1)
                                            }
                                    }
                            }
                    },
                    {
                            "desc" : "WT RecordStoreThread: local.oplog.rs",
                            "threadId" : "1164032320",
                            "active" : true,
                            "opid" : 24,
                            "secs_running" : 1304726,
                            "microsecs_running" : NumberLong("1304726793327"),
                            "op" : "none",
                            "ns" : "local.oplog.rs",
                            "query" : {
    
                            },
                            "numYields" : 0,
                            "locks" : {
    
                            },
                            "waitingForLock" : false,
                            "lockStats" : {
                                    "Global" : {
                                            "acquireCount" : {
                                                    "r" : NumberLong(1),
                                                    "w" : NumberLong(1)
                                            }
                                    },
                                    "Database" : {
                                            "acquireCount" : {
                                                    "w" : NumberLong(1)
                                            }
                                    },
                                    "oplog" : {
                                            "acquireCount" : {
                                                    "w" : NumberLong(1)
                                            }
                                    }
                            }
                    },
                    {
                            "desc" : "SyncSourceFeedback",
                            "threadId" : "1306708288",
                            "active" : true,
                            "opid" : 927,
                            "op" : "none",
                            "ns" : "",
                            "query" : {
    
                            },
                            "numYields" : 0,
                            "locks" : {
    
                            },
                            "waitingForLock" : false,
                            "lockStats" : {
    
                            }
                    },
                    {
                            "desc" : "conn4508",
                            "threadId" : "1085319488",
                            "connectionId" : 4508,
                            "client" : "10.130.170.11:27023",
                            "active" : true,
                            "opid" : 5677485,
                            "secs_running" : 0,
                            "microsecs_running" : NumberLong(76),
                            "op" : "command",
                            "ns" : "admin.$cmd",
                            "query" : {
                                    "currentOp" : 1
                            },
                            "numYields" : 0,
                            "locks" : {
    
                            },
                            "waitingForLock" : false,
                            "lockStats" : {
    
                            }
                    },
                    {
                            "desc" : "ReplBatcher",
                            "threadId" : "1608845632",
                            "active" : true,
                            "opid" : 9,
                            "op" : "none",
                            "ns" : "",
                            "query" : {
    
                            },
                            "numYields" : 0,
                            "locks" : {
    
                            },
                            "waitingForLock" : false,
                            "lockStats" : {
    
                            }
                    }
            ],
            "ok" : 1
    }
    MongoDB Enterprise testrs:PRIMARY>
    

登录后回复
 

与 萌阔论坛 的连接断开,我们正在尝试重连,请耐心等待