mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Merge pull request #16873 from overleaf/dp-mongo-command-monitoring
Use mongo command monitoring to add timing metrics GitOrigin-RevId: e7e5dd5cca1ba3802c02198ccf81058d4da3f1e7
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { Gauge } = require('prom-client')
|
||||
const { Gauge, Summary } = require('prom-client')
|
||||
|
||||
function monitor(mongoClient) {
|
||||
const labelNames = ['mongo_server']
|
||||
@@ -25,6 +25,35 @@ function monitor(mongoClient) {
|
||||
labelNames,
|
||||
})
|
||||
|
||||
const mongoCommandTimer = new Summary({
|
||||
name: 'mongo_command_time',
|
||||
help: 'time taken to complete a mongo command',
|
||||
percentiles: [],
|
||||
labelNames: ['status', 'method'],
|
||||
})
|
||||
|
||||
if (mongoClient.on) {
|
||||
mongoClient.on('commandSucceeded', event => {
|
||||
mongoCommandTimer.observe(
|
||||
{
|
||||
status: 'success',
|
||||
method: event.commandName === 'find' ? 'read' : 'write',
|
||||
},
|
||||
event.duration
|
||||
)
|
||||
})
|
||||
|
||||
mongoClient.on('commandFailed', event => {
|
||||
mongoCommandTimer.observe(
|
||||
{
|
||||
status: 'failed',
|
||||
method: event.commandName === 'find' ? 'read' : 'write',
|
||||
},
|
||||
event.duration
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function collect() {
|
||||
// Reset all gauges in case they contain values for servers that
|
||||
// disappeared
|
||||
|
||||
Reference in New Issue
Block a user