MongoDB 3.6 开启慢查询
参考:
Profiling Levels:支持一下级别。
0 默认的profiler level,profiler 关闭并且不收集数据。
1 profiler 收集超过slowms的操作数据。
2 profiler 收集所有的数据。
设置收集数据:设置级别为1,慢查询标准为200ms.
rs0:PRIMARY> db.setProfilingLevel(1,200)
{
"was" : 1,
"slowms" : 200,
"sampleRate" : 1,
"ok" : 1,
"operationTime" : Timestamp(1536309385, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1536309385, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
设置语句:
db.setProfilingLevel(1, { slowms: 200 })
查询验证配置:
rs0:PRIMARY> db.getProfilingStatus()
--查询级别:
rs0:PRIMARY> db.getProfilingLevel()
1
--关闭设置Profiling:
db.setProfilingLevel(0)
--设置慢查询抽样比例:
rs0:PRIMARY> db.setProfilingLevel(1, { sampleRate: 0.42 })
{
"was" : 1,
"slowms" : 200,
"sampleRate" : 1,
"ok" : 1,
"operationTime" : Timestamp(1536309735, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1536309735, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
rs0:PRIMARY>
rs0:PRIMARY> db.getProfilingStatus()
{
"was" : 1,
"slowms" : 200,
"sampleRate" : 0.42,
"operationTime" : Timestamp(1536309775, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1536309775, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
注释:
By default, sampleRate is set to 1.0, meaning all slow operations are profiled.
When 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.
sampleRate 参数的默认值是1.0,即收集所有慢查询,此参数的范围值是0到1.当级别设置为1会按照sampleRate 设置的值随机抽取百分比的慢操作。
除了在运行时设置慢查询外,还可以在命令模式下启动时设置:
mongod --profile 1 --slowms 15 --slowOpSampleRate 0.5
也可以将参数放置到配置文件:
profile=1
slowms=200
slowOpSampleRate=0.5
profiler的数据存储在MongoDB中的system.profile collection。
在主库修改system.profile的集合的大小:
步骤如下:
Disable profiling.
Drop the system.profile collection.
Create a new system.profile collection.
Re-enable profiling.
--修改为4M:
db.setProfilingLevel(0)
db.system.profile.drop()
db.createCollection( "system.profile", { capped: true, size:4000000 } )
db.setProfilingLevel(1)
--慢查询操作的查询:
--慢查询操作的可视化:
mongoDB的慢查询操作可以结合PMM的监控PMM-QAN,但是支持MongoDB 3.2及以上版本。
需要2个步骤:
1.设置必需的账号
2.开启profiler。
在MongoDB设置账号和权限:
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
MongoDB 3.6 开启慢查询的更多相关文章
- 操作3 mongodb和mysql 开启慢查询日志 ,以及mongodb从配置文件启动
1. mongodb从配置文件启动 创建配置文件:/usr/local/mongodb/etc/mongodb.conf 配置文件的内容为: #Directory and relavent set d ...
- Mongodb 3 查询优化(慢查询Profiling)
开启慢查询Profiling Profiling级别说明 0:关闭,不收集任何数据. 1:收集慢查询数据,默认是100毫秒. 2:收集所有数据 1.通过修改配置文件开启Profiling 修改启动mo ...
- mysql开启慢查询日志及查询--windows
MySQL慢查询配置 1. 慢查询有什么用? 它能记录下所有执行超过long_query_time时间的SQL语句, 帮你找到执行慢的SQL, 方便我们对这些SQL进行优化. 2. 如何开启慢查询? ...
- MYSQL开启慢查询日志实施
查看当前服务器是否开启慢查询:1.快速办法,运行sql语句show VARIABLES like "%slow%" 2.直接去my.conf中查看.my.conf中的配置(放在[m ...
- MySQL 5.5开启慢查询功能
vim /etc/my.cnf [mysqld] slow-query-log = on # 开启慢查询功能 slow_query_log_file = /usr/local/mysql/data/s ...
- MySQL:动态开启慢查询日志(Slow Query Log)
前言 在开发中,高效能的程序 也包括 高效能的查询,所以优化SQL也是程序员必要技能之一.要优化就必须要有慢日志记录才可以知道哪些查询慢,然后反向去修改 慢日志设置方式 写入文件 写入数据库 实践操作 ...
- MySQL开启慢查询 总结
MYSQL慢查询配置 1. 慢查询有什么用? 它能记录下所有执行超过long_query_time时间的SQL语句, 帮你找到执行慢的SQL, 方便我们对这些SQL进行优化. 2. 如何开启慢查询? ...
- linux下mysql开启慢查询
mysql中最影响速度的就是那些查询很慢的语句.这些慢的语句,可能是写的不够合理或者是大数据下多表的联合查询等等.所以我们要找出这些语句,分析原因,加以优化. 1.方法1:用命令开启慢查询 1).查看 ...
- MySQL慢查询(一) - 开启慢查询
一.简介 开启慢查询日志,可以让MySQL记录下查询超过指定时间的语句,通过定位分析性能的瓶颈,才能更好的优化数据库系统的性能. 二.参数说明 slow_query_log 慢查询开启状态slow_q ...
随机推荐
- python安装numpy
命令介绍: D:\computerSoft\python3.6.4\Scripts>python36 pip3.6.exe install numpy # 通过pip下载对应版本的numpy,然 ...
- 两台centos,用yum install 安装,一台成功,一台失败
记录一下问题: 两台centos,用yum install 安装软件,一台成功,一台失败 第一步:查看yum源 yum repolist enabled 疑问:centos安装的方法一致,但yum源 ...
- CF1105C Ayoub and Lost Array ——动态规划
CF1105C Ayoub and Lost Array 题意:一个整数数组,满足: 1. 长度为n 2. 所有元素都在[l, r]范围内 3. 所有元素的和能被3整除给出n, l, r (1 ≤ n ...
- LOJ 2234/BZOJ 3629 聪明的燕姿(数论+DFS)
题面 传送门 分析 看到约数之和,我们首先想到约数和公式 若$ x=\prod_{i=1}^{n}p_i^{k_i} \(,则x的约数和为\) \prod_{i=1}^{n} \sum_{j=0}^{ ...
- bzoj3218 a + b Problem(网络流+主席树)
$ans=\sum_{color_i=black}\ b_i+\sum_{color_i=white}\ w_i-\sum_{i=abnormal}\ p_i$ 把它转化一下 $ans=\sum_{i ...
- DevExpress 控件中设置分隔符
原文:DevExpress 控件中设置分隔符 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net ...
- style中各种选择器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 汇编语言之寄存器使用bx si di bp
转载自:https://www.cnblogs.com/youxin/archive/2012/05/29/2524780.html 如果你看到这篇博客时正在做第七章问题,强烈建议先去把8.1~8.4 ...
- C中char类型的用法
代码 /* char类型的用法 */ #include <stdio.h> main(int argc, char *argv[]) { /* 声明字符变量c1 */ char c1 = ...
- XMPP即时通讯协议使用(二)——基于Smack相关操作
package com.test; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator ...