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 ...
随机推荐
- 《JAVA设计模式》之责任链模式(Chain of Responsibility)
在阎宏博士的<JAVA与模式>一书中开头是这样描述责任链(Chain of Responsibility)模式的: 责任链模式是一种对象的行为模式.在责任链模式里,很多对象由每一个对象对其 ...
- 让gitlab暴露node-exporter供外部prometheus使用
花了两天部署了一套监控服务 prometheus+node-exporter+grafana,公司的gitlab服务器准备部署node-exporter的时候突然发现gitlab已经有了这些服务, 也 ...
- python------模块和包及异常处理
一.模块 所有的模块导入都应该尽量往上写,且顺序为: a:内置模块 b:扩展模块 c:自定义模块 #my_module.py print('from the my_module.py') money= ...
- 9、numpy——数组操作
Numpy 中包含了一些函数用于处理数组,大概可分为以下几类: (1)修改数组形状 (2)翻转数组 (3)修改数组维度 (4)连接数组 (5)分割数组 (6)数组元素的添加与删除 1.修改数组形状 函 ...
- K3 cloud选单时候必须把必录的数据录完以后才可以选单
解决办法:在bos中把选单按钮的提交时候校验打勾
- 微软Visual Studio Code基本特征
Visual Studio Code它的核心功能还是作为一个代码编辑器.和其他的代码编辑器一样,VScode采取通用的UI和布局,浏览器在左边,显示所有的文件和文件夹,右边你打开的文件的编辑页面. 文 ...
- Linux筛选数据
grep命令:在文件中查找关键字,并显示所在行(Globally search a Regular Expression and Print) grep text file:在file文件中搜索tex ...
- vue + element 创建教程
一.环境准备 node安装 node版本:v10.15.3 node下载地址:https://nodejs.org/zh-cn/ vue-cli安装 全局安装vue-cli npm install - ...
- 基本的bash shell
一.linux文件系统 linux文件系统结构是从Unix文件结构演进过来的.在linux文件系统中,通用的目录名用于表示一些常见的功能.如下表列出一些较为常见的Linux顶层虚拟目录名及其内容. / ...
- setup PC not sleep when turn off display