db.setProfilingLevel()---用于采集与分析慢操作的数据库请求
发布日期:2021-11-15 14:57:46 浏览次数:38 分类:技术文章

本文共 3371 字,大约阅读时间需要 11 分钟。

db.setProfilingLevel()

mongodb的profiler设置,默认该设置是关闭的,profiler可用于采集与分析慢操作的数据库请求。

> db.setProfilingLevel(
,
);

Parameters

参数:level
Type: integer
Description:配置数据库profiler级别

level Description
0 profiler已关闭,并且不收集任何数据。这是默认的profiler级别。
1 profiler收集花费的时间超过slowms值的数据。
2 profiler收集所有操作的数据。

参数:options

Type: document or integer
Description:可选的,接受document or integer。如果将整数值作为options参数而不是文档作为参数传递,则该值将分配给slowms。

Parameter Type Default Description
slowms integer 100 操作时间阈值,单位为毫秒。运行时间超过此阈值的操作被认为是缓慢的,将会被记录。
当logLevel设置为0时,MongoDB将以slowOpSampleRate确定的速率将慢速操作记录到诊断日志中。 从MongoDB 4.2开始,副本集的辅助副本记录所有花费比慢操作阈值更长的时间来应用的oplog条目消息,而不管采样率如何。
在较高的logLevel设置下,所有操作都将显示在诊断日志中,而与它们的延迟无关,但以下情况除外:次要对象记录慢速oplog条目消息。 辅助服务器仅记录慢速操作日志条目; 增加logLevel不会记录所有操作日志条目。
对于mongod实例,该设置会同时影响诊断日志和探查器(如果启用)。
对于mongos实例,该设置仅影响诊断日志,而不影响profiler,因为在mongos上不提供概要分析。
sampleRate double 1.0 表示分析或记录的慢速操作的百分数。 sampleRate接受介于0和1之间(含)的值。
对于mongod实例,该设置会同时影响诊断日志和探查器(如果启用)。
对于mongos实例,该设置仅影响诊断日志,而不影响事件探查器,因为在mongos上不提供概要分析。
filter object 一个过滤器表达式,用于控制分析和记录哪些操作。 过滤器表达式中的字段可以是profiler输出中的任何字段。
对于mongod实例,该设置会同时影响诊断日志和探查器(如果启用)。
对于mongos实例,该设置仅影响诊断日志,而不影响事件探查器,因为在mongos上不提供概要分析。
版本4.4.2中的新功能。

该方法会返回一个包含先前设置值的文档。

单机版Returns

{
"was" : 2, "slowms" : 100, "sampleRate" : 1, "filter" : {
"$and" : [ {
"op" : {
"$eq" : "query" } }, {
"millis" : {
"$gt" : 20000 } } ] }, "note" : "When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.", "ok" : 1}

副本集Returns

{
"was" : 0, "slowms" : 100, "sampleRate" : 1, "filter" : {
"$and" : [ {
"op" : {
"$eq" : "query" } }, {
"millis" : {
"$gte" : 2000 } } ] }, "note" : "When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.", "ok" : 1, "$clusterTime" : {
"clusterTime" : Timestamp(1572991238, 1), "signature" : {
"hash" : BinData(0,"hg6GnlrVhV9MAhwWdeHmHQ4T4qU="), "keyId" : NumberLong("6755945537557495811") } }, "operationTime" : Timestamp(1572991238, 1)}

mongos实例Returns

{
"was" : 0, "slowms" : 100, "sampleRate" : 1, "filter" : {
"$and" : [ {
"op" : {
"$eq" : "query" } }, {
"millis" : {
"$gte" : 2000 } } ] }, "note" : "When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.", "ok" : 1, "operationTime" : Timestamp(1572991499, 2), "$clusterTime" : {
"clusterTime" : Timestamp(1572991499, 2), "signature" : {
"hash" : BinData(0,"nhCquIxUw7thlrBudXe3PnsnvP0="), "keyId" : NumberLong("6755946491040235540") } }}

Parameter:

  • was 返回先前的profiler级别设置
  • slowms 返回先前的slowms阈值设置
  • sampleRate 返回先前的sampleRate设置
  • filter 返回先前的过滤器设置 (New in MongoDB 4.4.2)
  • note 是说明过滤器的字符串。 仅当还存在过滤器时,此字段才会出现在输出中。 (New in MongoDB 4.4.2)

查看当前设置:

> db.getProfilingStatus();

Examples

mongod实例设置:

  • profiler的级别设置为1
  • slowms阈值为20毫秒
  • sampleRate为42%
> db.setProfilingLevel(1, { slowms: 20, sampleRate: 0.42 })

转载地址:https://blog.csdn.net/qq_39741836/article/details/111984247 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:web实现视频播放-服务端所需工作
下一篇:mongodb数据备份与恢复基本操作示例

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月17日 09时23分49秒