mongodb_profier



一、获取、设置profile(profile用collection存储数据)
db.setProfilingLevel(level)  默认为100毫秒  
db.setProfilingLevel(level,slowms) 设置级别和默认毫秒数
db.setProfilingLevel(0)  关闭
db.system.profile.drop()  删除(删除前需要先关闭)
db.createCollection( "system.profile", { capped: true, size:4000000 } )  重新创建一个
Level
Setting
-1
No change. Returns the current profile level(获取已有的跟踪信息)
0
Off. No profiling.(不跟踪)
1
On. Only includes slow operations.(包含限定了时间的慢操作)
2
On. Includes all operations  (包含所有操作)

二、查看profile数据
db.system.profile.find() //查看所有


三、profile数据示例
{
    "op" : "insert",
    "ns" : "test.orders",
    "query" : {
       "_id" : 1,
       "cust_id" : "A123",
       "amount" : 500,
       "status" : "A"
    },
    "ninserted" : 1,
    "keyUpdates" : 0,
    "writeConflicts" : 0,
    "numYield" : 0,
    "locks" : {
          "Global" : {
             "acquireCount" : {
                "w" : NumberLong(1)
             }
          },
          "MMAPV1Journal" : {
             "acquireCount" : {
                "w" : NumberLong(2)
             }
          },
          "Database" : {
             "acquireCount" : {
                "w" : NumberLong(1)
             }
          },
          "Collection" : {
             "acquireCount" : {
                "W" : NumberLong(1)
             }
          }
       },
    ,
    "millis" : 0,
    "execStats" : {
    },
    "ts" : ISODate("2012-12-10T19:31:28.977Z"),
    "client" : "127.0.0.1",
    "allUsers" : [ ],
    "user" : ""
}


四、profile说明
1、system.profile.op
  • insert
  • query
  • update
  • remove
  • getmore
  • command
2、system.profile.ns
   命名空间:数据库名.collection名
3、system.profile.query
   查询条件
4、system.profile.command
   op为command时使用
5、system.profile.updateobj
   op为update时使用
6、system.profile.ntoreturn
   期望返回数量,query语句期望返回的数量,如limit(40)
7、system.profile.nreturned
   实际返回的数量
8、system.profile.ntoskip
   skip()方法跳过的记录数
9、system.profile.nscanned
   扫描次数,当扫描次数大于返回的数量(ntoreturn),考虑使用索引
   
nscanned和nscannedObjects区别:
   1、
nscanned:根据索引扫描文档,扫描的可能返回实际返回的数量
   2、nscannedObjects:扫描完整的文档,扫描实际返回的数据
    
http://stackoverflow.com/questions/13910097/explain-in-mongodb-differences-between-nscanned-and-nscannedobjects
10、system.profile.moved
   表示update操作移动的数据数量
11、system.profile.scanAndOrder
    布尔值,当为true时,表明排序未使用到索引,只有true时该字段才显示
12、system.profile.ndeleted
    删除操作影响的数据数量
13、system.profile.ninserted
    写入操作写入的数据数量
14、system.profile.nModified
    修改操作影响的数据数量
15、system.profile.responseLength
    返回的数据长度,单位为字节
16、system.profile.millis
    操作执行时间
17、system.profile.execStats
    统计信息,一般op为query有
18、system.profile.ts
    操作执行时间
19、system.profile.client
         客户端主机名或ip
20、system.profile.locks.acquireCount
        特定模式下获取锁的操作次数
14、system.profile.locks

The possible lock types are:

  • Global represents global lock.
  • MMAPV1Journal represents MMAPv1 storage engine specific lock to synchronize journal writes; for non-MMAPv1 storage engines, the mode for MMAPV1Journal is empty.
  • Database represents database lock.
  • Collection represents collection lock.
  • Metadata represents metadata lock.
  • oplog represents lock on the oplog.

The possible locking modes for the lock types are as follows:

  • R represents Shared (S) lock.
  • W represents Exclusive (X) lock.
  • r represents Intent Shared (IS) lock.
  • w represents Intent Exclusive (IX) lock.

    "locks" : {
        "Global" : {
          "acquireCount" : {
            "w" : NumberLong(1)
          }
        },
        "MMAPV1Journal" : {
          "acquireCount" : {
            "w" : NumberLong(1)
          }
        },
        "Database" : {
          "acquireCount" : {
            "W" : NumberLong(1)
          }
        }
      },

     




原文地址:https://www.cnblogs.com/gossip/p/4476531.html