mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Merge pull request #11680 from overleaf/em-mongo-pool-monitoring
Mongo connection pool monitoring GitOrigin-RevId: 050e50e7e67061ccbf39a710ca4532eafd423365
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import Metrics from '@overleaf/metrics'
|
||||
import Settings from '@overleaf/settings'
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
@@ -10,3 +11,5 @@ export const db = {
|
||||
messages: mongoDb.collection('messages'),
|
||||
rooms: mongoDb.collection('rooms'),
|
||||
}
|
||||
|
||||
Metrics.mongodb.monitor(mongoClient)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import Metrics from '@overleaf/metrics'
|
||||
import Settings from '@overleaf/settings'
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
export { ObjectId } from 'mongodb'
|
||||
|
||||
export const mongoClient = new MongoClient(Settings.mongo.url)
|
||||
|
||||
const mongoDb = mongoClient.db()
|
||||
|
||||
export const db = {
|
||||
contacts: mongoDb.collection('contacts'),
|
||||
}
|
||||
|
||||
Metrics.mongodb.monitor(mongoClient)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const Metrics = require('@overleaf/metrics')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { MongoClient, ObjectId } = require('mongodb')
|
||||
|
||||
@@ -9,6 +10,8 @@ const db = {
|
||||
docOps: mongoDb.collection('docOps'),
|
||||
}
|
||||
|
||||
Metrics.mongodb.monitor(mongoClient)
|
||||
|
||||
module.exports = {
|
||||
db,
|
||||
mongoClient,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const Metrics = require('@overleaf/metrics')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { MongoClient, ObjectId } = require('mongodb')
|
||||
|
||||
@@ -17,6 +18,8 @@ async function healthCheck() {
|
||||
}
|
||||
}
|
||||
|
||||
Metrics.mongodb.monitor(mongoClient)
|
||||
|
||||
module.exports = {
|
||||
db,
|
||||
ObjectId,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const Metrics = require('@overleaf/metrics')
|
||||
|
||||
const config = require('config')
|
||||
const { MongoClient } = require('mongodb')
|
||||
|
||||
@@ -9,4 +11,6 @@ const blobs = db.collection('projectHistoryBlobs')
|
||||
const globalBlobs = db.collection('projectHistoryGlobalBlobs')
|
||||
const shardedBlobs = db.collection('projectHistoryShardedBlobs')
|
||||
|
||||
Metrics.mongodb.monitor(client)
|
||||
|
||||
module.exports = { client, db, chunks, blobs, globalBlobs, shardedBlobs }
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const Metrics = require('@overleaf/metrics')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { MongoClient, ObjectId } = require('mongodb')
|
||||
|
||||
@@ -8,6 +9,8 @@ const db = {
|
||||
notifications: mongoDb.collection('notifications'),
|
||||
}
|
||||
|
||||
Metrics.mongodb.monitor(mongoClient)
|
||||
|
||||
module.exports = {
|
||||
db,
|
||||
mongoClient,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import Metrics from '@overleaf/metrics'
|
||||
import Settings from '@overleaf/settings'
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
@@ -6,6 +7,8 @@ export { ObjectId } from 'mongodb'
|
||||
export const mongoClient = new MongoClient(Settings.mongo.url)
|
||||
const mongoDb = mongoClient.db()
|
||||
|
||||
Metrics.mongodb.monitor(mongoClient)
|
||||
|
||||
export const db = {
|
||||
deletedProjects: mongoDb.collection('deletedProjects'),
|
||||
projects: mongoDb.collection('projects'),
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
const Metrics = require('@overleaf/metrics')
|
||||
const { ObjectId } = require('mongodb')
|
||||
const OError = require('@overleaf/o-error')
|
||||
const {
|
||||
addOptionalCleanupHandlerAfterDrainingConnections,
|
||||
} = require('./GracefulShutdown')
|
||||
const { getNativeDb } = require('./Mongoose')
|
||||
|
||||
if (
|
||||
@@ -26,7 +23,7 @@ async function waitForDb() {
|
||||
const db = {}
|
||||
async function setupDb() {
|
||||
const internalDb = await getNativeDb()
|
||||
collectStatsForDb(internalDb, 'shared')
|
||||
Metrics.mongodb.monitor(internalDb)
|
||||
|
||||
db.contacts = internalDb.collection('contacts')
|
||||
db.deletedFiles = internalDb.collection('deletedFiles')
|
||||
@@ -110,34 +107,6 @@ async function getCollectionInternal(name) {
|
||||
return internalDb.collection(name)
|
||||
}
|
||||
|
||||
function collectStatsForDb(internalDb, label) {
|
||||
const collectOnce = () => {
|
||||
for (const [name, server] of internalDb.s.topology.s.servers.entries()) {
|
||||
const { availableConnectionCount, waitQueueSize } = server.s.pool
|
||||
const { maxPoolSize } = server.s.pool.options
|
||||
const opts = { status: `${label}:${name}` }
|
||||
Metrics.gauge('mongo_connection_pool_max', maxPoolSize, 1, opts)
|
||||
Metrics.gauge(
|
||||
'mongo_connection_pool_available',
|
||||
availableConnectionCount,
|
||||
1,
|
||||
opts
|
||||
)
|
||||
Metrics.gauge('mongo_connection_pool_waiting', waitQueueSize, 1, opts)
|
||||
}
|
||||
}
|
||||
collectOnce() // init metrics
|
||||
const intervalHandle = setInterval(collectOnce, 60_000)
|
||||
addOptionalCleanupHandlerAfterDrainingConnections(
|
||||
`collect mongo connection pool metrics (${label})`,
|
||||
() => {
|
||||
clearInterval(intervalHandle)
|
||||
// collect one more time.
|
||||
collectOnce()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
db,
|
||||
ObjectId,
|
||||
@@ -145,5 +114,4 @@ module.exports = {
|
||||
getCollectionInternal,
|
||||
dropTestDatabase,
|
||||
waitForDb,
|
||||
collectStatsForDb,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user