generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(condo): DOMA-9803 try to monitor memory usage during lifetime (#…
…5081) * chore(condo): DOMA-9803 try to monitor memory usage during lifetime * chore(condo): DOMA-9803 add some gql data
- Loading branch information
1 parent
7e5211c
commit 0841eab
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const cuid = require('cuid') | ||
const { get } = require('lodash') | ||
|
||
const { logger } = require('./utils') | ||
|
||
/** @implements {import('apollo-server-plugin-base').ApolloServerPlugin} */ | ||
class ApolloMemMonPlugin { | ||
|
||
requestDidStart () { | ||
return { | ||
didResolveOperation: async (requestContext) => { | ||
const operationId = get(requestContext, 'operationId') || cuid() | ||
const mem = process.memoryUsage() | ||
const operationName = get(requestContext, ['request', 'operationName']) | ||
const query = get(requestContext, ['request', 'query']) | ||
const variables = get(requestContext, ['request', 'variables']) | ||
|
||
requestContext.operationId = operationId | ||
|
||
logger.info({ msg: 'beforeQuery', operationId, operationName, query, variables, data: { mem } }) | ||
}, | ||
willSendResponse: async (requestContext) => { | ||
const mem = process.memoryUsage() | ||
const operationName = get(requestContext, ['request', 'operationName']) | ||
|
||
logger.info({ msg: 'afterQuery', operationId: requestContext.operationId, operationName, data: { mem } }) | ||
}, | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
ApolloMemMonPlugin, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const process = require('node:process') | ||
const { PerformanceObserver } = require('perf_hooks') | ||
|
||
const { getLogger } = require('@open-condo/keystone/logging') | ||
|
||
const logger = getLogger('memMon') | ||
|
||
function isMemMonEnabled () { | ||
return !process.env['DISABLE_MEM_MON'] | ||
} | ||
|
||
function catchGC () { | ||
const obs = new PerformanceObserver((list) => { | ||
const entries = list.getEntries() | ||
const mem = process.memoryUsage() | ||
|
||
logger.info({ msg: 'afterGC', data: { mem, entriesCount: entries.length, entries } }) | ||
}) | ||
|
||
obs.observe({ entryTypes: ['gc'], buffered: true }) | ||
} | ||
|
||
module.exports = { isMemMonEnabled, catchGC, logger } |