feat: log memory usage with DEBUG_MEMORY_LOG

This commit is contained in:
diced
2025-10-27 15:01:19 -07:00
parent 2402c6f0ef
commit 2a6f1f418a
2 changed files with 21 additions and 2 deletions

3
.gitignore vendored
View File

@@ -48,4 +48,5 @@ yarn-error.log*
uploads*/
*.crt
*.key
src/prisma
src/prisma
.memory.log.json

View File

@@ -20,7 +20,7 @@ import { fastifyRateLimit } from '@fastify/rate-limit';
import { fastifySensible } from '@fastify/sensible';
import { fastifyStatic } from '@fastify/static';
import fastify from 'fastify';
import { mkdir, readFile } from 'fs/promises';
import { appendFile, mkdir, readFile, writeFile } from 'fs/promises';
import ms, { StringValue } from 'ms';
import { version } from '../../package.json';
import { checkRateLimit } from './plugins/checkRateLimit';
@@ -284,6 +284,24 @@ async function main() {
}
tasks.start();
if (process.env.DEBUG_MONITOR_MEMORY === 'true') {
await writeFile('.memory.log.json', '', 'utf8');
setInterval(async () => {
const mu = process.memoryUsage();
const cpu = process.cpuUsage();
const entry = {
timestamp: new Date().toISOString(),
data: {
memoryUsage: mu,
cpuUsage: cpu,
},
};
await appendFile('.memory.log.json', JSON.stringify(entry) + '\n', 'utf8');
}, 1000);
}
}
main();