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:
David
2024-02-22 11:03:27 +00:00
committed by Copybot
parent 10e7be0a69
commit b59326e96f
14 changed files with 66 additions and 8 deletions

View File

@@ -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