fix: debug + mem stats

This commit is contained in:
Saahil 2025-01-04 23:16:07 -05:00
parent 9e14394482
commit 8f35aa792c
No known key found for this signature in database
GPG key ID: 8A8B64515254CFC6
4 changed files with 22 additions and 1 deletions

View file

@ -30,6 +30,9 @@
"stegcloak": "^1.1.1",
"ws": "^8.18.0"
},
"optionalDependencies": {
"memwatch-next": "latest"
},
"devDependencies": {
"@types/node": "^22.7.4",
"canvas": "^2.11.2",

View file

@ -23,6 +23,7 @@ import { watchForWhenIUseHacktime } from "./modules/hacktime";
import { EncryptedJsonDb } from "./modules/encrypted-db";
import { setupOverallCron } from "./modules/cron";
import watchMem from "./modules/memwatch";
const db = new JSONdb("data/data.json");
app.dbs = {};
@ -34,6 +35,7 @@ app.dbs.anondm = new EncryptedJsonDb("data/anondm.json", {
app.dbs.tags = new JSONdb("data/tags.json");
app.dbs.stickymessages = new JSONdb("data/stickymessages.json");
attachDB(db);
watchMem(app)
app.start(process.env.PORT || 3000).then(async (d) => {
console.log(`App is UP (please help)`);
watchForWhenIUseHacktime(app);

16
src/modules/memwatch.ts Normal file
View file

@ -0,0 +1,16 @@
import memwatch from "memwatch-next"
import { ModifiedApp } from "./slackapp";
export default function watchMem(app:ModifiedApp) {
memwatch.on('leak', (info) => {
app.client.chat.postMessage({
text: `:x: my memory is leaking plz kill me :3\n\`\`\`\n${JSON.stringify(info, null, 2)}\n\`\`\``,
channel: `C07LGLUTNH2`
})
});
memwatch.on('stats', function(stats) {
app.client.chat.postMessage({
text: `debug: mem stats ;3 \n\`\`\`\n${JSON.stringify(stats, null, 2)}\n\`\`\``,
channel: `C07LGLUTNH2`
})
});
}

View file

@ -248,7 +248,7 @@ export function setupCronForShipments(app: ModifiedApp) {
);
} catch (e) {
// coulda failed parsing or diff..
console.error(e, `shipment viewer`);
console.error(e, `shipment viewer`, userURLID);
}
}
}