MongoDB 3.6 open slow query

Original link: http://www.cnblogs.com/ExMan/p/10907795.html


Reference:
Profiling Levels: Support what level.
0 default profiler level, profiler off and does not collect data.
1 profiler data collection operations of more than slowms.
2 profiler to collect all the data.

Collecting data set: a set level, slow query criteria for 200ms.
RS0: a PRIMARY> db.setProfilingLevel (1,200)
{
"WAS": 1,
"slowms": 200 is,
"the sampleRate": 1,
"OK": 1,
"operationTime": Timestamp (1536309385,. 1),
"$ clusterTime": {
"clusterTime": Timestamp (1536309385,. 1),
"Signature": {
"the hash": binData (0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA ="),
"keyId" : NumberLong (0)
}
}
}

set the statement:
db.setProfilingLevel (. 1, {slowms:


- Level Query:
RS0: a PRIMARY> db.getProfilingLevel ()
. 1
- OFF the Profiling:
db.setProfilingLevel (0)

- Set slow query sampling ratio:
RS0: a PRIMARY> db.setProfilingLevel (. 1, the sampleRate {:} 0.42 )
{
"WAS":. 1,
"slowms": 200 is,
"the sampleRate":. 1,
"OK":. 1,
"operationTime": Timestamp (1536309735,. 1),
"$ clusterTime": {
"clusterTime": Timestamp (1,536,309,735 ,. 1),
"Signature": {
"the hash": binData (0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA ="),
"keyId": NumberLong (0)
}
}
}
RS0: a PRIMARY>
RS0: a PRIMARY> DB.getProfilingStatus()
{
"was" : 1,
"slowms" : 200,
"sampleRate" : 0.42,
"operationTime": Timestamp (1536309775,. 1),
"$ clusterTime": {
"clusterTime": Timestamp (1536309775,. 1),
"Signature": {
"the hash": binData (0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA ="),
"keyId" : NumberLong (0)
}
}
}


Note:
By default, the sampleRate IS SET to 1.0, meaning All SLOW Operations are that profiled.
the When the sampleRate IS SET BETWEEN 0 and. 1, Databases with Profiling Level. 1 Will
only Profile A RANDOMLY sampled PERCENTAGE of SLOW Operations according to sampleRate.

default sampleRate parameter is 1.0, i.e., slow to collect all queries, the range of values of this parameter is 0 to 1. when the level is set to be a randomly selected set of percentages according to the value sampleRate slow operation.

In addition to setting the outer query is run slowly, may be provided in a startup command mode:
the mongod --profile --slowms. 1 0 15 --slowOpSampleRate.

=. 1 Profile
slowms = 200 is
slowOpSampleRate = 0.5

system.profile Collection of the Profiler data stored in MongoDB.
The size of the main database system.profile modified set of:
the following steps:
the Disable Profiling.
The Drop The system.profile Collection.
The Create new new system.profile A Collection.
Re-enable Profiling.

- Review of 4M:
db.setProfilingLevel (0)
db.system.profile.drop ()
db.createCollection ( "system.profile", {the capped: to true, size: 4000000})
db.setProfilingLevel (. 1)

- slow query query operation:

- slow query visualization :
mongoDB slow query operations can be monitored in conjunction with PMM PMM-QAN, but supports MongoDB 3.2 and above.
Two steps are required:
1. Set the required account
2. Turn profiler.
In MongoDB account and set permissions:
db.getSiblingDB ( "ADMIN") createUser ({.
user: "mongodb_exporter",
pwd: "mongodb_exporter",
roles: [
{ role: "clusterMonitor", db: "admin" },
{ role: "read", db: "local" }
]
})

开启profiler:
$ mongod --dbpath=DATABASEDIR --profile 2 --slowms 200 --rateLimit 100
或者写入配置文件:
operationProfiling:
slowOpThresholdMs: 200
mode: slowOp
rateLimit: 100

https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler/
https://www.percona.com/doc/percona-monitoring-and-management/conf-mongodb.html 

Reproduced in: https: //www.cnblogs.com/ExMan/p/10907795.html

Guess you like

Origin blog.csdn.net/weixin_30747253/article/details/95011890