给您的 MongoDB 定期做个体检:MongoDB 诊断

news2025/6/20 17:05:36

712b9163273e834524a7e01531fd37e8.gif

新钛云服已累计为您分享739篇技术干货

5c1039d9225a60632109eb74d3bcafe3.gif

接下来的一些列文章会为大家介绍日常工作中常用的 NoSQL 产品 MongoDB。

主要涉及到:

MongoDB 的安装及基本使用   

MongoDB 文档查询   

MongoDB 复制集   

MongoDB 分片集群的介绍及搭建   

MongoDB 安全加密   

MongoDB 诊断

我们会用六篇文章近五万字来阐述 MongoDB 运维相关的日常实战事宜。您当前看到的是系列文章的第六篇:《MongoDB 诊断》

随着 MongoDB 的不断运行且数据量日益增多,就会不免产生一些问题。当问题出现时,该怎么办呢?我们会从以下几个方面进行探讨。

日志

当有个长期运行的 MongoDB 进程时,我们可能想自己写个脚本来定期轮转日志文件。其实不用,MongoDB 已经提供了 logrotate 命令来完成这个操作,可以直接从 shell 里启动使用:

use admin


rs0:PRIMARY> db.runCommand({logRotate: 1})
{
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1679966896, 1),
        "signature" : {
            "hash" : BinData(0,"50vWhFp/59fAKwBbUQUDxApF/+g="),
            "keyId" : NumberLong("7173500260914823169")
        }
    },
    "operationTime" : Timestamp(1679966896, 1)
}

需要注意:logRotate 是区分大小写的。

或者可以向 Mongo 进程发送 SIGUSR1 信号:

$ kill -SIGUSR1 <mongo_pid>

诊断命令

MongoDB 包含了许多命令可以报告内部状态,这些命令背后都是监控 MongoDB。下面是一些常见命令的参考命令,希望对大家有所帮助:

  • 全局服务器统计信息: db.serverStatus();

  • 统计当前运行的操作: db.currentOp();

  • 包含空闲的操作: db currentOp(true)

  • 每个数据库的计数器和活动统计: db.runCommand({top: 1}) ; 

  • 查看当前数据库信息: db.stats()

我们接下来分别看一看上述这几个命令的输出。

01

全局服务器信息统计

00acf8e4a3d645ba60a6f69dd94f8172.gif

该命令输出的信息非常详细,当 MongoDB 出现问题时,是一个不错的诊断命令。

rs0:PRIMARY> db.serverStatus()
{
    "host" : "mongo03.tyun.cn",
    "version" : "4.4.15",
    "process" : "mongod",
    "pid" : NumberLong(14092),
    "uptime" : 18727504,
    "uptimeMillis" : NumberLong("18727504137"),
    "uptimeEstimate" : NumberLong(18727504),
    "localTime" : ISODate("2023-03-28T01:30:35.805Z"),
    "asserts" : {
        "regular" : 0,
        "warning" : 0,
        "msg" : 0,
        "user" : 1380727,
        "rollovers" : 0
    },
    "connections" : {
        "current" : 17,
        "available" : 51183,
        "totalCreated" : 3253,
        "active" : 7,
        "exhaustIsMaster" : 3,
        "exhaustHello" : 2,
        "awaitingTopologyChanges" : 176
    },
    "defaultRWConcern" : {
        "localUpdateWallClockTime" : ISODate("2022-08-23T07:25:32.995Z")
    },


        "tcmalloc" : {
            "pageheap_free_bytes" : 94162944,
            "pageheap_unmapped_bytes" : 349478912,
            "max_total_thread_cache_bytes" : 1024458752,
            "current_total_thread_cache_bytes" : 238198560,
            "total_free_bytes" : 637257904,
            "central_cache_free_bytes" : 397502736,
            "transfer_cache_free_bytes" : 1556608,
            "thread_cache_free_bytes" : 238198560,
            "aggressive_memory_decommit" : 0,
            "pageheap_committed_bytes" : NumberLong("3653197824"),
            "pageheap_scavenge_count" : 13297522,
            "pageheap_commit_count" : 14804116,
            "pageheap_total_commit_bytes" : NumberLong("60304102580224"),
            "pageheap_decommit_count" : 13297522,
            "pageheap_total_decommit_bytes" : NumberLong("60300449382400"),
            "pageheap_reserve_count" : 459,
            "pageheap_total_reserve_bytes" : NumberLong("4002676736"),
            "spinlock_total_delay_ns" : NumberLong("111430768421"),
            "release_rate" : 1,
            "formattedString" : "------------------------------------------------\nMALLOC:     2921777552 ( 2786.4 MiB) Bytes in use by application\nMALLOC: +     94162944 (   89.8 MiB) Bytes in page heap freelist\nMALLOC: +    397502736 (  379.1 MiB) Bytes in central cache freelist\nMALLOC: +      1556608 (    1.5 MiB) Bytes in transfer cache freelist\nMALLOC: +    238197984 (  227.2 MiB) Bytes in thread cache freelists\nMALLOC: +     24510464 (   23.4 MiB) Bytes in malloc metadata\nMALLOC:   ------------\nMALLOC: =   3677708288 ( 3507.3 MiB) Actual memory used (physical + swap)\nMALLOC: +    349478912 (  333.3 MiB) Bytes released to OS (aka unmapped)\nMALLOC:   ------------\nMALLOC: =   4027187200 ( 3840.6 MiB) Virtual address space used\nMALLOC:\nMALLOC:         265177              Spans in use\nMALLOC:             72              Thread heaps in use\nMALLOC:           4096              Tcmalloc page size\n------------------------------------------------\nCall ReleaseFreeMemory() to release freelist memory to the OS (via madvise()).\nBytes released to the OS take up virtual address space but no physical memory.\n"
        }
    },
    "trafficRecording" : {
        "running" : false
    },
    "transactions" : {
        "retriedCommandsCount" : NumberLong(0),
        "retriedStatementsCount" : NumberLong(0),
        "transactionsCollectionWriteCount" : NumberLong(0),
        "currentActive" : NumberLong(0),
        "currentInactive" : NumberLong(0),
        "currentOpen" : NumberLong(0),
        "totalAborted" : NumberLong(0),
        "totalCommitted" : NumberLong(0),
        "totalStarted" : NumberLong(0),
        "totalPrepared" : NumberLong(0),
        "totalPreparedThenCommitted" : NumberLong(0),
        "totalPreparedThenAborted" : NumberLong(0),
        "currentPrepared" : NumberLong(0)
    },
    "transportSecurity" : {
        "1.0" : NumberLong(0),
        "1.1" : NumberLong(0),
        "1.2" : NumberLong(0),
        "1.3" : NumberLong(0),
        "unknown" : NumberLong(0)
    },
    "twoPhaseCommitCoordinator" : {
        "totalCreated" : NumberLong(0),
        "totalStartedTwoPhaseCommit" : NumberLong(0),
        "totalAbortedTwoPhaseCommit" : NumberLong(0),
        "totalCommittedTwoPhaseCommit" : NumberLong(0),
        "currentInSteps" : {
            "writingParticipantList" : NumberLong(0),
            "waitingForVotes" : NumberLong(0),
            "writingDecision" : NumberLong(0),
            "waitingForDecisionAcks" : NumberLong(0),
            "deletingCoordinatorDoc" : NumberLong(0)
        }
    },
    "wiredTiger" : {
        "uri" : "statistics:",
        "block-manager" : {
            "blocks pre-loaded" : 23,
            "blocks read" : 4268362,
            "blocks written" : 39421996,
            "bytes read" : 48401854464,
            "bytes read via memory map API" : 0,
            "bytes read via system call API" : 0,
            "bytes written" : 418967826432,
            "bytes written for checkpoint" : 305570754560,
            "bytes written via memory map API" : 0,
            "bytes written via system call API" : 0,
            "mapped blocks read" : 0,
            "mapped bytes read" : 0,
            "number of times the file was remapped because it changed size via fallocate or truncate" : 0,
            "number of times the region was remapped via write" : 0
        },


        "capacity" : {
            "background fsync file handles considered" : 0,
            "background fsync file handles synced" : 0,
            "background fsync time (msecs)" : 0,
            "bytes read" : 39614959616,
            "bytes written for checkpoint" : 239185165378,
            "bytes written for eviction" : 97795992160,
            "bytes written for log" : 157233860864,
            "bytes written total" : 494215018402,
            "threshold to call fsync" : 0,
            "time waiting due to total capacity (usecs)" : 0,
            "time waiting during checkpoint (usecs)" : 0,
            "time waiting during eviction (usecs)" : 0,
            "time waiting during logging (usecs)" : 0,
            "time waiting during read (usecs)" : 0
        },
        "checkpoint-cleanup" : {
            "pages added for eviction" : 81667,
            "pages removed" : 16946,
            "pages skipped during tree walk" : 3064011324,
            "pages visited" : 5381579176
        },
        "connection" : {
            "auto adjusting condition resets" : 6326104,
            "auto adjusting condition wait calls" : 121447994,
            "auto adjusting condition wait raced to update timeout and skipped updating" : 61,
            "detected system time went backwards" : 0,
            "files currently open" : 71,
            "hash bucket array size for data handles" : 512,
            "hash bucket array size general" : 512,
            "memory allocations" : 14030754494,
            "memory frees" : 14027269174,
            "memory re-allocations" : 161883962,
            "pthread mutex condition wait calls" : 314479507,
            "pthread mutex shared lock read-lock calls" : 12181240198,
            "pthread mutex shared lock write-lock calls" : 743154980,
            "total fsync I/Os" : 275579938,
            "total read I/Os" : 4582332,
            "total write I/Os" : 313739357
        },


    "mem" : {
        "bits" : 64,
        "resident" : 3423,
        "virtual" : 5564,
        "supported" : true
    },
    "metrics" : {
        "aggStageCounters" : {
            "$_internalInhibitOptimization" : NumberLong(0),
            "$_internalSplitPipeline" : NumberLong(0),
            "$addFields" : NumberLong(1),
            "$bucket" : NumberLong(0),
            "$bucketAuto" : NumberLong(0),
            "$changeStream" : NumberLong(0),
            "$collStats" : NumberLong(0),
            "$count" : NumberLong(0),
            "$currentOp" : NumberLong(0),
            "$documents" : NumberLong(0),
            "$facet" : NumberLong(0),
            "$geoNear" : NumberLong(0),
            "$graphLookup" : NumberLong(0),
            "$group" : NumberLong(0),
            "$indexStats" : NumberLong(0),
            "$limit" : NumberLong(0),
            "$listLocalSessions" : NumberLong(0),
            "$listSessions" : NumberLong(0),
            "$lookup" : NumberLong(0),
            "$match" : NumberLong(1),
            "$merge" : NumberLong(0),
            "$mergeCursors" : NumberLong(0),
            "$out" : NumberLong(0),
            "$planCacheStats" : NumberLong(0),
            "$project" : NumberLong(2),
            "$queue" : NumberLong(0),
            "$redact" : NumberLong(0),
            "$replaceRoot" : NumberLong(0),
            "$replaceWith" : NumberLong(0),
            "$sample" : NumberLong(0),
            "$set" : NumberLong(46126),
            "$skip" : NumberLong(0),
            "$sort" : NumberLong(1),
            "$sortByCount" : NumberLong(0),
            "$unionWith" : NumberLong(0),
            "$unset" : NumberLong(0),
            "$unwind" : NumberLong(0)
        },
        "commands" : {
            "<UNKNOWN>" : NumberLong(2),
            "_isSelf" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(13)
            },
            "buildInfo" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(690365)
            },
            "count" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(6)
            },
            "delete" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(48)
            },
            "endSessions" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(134)
            },
            "find" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(2142077)
            },
            "getCmdLineOpts" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(1380235)
            },
            "getDiagnosticData" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(2070345)
            },
            "getFreeMonitoringStatus" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(5)
            },
            "getLastError" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(101)
            },
            "getLog" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(5)
            },
            "getMore" : {
                "failed" : NumberLong(1),
                "total" : NumberLong(465344562)
            },
            "getnonce" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(2)
            },
            "hello" : {
                "failed" : NumberLong(268),
                "total" : NumberLong(1384888)
            },
            "insert" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(1)
            },
            "isMaster" : {
                "failed" : NumberLong(2),
                "total" : NumberLong(7731521)
            },
            "killCursors" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(5)
            },
            "listCollections" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(10)
            },
            "listDatabases" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(57515)
            },
            "listIndexes" : {
                "failed" : NumberLong(3),
                "total" : NumberLong(124851)
            },
            "logRotate" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(1)
            },
            "ping" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(4436308)
            },
            "replSetGetConfig" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(2070345)
            },
            "replSetGetRBID" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(6)
            },
            "replSetGetStatus" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(690128)
            },
            "replSetHeartbeat" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(17000850)
            },
            "replSetRequestVotes" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(4)
            },
            "replSetUpdatePosition" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(390211482)
            },
            "rolesInfo" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(1)
            },
            "saslContinue" : {
                "failed" : NumberLong(6),
                "total" : NumberLong(62466)
            },
            "saslStart" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(57875)
            },
            "serverStatus" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(1)
            },
            "update" : {
                "arrayFilters" : NumberLong(0),
                "failed" : NumberLong(0),
                "pipeline" : NumberLong(23063),
                "total" : NumberLong(511271)
            },
            "usersInfo" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(1)
            },
            "whatsmyuri" : {
                "failed" : NumberLong(0),
                "total" : NumberLong(5)
            }
        },
        "cursor" : {
            "timedOut" : NumberLong(0),
            "open" : {
                "noTimeout" : NumberLong(0),
                "pinned" : NumberLong(1),
                "total" : NumberLong(1)
            }
        },
        "document" : {
            "deleted" : NumberLong(0),
            "inserted" : NumberLong(1),
            "returned" : NumberLong(322743825),
            "updated" : NumberLong(522796)
        },
        "getLastError" : {
            "wtime" : {
                "num" : 11577,
                "totalMillis" : 37265
            },
            "wtimeouts" : NumberLong(1),
            "default" : {
                "unsatisfiable" : NumberLong(0),
                "wtimeouts" : NumberLong(0)
            }
        },
        "operation" : {
            "scanAndOrder" : NumberLong(15),
            "writeConflicts" : NumberLong(9825)
        },


        "query" : {
            "planCacheTotalSizeEstimateBytes" : NumberLong(0),
            "updateOneOpStyleBroadcastWithExactIDCount" : NumberLong(0),
            "multiPlanner" : {
                "classicCount" : NumberLong(0),
                "classicMicros" : NumberLong(0),
                "classicWorks" : NumberLong(0),
                "histograms" : {
                    "classicMicros" : [
                        {
                            "lowerBound" : NumberLong(0),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(1024),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(4096),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(16384),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(65536),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(262144),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(1048576),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(4194304),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(16777216),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(67108864),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(268435456),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(1073741824),
                            "count" : NumberLong(0)
                        }
                    ],
                    "classicNumPlans" : [
                        {
                            "lowerBound" : NumberLong(0),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(2),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(4),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(8),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(16),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(32),
                            "count" : NumberLong(0)
                        }
                    ],
                    "classicWorks" : [
                        {
                            "lowerBound" : NumberLong(0),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(128),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(256),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(512),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(1024),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(2048),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(4096),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(8192),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(16384),
                            "count" : NumberLong(0)
                        },
                        {
                            "lowerBound" : NumberLong(32768),
                            "count" : NumberLong(0)
                        }
                    ]
                }
            }
        },
        "queryExecutor" : {
            "scanned" : NumberLong(1070392),
            "scannedObjects" : NumberLong(323266658),
            "collectionScans" : {
                "nonTailable" : NumberLong(1386454),
                "total" : NumberLong(1386461)
            }
        },
        "record" : {
            "moves" : NumberLong(0)
        },
        "repl" : {
            "executor" : {
                "pool" : {
                    "inProgressCount" : 0
                },
                "queues" : {
                    "networkInProgress" : 0,
                    "sleepers" : 3
                },
                "unsignaledEvents" : 0,
                "shuttingDown" : false,
                "networkInterface" : "DEPRECATED: getDiagnosticString is deprecated in NetworkInterfaceTL"
            },
            "apply" : {
                "attemptsToBecomeSecondary" : NumberLong(19),
                "batchSize" : NumberLong(318318346),
                "batches" : {
                    "num" : 278600198,
                    "totalMillis" : 5795319
                },
                "ops" : NumberLong(318318943)
            },
            "buffer" : {
                "count" : NumberLong(0),
                "maxSizeBytes" : NumberLong(268435456),
                "sizeBytes" : NumberLong(0)
            },
            "initialSync" : {
                "completed" : NumberLong(0),
                "failedAttempts" : NumberLong(0),
                "failures" : NumberLong(0)
            },
            "network" : {
                "bytes" : NumberLong("57955381887"),
                "getmores" : {
                    "num" : 364468339,
                    "totalMillis" : 15110995960,
                    "numEmptyBatches" : NumberLong(67943454)
                },
                "notPrimaryLegacyUnacknowledgedWrites" : NumberLong(0),
                "notPrimaryUnacknowledgedWrites" : NumberLong(0),
                "oplogGetMoresProcessed" : {
                    "num" : 465344548,
                    "totalMillis" : 200161
                },
                "ops" : NumberLong(318318349),
                "readersCreated" : NumberLong(5),
                "replSetUpdatePosition" : {
                    "num" : NumberLong(455260555)
                }
            },
            "stateTransition" : {
                "lastStateTransition" : "stepUp",
                "userOperationsKilled" : NumberLong(0),
                "userOperationsRunning" : NumberLong(5)
            },
            "syncSource" : {
                "numSelections" : NumberLong(28),
                "numTimesChoseDifferent" : NumberLong(3),
                "numTimesChoseSame" : NumberLong(0),
                "numTimesCouldNotFind" : NumberLong(25)
            }
        },
        "ttl" : {
            "deletedDocuments" : NumberLong(9),
            "passes" : NumberLong(312121)
        }
    },
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1679967033, 3),
        "signature" : {
            "hash" : BinData(0,"7p9I6mnYmAqWdGWHZuVRCfEIJtU="),
            "keyId" : NumberLong("7173500260914823169")
        }
    },
    "operationTime" : Timestamp(1679967033, 3)
}

02

统计当前运行的操作

7aad6be145e19167f20e62e5a8aaad8a.gif

rs0:PRIMARY> db.currentOp()
{
    "inprog" : [
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "OplogApplier-0",
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.539+00:00",
            "effectiveUsers" : [
                {
                    "user" : "__system",
                    "db" : "local"
                }
            ],
            "opid" : -935445419,
            "op" : "none",
            "ns" : "",
            "command" : {


            },
            "numYields" : 0,
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "TimestampMonitor",
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "opid" : -935445412,
            "op" : "none",
            "ns" : "",
            "command" : {


            },
            "numYields" : 0,
            "waitingForLatch" : {
                "timestamp" : ISODate("2023-03-28T01:37:05.546Z"),
                "captureName" : "ServiceContext::_mutex"
            },
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "ReplBatcher",
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "opid" : -935445421,
            "op" : "none",
            "ns" : "",
            "command" : {


            },
            "numYields" : 0,
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {
                "FeatureCompatibilityVersion" : {
                    "acquireCount" : {
                        "r" : NumberLong(1)
                    }
                },
                "ReplicationStateTransition" : {
                    "acquireCount" : {
                        "w" : NumberLong(1)
                    }
                },
                "Global" : {
                    "acquireCount" : {
                        "r" : NumberLong(1)
                    }
                }
            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "conn333",
            "connectionId" : 333,
            "client" : "10.20.20.11:42734",
            "clientMetadata" : {
                "driver" : {
                    "name" : "NetworkInterfaceTL",
                    "version" : "4.4.15"
                },
                "os" : {
                    "type" : "Linux",
                    "name" : "CentOS Linux release 7.9.2009 (Core)",
                    "architecture" : "x86_64",
                    "version" : "Kernel 3.10.0-1160.62.1.el7.x86_64"
                }
            },
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "effectiveUsers" : [
                {
                    "user" : "__system",
                    "db" : "local"
                }
            ],
            "opid" : -935445430,
            "secs_running" : NumberLong(1),
            "microsecs_running" : NumberLong(1002908),
            "op" : "command",
            "ns" : "admin.$cmd",
            "command" : {
                "isMaster" : 1,
                "maxAwaitTimeMS" : NumberLong(10000),
                "topologyVersion" : {
                    "processId" : ObjectId("630480eb8e13bda8cb16c7e9"),
                    "counter" : NumberLong(28)
                },
                "internalClient" : {
                    "minWireVersion" : 9,
                    "maxWireVersion" : 9
                },
                "$db" : "admin"
            },
            "numYields" : 0,
            "waitingForLatch" : {
                "timestamp" : ISODate("2023-03-28T01:37:04.649Z"),
                "captureName" : "FutureResolution"
            },
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "conn6901",
            "connectionId" : 6901,
            "client" : "10.20.20.19:56616",
            "appName" : "MongoDB Shell",
            "clientMetadata" : {
                "application" : {
                    "name" : "MongoDB Shell"
                },
                "driver" : {
                    "name" : "MongoDB Internal Client",
                    "version" : "4.4.15"
                },
                "os" : {
                    "type" : "Linux",
                    "name" : "CentOS Linux release 7.9.2009 (Core)",
                    "architecture" : "x86_64",
                    "version" : "Kernel 3.10.0-1160.62.1.el7.x86_64"
                }
            },
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "effectiveUsers" : [
                {
                    "user" : "root",
                    "db" : "admin"
                }
            ],
            "opid" : -935445413,
            "lsid" : {
                "id" : UUID("5daca131-7d85-4e21-a44b-2b1ded973009"),
                "uid" : BinData(0,"Y5mrDaxi8gv8RmdTsQ+1j7fmkr7JUsabhNmXAheU0fg=")
            },
            "secs_running" : NumberLong(0),
            "microsecs_running" : NumberLong(22989),
            "op" : "command",
            "ns" : "admin.$cmd.aggregate",
            "command" : {
                "currentOp" : 1,
                "lsid" : {
                    "id" : UUID("5daca131-7d85-4e21-a44b-2b1ded973009")
                },
                "$clusterTime" : {
                    "clusterTime" : Timestamp(1679967416, 1),
                    "signature" : {
                        "hash" : BinData(0,"hZEpDTiaiD3Zna+djn4cNU7WLjE="),
                        "keyId" : NumberLong("7173500260914823169")
                    }
                },
                "$db" : "admin"
            },
            "numYields" : 0,
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "OplogCapMaintainerThread-local.oplog.rs",
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "opid" : -964016203,
            "op" : "none",
            "ns" : "",
            "command" : {


            },
            "numYields" : 0,
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {
                "FeatureCompatibilityVersion" : {
                    "acquireCount" : {
                        "w" : NumberLong(1)
                    }
                },
                "ReplicationStateTransition" : {
                    "acquireCount" : {
                        "w" : NumberLong(1)
                    }
                },
                "Global" : {
                    "acquireCount" : {
                        "w" : NumberLong(1)
                    }
                }
            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "conn2762",
            "connectionId" : 2762,
            "client" : "10.20.20.41:33548",
            "appName" : "QAN-mongodb-profiler-/agent_id/549d2b38-caf8-44a4-9903-28f769a12e68",
            "clientMetadata" : {
                "driver" : {
                    "name" : "mongo-go-driver",
                    "version" : "v1.11.1"
                },
                "os" : {
                    "type" : "linux",
                    "architecture" : "amd64"
                },
                "platform" : "go1.19.1",
                "application" : {
                    "name" : "QAN-mongodb-profiler-/agent_id/549d2b38-caf8-44a4-9903-28f769a12e68"
                }
            },
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "opid" : -935445550,
            "secs_running" : NumberLong(7),
            "microsecs_running" : NumberLong(7041972),
            "op" : "command",
            "ns" : "admin.$cmd",
            "command" : {
                "hello" : 1,
                "helloOk" : true,
                "topologyVersion" : {
                    "processId" : ObjectId("630480eb8e13bda8cb16c7e9"),
                    "counter" : NumberLong(28)
                },
                "maxAwaitTimeMS" : NumberLong(10000),
                "$db" : "admin",
                "$readPreference" : {
                    "mode" : "primaryPreferred"
                }
            },
            "numYields" : 0,
            "waitingForLatch" : {
                "timestamp" : ISODate("2023-03-28T01:36:58.610Z"),
                "captureName" : "FutureResolution"
            },
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "JournalFlusher",
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "opid" : -935445414,
            "op" : "none",
            "ns" : "",
            "command" : {


            },
            "numYields" : 0,
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "conn332",
            "connectionId" : 332,
            "client" : "10.20.20.11:42736",
            "clientMetadata" : {
                "driver" : {
                    "name" : "NetworkInterfaceTL",
                    "version" : "4.4.15"
                },
                "os" : {
                    "type" : "Linux",
                    "name" : "CentOS Linux release 7.9.2009 (Core)",
                    "architecture" : "x86_64",
                    "version" : "Kernel 3.10.0-1160.62.1.el7.x86_64"
                }
            },
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "effectiveUsers" : [
                {
                    "user" : "__system",
                    "db" : "local"
                }
            ],
            "opid" : -935445538,
            "secs_running" : NumberLong(6),
            "microsecs_running" : NumberLong(6388394),
            "op" : "command",
            "ns" : "admin.$cmd",
            "command" : {
                "isMaster" : 1,
                "maxAwaitTimeMS" : NumberLong(10000),
                "topologyVersion" : {
                    "processId" : ObjectId("630480eb8e13bda8cb16c7e9"),
                    "counter" : NumberLong(28)
                },
                "internalClient" : {
                    "minWireVersion" : 9,
                    "maxWireVersion" : 9
                },
                "$db" : "admin"
            },
            "numYields" : 0,
            "waitingForLatch" : {
                "timestamp" : ISODate("2023-03-28T01:36:59.264Z"),
                "captureName" : "FutureResolution"
            },
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "NoopWriter",
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "opid" : -935445599,
            "op" : "none",
            "ns" : "",
            "command" : {


            },
            "numYields" : 0,
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "conn326",
            "connectionId" : 326,
            "client" : "10.20.20.11:42726",
            "appName" : "OplogFetcher",
            "clientMetadata" : {
                "application" : {
                    "name" : "OplogFetcher"
                },
                "driver" : {
                    "name" : "MongoDB Internal Client",
                    "version" : "4.4.15"
                },
                "os" : {
                    "type" : "Linux",
                    "name" : "CentOS Linux release 7.9.2009 (Core)",
                    "architecture" : "x86_64",
                    "version" : "Kernel 3.10.0-1160.62.1.el7.x86_64"
                }
            },
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "effectiveUsers" : [
                {
                    "user" : "__system",
                    "db" : "local"
                }
            ],
            "opid" : -935445493,
            "secs_running" : NumberLong(3),
            "microsecs_running" : NumberLong(3702937),
            "op" : "getmore",
            "ns" : "local.oplog.rs",
            "command" : {
                "getMore" : NumberLong("3869305470684881343"),
                "collection" : "oplog.rs",
                "batchSize" : NumberLong(13981010),
                "maxTimeMS" : NumberLong(5000),
                "term" : NumberLong(3),
                "lastKnownCommittedOpTime" : {
                    "ts" : Timestamp(1661570687, 1397),
                    "t" : NumberLong(2)
                },
                "$db" : "local",
                "$replData" : 1,
                "$oplogQueryData" : 1,
                "$readPreference" : {
                    "mode" : "secondaryPreferred"
                },
                "$clusterTime" : {
                    "clusterTime" : Timestamp(1661570687, 1399),
                    "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                    }
                }
            },
            "planSummary" : "COLLSCAN",


        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "conn2764",
            "connectionId" : 2764,
            "client" : "10.20.20.41:33552",
            "appName" : "mongodb_exporter",
            "clientMetadata" : {
                "driver" : {
                    "name" : "mongo-go-driver",
                    "version" : "v1.10.3"
                },
                "os" : {
                    "type" : "linux",
                    "architecture" : "amd64"
                },
                "platform" : "go1.19.1",
                "application" : {
                    "name" : "mongodb_exporter"
                }
            },
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "opid" : -935445535,
            "secs_running" : NumberLong(6),
            "microsecs_running" : NumberLong(6117158),
            "op" : "command",
            "ns" : "admin.$cmd",
            "command" : {
                "hello" : 1,
                "helloOk" : true,
                "topologyVersion" : {
                    "processId" : ObjectId("630480eb8e13bda8cb16c7e9"),
                    "counter" : NumberLong(28)
                },
                "maxAwaitTimeMS" : NumberLong(10000),
                "$db" : "admin",
                "$readPreference" : {
                    "mode" : "primaryPreferred"
                }
            },
            "numYields" : 0,
            "waitingForLatch" : {
                "timestamp" : ISODate("2023-03-28T01:36:59.535Z"),
                "captureName" : "FutureResolution"
            },
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "WTCheckpointThread",
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "opid" : -935445426,
            "op" : "none",
            "ns" : "",
            "command" : {


            },
            "numYields" : 0,
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        },
        {
            "type" : "op",
            "host" : "mongo03.tyun.cn:27017",
            "desc" : "conn184",
            "connectionId" : 184,
            "client" : "10.20.20.41:45032",
            "clientMetadata" : {
                "driver" : {
                    "name" : "NetworkInterfaceTL",
                    "version" : "4.4.15"
                },
                "os" : {
                    "type" : "Linux",
                    "name" : "CentOS Linux release 7.9.2009 (Core)",
                    "architecture" : "x86_64",
                    "version" : "Kernel 3.10.0-1160.62.1.el7.x86_64"
                }
            },
            "active" : true,
            "currentOpTime" : "2023-03-28T01:37:05.552+00:00",
            "effectiveUsers" : [
                {
                    "user" : "__system",
                    "db" : "local"
                }
            ],
            "opid" : -935445564,
            "secs_running" : NumberLong(7),
            "microsecs_running" : NumberLong(7951531),
            "op" : "command",
            "ns" : "admin.$cmd",
            "command" : {
                "isMaster" : 1,
                "maxAwaitTimeMS" : NumberLong(10000),
                "topologyVersion" : {
                    "processId" : ObjectId("630480eb8e13bda8cb16c7e9"),
                    "counter" : NumberLong(28)
                },
                "internalClient" : {
                    "minWireVersion" : 9,
                    "maxWireVersion" : 9
                },
                "$db" : "admin"
            },
            "numYields" : 0,
            "waitingForLatch" : {
                "timestamp" : ISODate("2023-03-28T01:36:57.701Z"),
                "captureName" : "FutureResolution"
            },
            "locks" : {


            },
            "waitingForLock" : false,
            "lockStats" : {


            },
            "waitingForFlowControl" : false,
            "flowControlStats" : {


            }
        }
    ],
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1679967416, 1),
        "signature" : {
            "hash" : BinData(0,"hZEpDTiaiD3Zna+djn4cNU7WLjE="),
            "keyId" : NumberLong("7173500260914823169")
        }
    },
    "operationTime" : Timestamp(1679967416, 1)
}

03

查看当前数据库统计信息

073036e30f56c6a0631f7914cdbc975a.gif

该命令返回当前连接的数据库信息。如:查看 admin 数据库信息:

rs0:PRIMARY> db.stats()
{
    "db" : "admin",
    "collections" : 4,
    "views" : 0,
    "objects" : 10,
    "avgObjSize" : 242.8,
    "dataSize" : 2428,
    "storageSize" : 131072,
    "indexes" : 6,
    "indexSize" : 188416,
    "totalSize" : 319488,
    "scaleFactor" : 1,
    "fsUsedSize" : 44225654784,
    "fsTotalSize" : 64174051328,
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1679967646, 1),
        "signature" : {
            "hash" : BinData(0,"G/+ynHN7GNtj09WoJaJ4TMXR/sc="),
            "keyId" : NumberLong("7173500260914823169")
        }
    },
    "operationTime" : Timestamp(1679967646, 1)
}

还可以查看其他数据库信息:

rs0:PRIMARY> show dbs
admin        0.000GB
config       0.000GB
local        3.794GB
mongoshake   0.000GB
signals      0.000GB
streams      0.000GB
test         6.814GB
ycsb        14.253GB
rs0:PRIMARY> use streams
switched to db streams
rs0:PRIMARY> db.stats()
{
    "db" : "streams",
    "collections" : 2,
    "views" : 0,
    "objects" : 2,
    "avgObjSize" : 40,
    "dataSize" : 80,
    "storageSize" : 40960,
    "indexes" : 2,
    "indexSize" : 40960,
    "totalSize" : 81920,
    "scaleFactor" : 1,
    "fsUsedSize" : 44226154496,
    "fsTotalSize" : 64174051328,
    "ok" : 1,
    "$clusterTime" : {
        "clusterTime" : Timestamp(1679967836, 1),
        "signature" : {
            "hash" : BinData(0,"L0keGbNUzAlINUX7sbG9t2TzkAk="),
            "keyId" : NumberLong("7173500260914823169")
        }
    },
    "operationTime" : Timestamp(1679967836, 1)
}

04

mongostat

8dd85e2864ac9b1216cd4b89deb7bde2.gif

mongostat 是 db.currentOp() 及 db.serverStatus() 命令的外部工具。以下是一个演示:

[root@mongo01 ~]# mongostat --host mongo03.tyun.cn:27017 --authenticationDatabase admin -u root 5
Enter password:


insert query update delete getmore command dirty  used flushes vsize   res qrw arw net_in net_out conn set repl                time
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.61k   56.7k   19 rs0  PRI Mar 28 01:46:02.077
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       1 5.43G 3.34G 0|0 1|0  1.78k   56.7k   19 rs0  PRI Mar 28 01:46:07.074
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.61k   56.8k   19 rs0  PRI Mar 28 01:46:12.075
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.79k   56.6k   19 rs0  PRI Mar 28 01:46:17.075
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:46:22.075
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:46:27.074
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:46:32.074
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:46:37.074
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:46:42.074
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:46:47.074
insert query update delete getmore command dirty  used flushes vsize   res qrw arw net_in net_out conn set repl                time
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:46:52.075
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:46:57.074
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:47:02.074
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       1 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:47:07.074
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:47:12.075
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.79k   56.6k   19 rs0  PRI Mar 28 01:47:17.074
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:47:22.076
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:47:27.074
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:47:32.075
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:47:37.074
insert query update delete getmore command dirty  used flushes vsize   res qrw arw net_in net_out conn set repl                time
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:47:42.074
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:47:47.073
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:47:52.075
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:47:57.074
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:48:02.075
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       1 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:48:07.074
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:48:12.074
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.79k   56.6k   19 rs0  PRI Mar 28 01:48:17.074
    *0    *0     *0     *0       0     5|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.65k   56.9k   19 rs0  PRI Mar 28 01:48:22.075
    *0    *0     *0     *0       0     4|0  0.3% 78.8%       0 5.43G 3.34G 0|0 1|0  1.74k   56.5k   19 rs0  PRI Mar 28 01:48:27.074

05

mongotop

f401f73de85541a9f099339cdbd18cae.gif

mongotop 是 db.runCommand({top: 1}) 命令的外部工具。以下是命令的演示:

[root@mongo01 ~]# mongotop --host mongo03.tyun.cn:27017 --authenticationDatabase admin -u root 5
Enter password:


2023-03-28T01:50:12.279+0000    connected to: mongodb://mongo03.tyun.cn:27017/


                       ns    total    read    write    2023-03-28T01:50:17Z
           local.oplog.rs      4ms     4ms      0ms                        
     admin.$cmd.aggregate      0ms     0ms      0ms                        
        admin.system.keys      0ms     0ms      0ms                        
     admin.system.profile      0ms     0ms      0ms                        
       admin.system.roles      0ms     0ms      0ms                        
       admin.system.users      0ms     0ms      0ms                        
     admin.system.version      0ms     0ms      0ms                        
          config.settings      0ms     0ms      0ms                        
config.system.indexBuilds      0ms     0ms      0ms                        
    config.system.profile      0ms     0ms      0ms                        


                       ns    total    read    write    2023-03-28T01:50:22Z
           local.oplog.rs      4ms     4ms      0ms                        
     admin.$cmd.aggregate      0ms     0ms      0ms                        
        admin.system.keys      0ms     0ms      0ms                        
     admin.system.profile      0ms     0ms      0ms                        
       admin.system.roles      0ms     0ms      0ms                        
       admin.system.users      0ms     0ms      0ms                        
     admin.system.version      0ms     0ms      0ms                        
          config.settings      0ms     0ms      0ms                        
config.system.indexBuilds      0ms     0ms      0ms                        
    config.system.profile      0ms     0ms      0ms                        


                       ns    total    read    write    2023-03-28T01:50:27Z
           local.oplog.rs      4ms     4ms      0ms                        
     admin.$cmd.aggregate      0ms     0ms      0ms                        
        admin.system.keys      0ms     0ms      0ms                        
     admin.system.profile      0ms     0ms      0ms                        
       admin.system.roles      0ms     0ms      0ms                        
       admin.system.users      0ms     0ms      0ms                        
     admin.system.version      0ms     0ms      0ms                        
          config.settings      0ms     0ms      0ms                        
config.system.indexBuilds      0ms     0ms      0ms                        
    config.system.profile      0ms     0ms      0ms                        


^C2023-03-28T01:50:28.048+0000    signal 'interrupt' received; forcefully terminating

监控

监控是少不了的,可以考虑从主机及服务监控两个方面来监控 MongoDB。

01

主机监控

887f1f6e103799ae62fa199ac49878e1.gif

MongoDB 所在主机的监控是不可缺少的。现在有很多成熟的监控工具,具体选用什么监控工具,可以按照自己的习惯来选择即可。

dbde6d9c6fccf92a0912ed256fd265f0.png

02

服务监控

495e499d03996818db46e80359061455.gif

服务监控更是不可缺少的。

a0ac0374ee4b794daeb23d1c564a1586.png

另外,我们对某个实例进行压测时,看看服务可以承受多大的压力,具体瓶颈在哪里,通过监控趋势图可以看得一清二楚。如:

./bin/ycsb run mongodb -s \
    -P workloads/workloada \
    -p recordcount=1000000 -p operationcount=1000000 \
    -p readproportion=0.5 -p updateproportion=0.5 \
    -p requestdistribution=zipfian \
    -p mongodb.url="mongodb://root:root123@mongo03.tyun.cn:27017/admin?waitQueueMultiple=100" \
    -threads 500

在对数据库进行压测时,可以查看监控:

e776812a8f9bd7dbb7bd20525d85ffdb.png

总结

上面我们介绍了一些列的诊断工具,可以帮助我们迅速地判断当前 MongoDB 的运行状态。通过这些诊断,就可以给 MongoDB 开出一个药方,使其更健康。

本系列文章到此结束,希望本系列文章对大家有所帮助。后续我们会有更多的话题,请大家继续关注。

    推荐阅读   

47addf29c60650bb6759734f892d0dda.png

9874d08374a295ba929c3fd6f75c5231.png

    推荐视频    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/411479.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

适合销售使用的CRM系统特点

销售人员抱怨CRM系统太复杂&#xff0c;这是一个很重要的问题。毕竟&#xff0c;如果系统太难使用&#xff0c;会导致CRM实用率和效率下降&#xff0c;最终影响公司的运作。在这篇文章中&#xff0c;我们来探讨当销售抱怨crm客户系统太复杂了&#xff0c;企业该如何解决。 缺少…

能自动翻译的软件-最精准的翻译软件

批量翻译软件是一种利用自然语言处理技术和机器学习算法&#xff0c;可以快速翻译大量文本内容的工具。批量翻译软件可以处理多种格式的文本&#xff0c;包括文档、网页、邮件、PDF等等&#xff0c;更符合掌握多语言的计算机化需求。 147CGPT翻译软件特点&#xff1a; 1.批量任…

机器学习入门实例-加州房价预测-1(数据准备与可视化)

问题描述 数据来源&#xff1a;California Housing Prices dataset from the StatLib repository&#xff0c;1990年加州的统计数据。 要求&#xff1a;预测任意一个街区的房价中位数 缩小问题&#xff1a;superwised multiple regressiong(用到人口、收入等特征) univariat…

Springboot实现优雅的参数校验(Spring Validation)和 if else说再见

文章目录一、概述二、注解2.1 空和非空检查2.2 数值检查2.3 Boolean 值检查2.4 长度检查2.5 日期检查2.6 其它检查2.7 Hibernate Validator 附加的约束注解2.8 Valid 和 Validated三、快速入门3.1 引入依赖3.2 创建基本的类3.3 启动程序&#xff0c;进行测试3.3 一些疑问3.3.1 …

抽烟行为识别预警系统 yolov5

抽烟行为识别预警系统基于yolov5网络模型智能分析技术&#xff0c;抽烟行为识别预警算法通过监测现场人员抽烟行为自动存档进行报警提示。我们选择当下YOLO卷积神经网络YOLOv5来进行抽烟识别检测。6月9日&#xff0c;Ultralytics公司开源了YOLOv5&#xff0c;离上一次YOLOv4发布…

该不该放弃嵌入式,单片机这条路?

本文几乎浓缩了我从业10几年的精华&#xff0c;内容涵盖我转行、打工、创业的经历。 建议从头到尾不要错过一字一句&#xff0c;因为字里行间的经验之谈&#xff0c;或许能成为你人生重要转折点。 全文3700多字&#xff0c;写了6个多小时&#xff0c;如果你赶时间&#xff0c;建…

MATLAB——多元函数的极值

目录 计算多元函数的自由极值 计算二元函数在区域D内的最大值和最小值 函数求偏导数的MATLAB命令 例题如下 计算多元函数的自由极值 定义多元函数 Zf(x,x)求解正规方程fx(x,y)0,fy(x,y)0 得到驻点对于每一个驻点&#xff08;x0,y0&#xff09;&#xff0c;求二阶偏导 A B …

系统复杂度之【高性能】

系统复杂度之【高性能】 今天我们来谈一谈系统复杂度的根源之【高性能】 对性能的不懈追求一直是人类科技持续发展的核心动力。例如计算机&#xff0c;从电子管计算机到晶体管计算机&#xff0c;再到集成电路计算机&#xff0c;运算性能从每秒几次提高到每秒几亿次。然而&#…

Java开发 - 读写分离初体验

前言 上一篇中&#xff0c;我们介绍了主从复制&#xff0c;相信学过的小伙伴已经能够很好的掌握主从复制的技术&#xff0c;实际上也并没有那么难&#xff0c;虽然没有讲一主多从&#xff0c;多主多从的配置&#xff0c;但是从一主一从的配置中也很容易联想到该怎么配置&#…

2023年顶级编程语言趋势

对于开发人员和软件工程师来说&#xff0c;选择更优秀的编程语言使编写可以在任何地方运行的软件变得更加容易&#xff0c;工作效率更高。从 Java 的缓慢衰落到 MATLAB 的惊人流行&#xff0c;对当今最流行的编程语言的分析&#xff0c;可以帮助你了解最新趋势并响应最新趋势。…

4.5、协议

4.5、协议1.简介2.常见协议3.UDP协议4.TCP协议5.IP协议6.以太网帧协议7.ARP协议1.简介 协议&#xff0c;网络协议的简称&#xff0c;网络协议是通信计算机双方必须共同遵从的一组约定。如怎么样建立连接、怎么样互相识别等。只有遵守这个约定&#xff0c;计算机之间才能相互通信…

JAVA NIO简解

1. 了解NIO 1.1.什么是NIO&#xff1f; Java nio是Java的一个新的输入输出&#xff08;NewInput/Output&#xff09;API&#xff0c;它提供了一些高效的数据处理方式&#xff0c;如缓冲区&#xff08;buffers&#xff09;、字符集&#xff08;charsets&#xff09;、通道&#…

No.036<软考>《(高项)备考大全》【第20章】项目集管理

【第20章】项目集管理1 考试相关2项目集合项目组合的区别2.1 项目组合、项目集、项目管理之间的关系&#xff1a;2.3 举例说三者的关系3 项目集管理3.1 项目集管理与项目管理区别3.2 项目集指导委员会3.3 项目集生命周期4 练习题参考答案1 考试相关 选择1分必考 案例概率低&am…

Ubuntu 23.04 新特性一览

Ubuntu 23.04 “Lunar Lobster” 计划于 2023 年 4 月 20 日星期四发布&#xff0c;这是 Ubuntu 桌面的第 38 个版本。作为一个短期版本&#xff0c;Ubuntu 23.04 共获得了 9 个月的持续更新、安全补丁和关键修复。 在正式发布之前&#xff0c;OMG! Ubuntu! 汇总整理了一些 Ub…

京东产发奔赴港股上市,分拆上市或成互联网大厂的共同选择?

‍数据智能产业创新服务媒体——聚焦数智 改变商业3月30日晚间&#xff0c;京东集团&#xff08;9618.HK&#xff09;相继发布2则公告称&#xff0c;拟分拆京东智能产发股份有限公司&#xff08;以下简称“京东产发”&#xff09;、京东工业股份有限公司&#xff08;以下简称“…

基于改进多目标灰狼优化算法的考虑V2G技术的风、光、荷、储微网多目标日前优化调度研究(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

( “树” 之 DFS) 404. 左叶子之和 ——【Leetcode每日一题】

404. 左叶子之和 给定二叉树的根节点 root &#xff0c;返回所有左叶子之和。 示例 1&#xff1a; 输入: root [3,9,20,null,null,15,7] 输出: 24 解释: 在这个二叉树中&#xff0c;有两个左叶子&#xff0c;分别是 9 和 15&#xff0c;所以返回 24 示例 2: 输入: root [1]…

当ChatGPT续写《红楼梦》,能替代原著吗?

来源: 清华大学出版社 近段时间&#xff0c;人工智能聊天机器人ChatGPT火爆网络&#xff0c;“AI写作是否会让文字工作者被替代&#xff1f;”成为人们关注并持续讨论的话题。 闲聊、问答、解题、写代码、写诗、创作小说&#xff0c; 连续回答&#xff0c;不断纠错&#xff0c…

window下面安装phpstudy进行PHP开发

文章目录前言在这里插入图片描述一、安装步骤1.1 下载PHPStudy软件1.2 安装PHPStudy软件1.3 启动PHPStudy软件1.4 设置PHPStudy1.5 安装扩展1.6 启动服务总结前言 php的集成开发环境比较多&#xff0c;有wamp server&#xff0c;xmapp&#xff0c;phpstudy等。经过这些年的体验…

【李宏毅】深度学习——HW5-Machine Translation

Machine Translation 1. Goal 给定一段英文&#xff0c;翻译成繁体中文 2. Introduction 2.1 Dataset training dataset TED2020: TED talks with transcriptions translated by a global community of volunteers to more than 100 language.we will use (en, zh-tw) alig…