要获取打开的连接数,请serverStatus()
在MongoDB中使用。以下是查询-
> db.serverStatus();
这将产生以下输出-
{ "host" : "DESKTOP-QN2RB3H", "version" : "4.0.5", "process" : "mongod", "pid" : NumberLong(10540), "uptime" : 74156, "uptimeMillis" : NumberLong(74156688), "uptimeEstimate" : NumberLong(74156), "localTime" : ISODate("2020-01-07T15:09:18.366Z"), "asserts" : { "regular" : 0, "warning" : 0, "msg" : 0, "user" : 1, "rollovers" : 0 }, "connections" : { "current" : 1, "available" : 999999, "totalCreated" : 1 }, "extra_info" : { "note" : "fields vary by platform", "page_faults" : 64557, "usagePageFileMB" : 196, "totalPageFileMB" : 11787, "availPageFileMB" : 7408, "ramMB" : 10187 }, "freeMonitoring" : { "state" : "undecided" }, "globalLock" : { "totalTime" : NumberLong("74156586000"), "currentQueue" : { "total" : 0, "readers" : 0, "writers" : 0 }, "activeClients" : { "total" : 12, "readers" : 0, "writers" : 0 } }, "locks" : { "Global" : { "acquireCount" : { "r" : NumberLong(2048526), "w" : NumberLong(857), "W" : NumberLong(5) } }, "Database" : { "acquireCount" : { "r" : NumberLong(1021070), "w" : NumberLong(133), "R" : NumberLong(14), "W" : NumberLong(724) }, "acquireWaitCount" : { "r" : NumberLong(1) }, "timeAcquiringMicros" : { "r" : NumberLong(89245) } }, "Collection" : { "acquireCount" : { "r" : NumberLong(1021070), "w" : NumberLong(133) } } }, "logicalSessionRecordCache" : { "activeSessionsCount" : 1, "sessionsCollectionJobCount" : 19, "lastSessionsCollectionJobDurationMillis" : 31, "lastSessionsCollectionJobTimestamp" : ISODate("2020-01-07T15:06:21.428Z"), "lastSessionsCollectionJobEntriesRefreshed" : 0, "lastSessionsCollectionJobEntriesEnded" : 0, "lastSessionsCollectionJobCursorsClosed" : 0, "transactionReaperJobCount" : 0, "lastTransactionReaperJobDurationMillis" : 0, "lastTransactionReaperJobTimestamp" : ISODate("2020-01-06T18:35:28.091Z"), "lastTransactionReaperJobEntriesCleanedUp" : 0 }, "network" : { "bytesIn" : NumberLong(20054), "bytesOut" : NumberLong(39842), "physicalBytesIn" : NumberLong(20054), "physicalBytesOut" : NumberLong(39842), "numRequests" : NumberLong(187), "compression" : { "snappy" : { "compressor" : { "bytesIn" : NumberLong(0), "bytesOut" : NumberLong(0) }, "decompressor" : { "bytesIn" : NumberLong(0), "bytesOut" : NumberLong(0) } } }, "serviceExecutorTaskStats" : { "executor" : "passthrough", "threadsRunning" : 1 } }, "opLatencies" : { "reads" : { "latency" : NumberLong(67492), "ops" : NumberLong(27) }, "writes" : { "latency" : NumberLong(2513055), "ops" : NumberLong(23) }, "commands" : { "latency" : NumberLong(248101), "ops" : NumberLong(136) }, "transactions" : { "latency" : NumberLong(0), "ops" : NumberLong(0) } }, "opcounters" : { "insert" : 13, "query" : 24, "update" : 20, "delete" : 0, "getmore" : 0, "command" : 160 }, "opcountersRepl" : { "insert" : 0, "query" : 0, "update" : 0, "delete" : 0, "getmore" : 0, "command" : 0 }, "storageEngine" : { "name" : "wiredTiger", "supportsCommittedReads" : true, "supportsSnapshotReadConcern" : true, "readOnly" : false, "persistent" : true }, "tcmalloc" : { "generic" : { "current_allocated_bytes" : 93839200, "heap_size" : 94830592 }, "tcmalloc" : { "pageheap_free_bytes" : 327680, "pageheap_unmapped_bytes" : 0, "max_total_thread_cache_bytes" : NumberLong(1073741824), "current_total_thread_cache_bytes" : 424912, "total_free_bytes" : 663712, "central_cache_free_bytes" : 238800, "transfer_cache_free_bytes" : 0, "thread_cache_free_bytes" : 424912, "aggressive_memory_decommit" : 0, "pageheap_committed_bytes" : 94830592, "pageheap_scavenge_count" : 0, "pageheap_commit_count" : 69, "pageheap_total_commit_bytes" : 94830592, "pageheap_decommit_count" : 0, "pageheap_total_decommit_bytes" : 0, "pageheap_reserve_count" : 69, "pageheap_total_reserve_bytes" : 94830592, "spinlock_total_delay_ns" : 0, "formattedString" : "------------------------------------------------\nMALLOC: 93839200 ( 89.5 MiB) Bytes in use by application\nMALLOC: + 327680 ( 0.3 MiB) Bytes in page heap freelist\nMALLOC: + 238800 ( 0.2 MiB) Bytes in central cache freelist\nMALLOC: + 0 ( 0.0 MiB) Bytes in transfer cache freelist\nMALLOC: + 424912 ( 0.4 MiB) Bytes in thread cache freelists\nMALLOC: + 6316248 ( 6.0 MiB) Bytes in malloc metadata\nMALLOC: ------------\nMALLOC: = 101146840 ( 96.5 MiB) Actual memory used (physical + swap)\nMALLOC: + 0 ( 0.0 MiB) Bytes released to OS (aka unmapped)\nMALLOC: ------------ \nMALLOC: = 101146840 ( 96.5 MiB) Virtual address space used\nMALLOC:\nMALLOC: 2167 Spans in use\nMALLOC: 10 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" } }, "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) }, "transportSecurity" : { "1.0" : NumberLong(0), "1.1" : NumberLong(0), "1.2" : NumberLong(0), "1.3" : NumberLong(0), "unknown" : NumberLong(0) }, "wiredTiger" : { "uri" : "statistics:", "LSM" : { "application work units currently queued" : 0, "merge work units currently queued" : 0, "rows merged in an LSM tree" : 0, "sleep for LSM checkpoint throttle" : 0, "sleep for LSM merge throttle" : 0, "switch work units currently queued" : 0, "tree maintenance operations discarded" : 0, "tree maintenance operations executed" : 0, "tree maintenance operations scheduled" : 0, "tree queue hit maximum" : 0 }, "async" : { "current work queue length" : 0, "maximum work queue length" : 0, "number of allocation state races" : 0, "number of flush calls" : 0, "number of operation slots viewed for allocation" : 0, "number of times operation allocation failed" : 0, "number of times worker found no work" : 0, "total allocations" : 0, "total compact calls" : 0, "total insert calls" : 0, "total remove calls" : 0, "total search calls" : 0, "total update calls" : 0 }, "block-manager" : { "blocks pre-loaded" : 796, "blocks read" : 1978, "blocks written" : 525, "bytes read" : 10067968, "bytes written" : 5468160, "bytes written for checkpoint" : 5468160, "mapped blocks read" : 0, "mapped bytes read" : 0 }, "cache" : { "application threads page read from disk to cache count" : 721, "application threads page read from disk to cache time (usecs)" : 297604, "application threads page write from cache to disk count" : 309, "application threads page write from cache to disk time (usecs)" : 67973, "bytes belonging to page images in the cache" : 3010020, "bytes belonging to the cache overflow table in the cache" : 182, "bytes currently in the cache" : 3487169, "bytes dirty in the cache cumulative" : 6037950, "bytes not belonging to page images in the cache" : 477149, "bytes read into cache" : 2787109, "bytes written from cache" : 3880089, "cache overflow cursor application thread wait time (usecs)" : 0, "cache overflow cursor internal thread wait time (usecs)" : 0, "cache overflow score" : 0, "cache overflow table entries" : 0, "cache overflow table insert calls" : 0, "cache overflow table remove calls" : 0, "checkpoint blocked page eviction" : 0, "eviction calls to get a page" : 559, "eviction calls to get a page found queue empty" : 562, "eviction calls to get a page found queue empty after locking" : 0, "eviction currently operating in aggressive mode" : 0, "eviction empty score" : 0, "eviction passes of a file" : 0, "eviction server candidate queue empty when topping up" : 0, "eviction server candidate queue not empty when topping up" : 0, "eviction server evicting pages" : 0, "eviction server slept, because we did not make progress with eviction" : 328, "eviction server unable to reach eviction goal" : 0, "eviction state" : 32, "eviction walk target pages histogram - 0-9" : 0, "eviction walk target pages histogram - 10-31" : 0, "eviction walk target pages histogram - 128 and higher" : 0, "eviction walk target pages histogram - 32-63" : 0, "eviction walk target pages histogram - 64-128" : 0, "eviction walks abandoned" : 0, "eviction walks gave up because they restarted their walk twice" : 0, "eviction walks gave up because they saw too many pages and found no candidates" : 0, "eviction walks gave up because they saw too many pages and found too few candidates" : 0, "eviction walks reached end of tree" : 0, "eviction walks started from root of tree" : 0, "eviction walks started from saved location in tree" : 0, "eviction worker thread active" : 4, "eviction worker thread created" : 0, "eviction worker thread evicting pages" : 3, "eviction worker thread removed" : 0, "eviction worker thread stable number" : 0, "failed eviction of pages that exceeded the in-memory maximum count" : 0, "failed eviction of pages that exceeded the in-memory maximum time (usecs)" : 0, "files with active eviction walks" : 0, "files with new eviction walks started" : 0, "force re-tuning of eviction workers once in a while" : 0, "hazard pointer blocked page eviction" : 1, "hazard pointer check calls" : 3, "hazard pointer check entries walked" : 1, "hazard pointer maximum array length" : 1, "in-memory page passed criteria to be split" : 0, "in-memory page splits" : 0, "internal pages evicted" : 0, "internal pages split during eviction" : 0, "leaf pages split during eviction" : 0, "maximum bytes configured" : 4803526656, "maximum page size at eviction" : 0, "modified pages evicted" : 2, "modified pages evicted by application threads" : 0, "operations timed out waiting for space in cache" : 0, "overflow pages read into cache" : 0, "page split during eviction deepened the tree" : 0, "page written requiring cache overflow records" : 0, "pages currently held in the cache" : 1530, "pages evicted because they exceeded the in-memory maximum count" : 0, "pages evicted because they exceeded the in-memory maximum time (usecs)" : 0, "pages evicted because they had chains of deleted items count" : 0, "pages evicted because they had chains of deleted items time (usecs)" : 0, "pages evicted by application threads" : 0, "pages queued for eviction" : 0, "pages queued for urgent eviction" : 3, "pages queued for urgent eviction during walk" : 0, "pages read into cache" : 1470, "pages read into cache after truncate" : 16, "pages read into cache after truncate in prepare state" : 0, "pages read into cache requiring cache overflow entries" : 0, "pages read into cache requiring cache overflow for checkpoint" : 0, "pages read into cache skipping older cache overflow entries" : 0, "pages read into cache with skipped cache overflow entries needed later" : 0, "pages read into cache with skipped cache overflow entries needed later by checkpoint" : 0, "pages requested from the cache" : 174351, "pages seen by eviction walk" : 0, "pages selected for eviction unable to be evicted" : 1, "pages walked for eviction" : 0, "pages written from cache" : 311, "pages written requiring in-memory restoration" : 0, "percentage overhead" : 8, "tracked bytes belonging to internal pages in the cache" : 166860, "tracked bytes belonging to leaf pages in the cache" : 3320309, "tracked dirty bytes in the cache" : 0, "tracked dirty pages in the cache" : 0, "unmodified pages evicted" : 0 }, "connection" : { "auto adjusting condition resets" : 481, "auto adjusting condition wait calls" : 35030, "detected system time went backwards" : 0, "files currently open" : 733, "memory allocations" : 644375, "memory frees" : 595480, "memory re-allocations" : 33215, "pthread mutex condition wait calls" : 95247, "pthread mutex shared lock read-lock calls" : 387569, "pthread mutex shared lock write-lock calls" : 18224, "total fsync I/Os" : 1993, "total read I/Os" : 3742, "total write I/Os" : 2300 }, "cursor" : { "cursor close calls that result in cache" : 1063, "cursor create calls" : 2283, "cursor insert calls" : 953, "cursor modify calls" : 0, "cursor next calls" : 13290, "cursor operation restarted" : 0, "cursor prev calls" : 738, "cursor remove calls" : 30, "cursor reserve calls" : 0, "cursor reset calls" : 170778, "cursor search calls" : 103081, "cursor search near calls" : 1571, "cursor sweep buckets" : 33689, "cursor sweep cursors closed" : 5, "cursor sweep cursors examined" : 1731, "cursor sweeps" : 5614, "cursor update calls" : 0, "cursors currently cached" : 740, "cursors reused from cache" : 318, "truncate calls" : 0 }, "data-handle" : { "connection data handles currently active" : 2200, "connection sweep candidate became referenced" : 0, "connection sweep dhandles closed" : 4, "connection sweep dhandles removed from hash list" : 821, "connection sweep time-of-death sets" : 3286, "connection sweeps" : 2843, "session dhandles swept" : 5, "session sweep attempts" : 1560 }, "lock" : { "checkpoint lock acquisitions" : 1568, "checkpoint lock application thread wait time (usecs)" : 237424, "checkpoint lock internal thread wait time (usecs)" : 0, "commit timestamp queue lock application thread time waiting (usecs)" : 0, "commit timestamp queue lock internal thread time waiting (usecs)" : 0, "commit timestamp queue read lock acquisitions" : 0, "commit timestamp queue write lock acquisitions" : 0, "dhandle lock application thread time waiting (usecs)" : 0, "dhandle lock internal thread time waiting (usecs)" : 995, "dhandle read lock acquisitions" : 23462, "dhandle write lock acquisitions" : 3860, "metadata lock acquisitions" : 95, "metadata lock application thread wait time (usecs)" : 0, "metadata lock internal thread wait time (usecs)" : 0, "read timestamp queue lock application thread time waiting (usecs)" : 0, "read timestamp queue lock internal thread time waiting (usecs)" : 0, "read timestamp queue read lock acquisitions" : 0, "read timestamp queue write lock acquisitions" : 0, "schema lock acquisitions" : 2323, "schema lock application thread wait time (usecs)" : 26952, "schema lock internal thread wait time (usecs)" : 0, "table lock application thread time waiting for the table lock (usecs)" : 0, "table lock internal thread time waiting for the table lock (usecs)" : 0, "table read lock acquisitions" : 0, "table write lock acquisitions" : 2957, "txn global lock application thread time waiting (usecs)" : 0, "txn global lock internal thread time waiting (usecs)" : 0, "txn global read lock acquisitions" : 625, "txn global write lock acquisitions" : 323 }, "log" : { "busy returns attempting to switch slots" : 0, "force archive time sleeping (usecs)" : 0, "log bytes of payload data" : 107056, "log bytes written" : 294656, "log files manually zero-filled" : 0, "log flush operations" : 55995, "log force write operations" : 61866, "log force write operations skipped" : 61677, "log records compressed" : 64, "log records not compressed" : 57, "log records too small to compress" : 1663, "log release advances write LSN" : 1530, "log scan operations" : 4, "log scan records requiring two reads" : 3, "log server thread advances write LSN" : 189, "log server thread write LSN walk skipped" : 6435, "log sync operations" : 1719, "log sync time duration (usecs)" : 91313877, "log sync_dir operations" : 1, "log sync_dir time duration (usecs)" : 0, "log write operations" : 1784, "logging bytes consolidated" : 294144, "maximum log file size" : 104857600, "number of pre-allocated log files to create" : 2, "pre-allocated log files not ready and missed" : 1, "pre-allocated log files prepared" : 2, "pre-allocated log files used" : 0, "records processed by log scan" : 58, "slot close lost race" : 0, "slot close unbuffered waits" : 0, "slot closures" : 1719, "slot join atomic update races" : 0, "slot join calls atomic updates raced" : 0, "slot join calls did not yield" : 1784, "slot join calls found active slot closed" : 0, "slot join calls slept" : 0, "slot join calls yielded" : 0, "slot join found active slot closed" : 0, "slot joins yield time (usecs)" : 0, "slot transitions unable to find free slot" : 0, "slot unbuffered writes" : 0, "total in-memory size of compressed records" : 169499, "total log buffer size" : 33554432, "total size of compressed records" : 62513, "written slots coalesced" : 0, "yields waiting for previous log file close" : 0 }, "perf" : { "file system read latency histogram (bucket 1) - 10-49ms" : 4, "file system read latency histogram (bucket 2) - 50-99ms" : 0, "file system read latency histogram (bucket 3) - 100-249ms" : 4, "file system read latency histogram (bucket 4) - 250-499ms" : 1, "file system read latency histogram (bucket 5) - 500-999ms" : 0, "file system read latency histogram (bucket 6) - 1000ms+" : 0, "file system write latency histogram (bucket 1) - 10-49ms" : 13, "file system write latency histogram (bucket 2) - 50-99ms" : 0, "file system write latency histogram (bucket 3) - 100-249ms" : 0, "file system write latency histogram (bucket 4) - 250-499ms" : 0, "file system write latency histogram (bucket 5) - 500-999ms" : 0, "file system write latency histogram (bucket 6) - 1000ms+" : 0, "operation read latency histogram (bucket 1) - 100-249us" : 0, "operation read latency histogram (bucket 2) - 250-499us" : 0, "operation read latency histogram (bucket 3) - 500-999us" : 198, "operation read latency histogram (bucket 4) - 1000-9999us" : 69, "operation read latency histogram (bucket 5) - 10000us+" : 2, "operation write latency histogram (bucket 1) - 100-249us" : 0, "operation write latency histogram (bucket 2) - 250-499us" : 0, "operation write latency histogram (bucket 3) - 500-999us" : 7, "operation write latency histogram (bucket 4) - 1000-9999us" : 7, "operation write latency histogram (bucket 5) - 10000us+" : 0 }, "reconciliation" : { "fast-path pages deleted" : 0, "page reconciliation calls" : 327, "page reconciliation calls for eviction" : 1, "pages deleted" : 16, "split bytes currently awaiting free" : 0, "split objects currently awaiting free" : 0 }, "session" : { "open cursor count" : 22, "open session count" : 19, "session query timestamp calls" : 0, "table alter failed calls" : 0, "table alter successful calls" : 1473, "table alter unchanged and skipped" : 4419, "table compact failed calls" : 0, "table compact successful calls" : 0, "table create failed calls" : 0, "table create successful calls" : 15, "table drop failed calls" : 0, "table drop successful calls" : 4, "table rebalance failed calls" : 0, "table rebalance successful calls" : 0, "table rename failed calls" : 0, "table rename successful calls" : 0, "table salvage failed calls" : 0, "table salvage successful calls" : 0, "table truncate failed calls" : 0, "table truncate successful calls" : 0, "table verify failed calls" : 0, "table verify successful calls" : 0 }, "thread-state" : { "active filesystem fsync calls" : 0, "active filesystem read calls" : 0, "active filesystem write calls" : 0 }, "thread-yield" : { "application thread time evicting (usecs)" : 0, "application thread time waiting for cache (usecs)" : 0, "connection close blocked waiting for transaction state stabilization" : 0, "connection close yielded for lsm manager shutdown" : 0, "data handle lock yielded" : 0, "get reference for page index and slot time sleeping (usecs)" : 0, "log server sync yielded for log write" : 0, "page access yielded due to prepare state change" : 0, "page acquire busy blocked" : 0, "page acquire eviction blocked" : 0, "page acquire locked blocked" : 0, "page acquire read blocked" : 0, "page acquire time sleeping (usecs)" : 0, "page delete rollback time sleeping for state change (usecs)" : 0, "page reconciliation yielded due to child modification" : 0 }, "transaction" : { "Number of prepared updates" : 0, "Number of prepared updates added to cache overflow" : 0, "Number of prepared updates resolved" : 0, "commit timestamp queue entries walked" : 0, "commit timestamp queue insert to empty" : 0, "commit timestamp queue inserts to head" : 0, "commit timestamp queue inserts total" : 0, "commit timestamp queue length" : 0, "number of named snapshots created" : 0, "number of named snapshots dropped" : 0, "prepared transactions" : 0, "prepared transactions committed" : 0, "prepared transactions currently active" : 0, "prepared transactions rolled back" : 0, "query timestamp calls" : 1, "read timestamp queue entries walked" : 0, "read timestamp queue insert to empty" : 0, "read timestamp queue inserts to head" : 0, "read timestamp queue inserts total" : 0, "read timestamp queue length" : 0, "rollback to stable calls" : 0, "rollback to stable updates aborted" : 0, "rollback to stable updates removed from cache overflow" : 0, "set timestamp calls" : 0, "set timestamp commit calls" : 0, "set timestamp commit updates" : 0, "set timestamp oldest calls" : 0, "set timestamp oldest updates" : 0, "set timestamp stable calls" : 0, "set timestamp stable updates" : 0, "transaction begins" : 323, "transaction checkpoint currently running" : 0, "transaction checkpoint generation" : 96, "transaction checkpoint max time (msecs)" : 7169, "transaction checkpoint min time (msecs)" : 17, "transaction checkpoint most recent time (msecs)" : 121, "transaction checkpoint scrub dirty target" : 0, "transaction checkpoint scrub time (msecs)" : 0, "transaction checkpoint total time (msecs)" : 27505, "transaction checkpoints" : 95, "transaction checkpoints skipped because database was clean" : 0, "transaction failures due to cache overflow" : 0, "transaction fsync calls for checkpoint after allocating the transaction ID" : 95, "transaction fsync duration for checkpoint after allocating the transaction ID (usecs)" : 0, "transaction range of IDs currently pinned" : 0, "transaction range of IDs currently pinned by a checkpoint" : 0, "transaction range of IDs currently pinned by named snapshots" : 0, "transaction range of timestamps currently pinned" : 0, "transaction range of timestamps pinned by a checkpoint" : 0, "transaction range of timestamps pinned by the oldest timestamp" : 0, "transaction sync calls" : 0, "transactions committed" : 68, "transactions rolled back" : 255, "update conflicts" : 0 }, "concurrentTransactions" : { "write" : { "out" : 0, "available" : 128, "totalTickets" : 128 }, "read" : { "out" : 1, "available" : 127, "totalTickets" : 128 } } }, "mem" : { "bits" : 64, "resident" : 128, "virtual" : 5125, "supported" : true, "mapped" : 0, "mappedWithJournal" : 0 }, "metrics" : { "commands" : { "aggregate" : { "failed" : NumberLong(0), "total" : NumberLong(4) }, "buildInfo" : { "failed" : NumberLong(0), "total" : NumberLong(2) }, "drop" : { "failed" : NumberLong(0), "total" : NumberLong(2) }, "find" : { "failed" : NumberLong(0), "total" : NumberLong(24) }, "getFreeMonitoringStatus" : { "failed" : NumberLong(0), "total" : NumberLong(1) }, "getLog" : { "failed" : NumberLong(0), "total" : NumberLong(1) }, "insert" : { &