MongoDB我们如何获取所有CURRENT打开的游标以及它们正在运行的查询? [英] MongoDB How do we get all CURRENT open cursors and the queries they are running?

查看:58
本文介绍了MongoDB我们如何获取所有CURRENT打开的游标以及它们正在运行的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些用户打开了没有设置noTimeout的mongo游标.我想列出所有打开的游标,它们的ID,它们的选项,它们在其下运行的查询,该游标的开始时间,上次使用它的时间(获取更多信息).有什么命令可以做到这一点吗?有人可以指出我的任何提示,以便在需要时我可以编写一个小应用程序.

Some users open cursors to mongo with noTimeout set. I want to list all the open cursors, their IDs, their options, the query they are running under, the start time for that cursor, the lasttime it was used(getmore). Is there any command to do that? Can someone point me to any hints so that I can write a small app if needed.

推荐答案

MongoDB有一个命令"currentOp",其中包含当前操作(通常,不仅打开游标).结果是"inprog"值的数组.您具有操作的线程ID,而不是游标ID,但是对于研究繁重的操作或已运行很长时间的操作非常有用. 这并不是您想要的,但是我认为您可以编写一个小程序来分析操作的运行时间,以识别在某个时间段内正在运行的程序.

MongoDB has a command 'currentOp' which contains current operations (in general, not only open cursors). The result is an array of "inprog" values. You have the thread id of the operation, not a cursor id but it's very useful to investigate heavy operations or those ones that've been running for a long time. It's not perfectly what you want but I think you could write a small program that parse time running of operations to identify which one have been running for a certain period of time.

看看我只是为了测试目的而运行的聚合数据库的示例,我将隐藏一些数据,因为在我们的案例中这非常明智:)

Look at an example of my database of an aggregation I run just for testing purposes, I will hide some data because it's very sensible in our case :)

"inprog" : [
    {
        "opid" : 74074645,
        "active" : true,
        "secs_running" : 2,
        "op" : "query",
        "ns" : "mydb.Terms.ByHour",
        "query" : {
            "aggregate" : "Terms.ByHour",
            "pipeline" : [
                {
                    "$match" : {
                        "cluster" : "my_key",
                        "start" : {
                            "$gte" : ISODate("2013-11-10T00:00:00Z"),
                            "$lte" : ISODate("2013-11-11T00:00:00Z")
                        }
                    }
                },
                {
                    "$group" : {
                        "_id" : "$start",
                        "count" : {
                            "$sum" : "$count"
                        }
                    }
                },
                {
                    "$sort" : {
                        "_id" : 1
                    }
                }
            ]

只需将结果放入变量中即可

Just put the result in a variable:

currentOps = db.currentOp()

并将其用作常规json,或编写一个迭代currentOps.inprog数组并检查secs_running>内容的小程序

and use it as a regular json, or write a small program that iterate currentOps.inprog array and check for secs_running > something

希望对您有帮助.

这篇关于MongoDB我们如何获取所有CURRENT打开的游标以及它们正在运行的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆