mirror of
https://github.com/System-End/slack-end.git
synced 2026-04-19 16:28:19 +00:00
feat: test alert cpu
This commit is contained in:
parent
8139af2a3c
commit
960bc2fad9
3 changed files with 30 additions and 5 deletions
|
|
@ -35,7 +35,8 @@
|
|||
"smee-client": "^2.0.3",
|
||||
"socket.io": "^4.8.1",
|
||||
"stegcloak": "^1.1.1",
|
||||
"ws": "^8.18.0"
|
||||
"ws": "^8.18.0",
|
||||
"pidusage": "latest"
|
||||
},
|
||||
"optionalDependencies": {},
|
||||
"devDependencies": {
|
||||
|
|
@ -44,4 +45,4 @@
|
|||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.5.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import * as utils from "./modules/index";
|
|||
import { resetSpotifyCache } from "./modules/howWasYourDay";
|
||||
import { PrivateDNS } from "./modules/nextdns";
|
||||
import { attachDB } from "./modules/projectWaterydo";
|
||||
|
||||
import monitorMemCpu from "./modules/alertcpu"
|
||||
import { watchForWhenIUseHacktime } from "./modules/hacktime";
|
||||
|
||||
import { EncryptedJsonDb } from "./modules/encrypted-db";
|
||||
|
|
@ -111,8 +111,8 @@ app.start(process.env.PORT || 3000).then(async (d) => {
|
|||
text: `Starting Slack Bot :D`,
|
||||
});
|
||||
init(app);
|
||||
PrivateDNS(app, process.env.MY_NEXTDNS, `C07LT7XS28Z`);
|
||||
PrivateDNS(app, process.env.HACKCLUB_NEXTDNS, `C07TWGJKK98`);
|
||||
PrivateDNS(app, process.env.MY_NEXTDNS, `C07LT7XS28Z`);
|
||||
monitorMemCpu()
|
||||
// grab spotify cache from db
|
||||
resetSpotifyCache(app);
|
||||
app.client.chat.postMessage({
|
||||
|
|
|
|||
24
src/modules/alertcpu.ts
Normal file
24
src/modules/alertcpu.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { ModifiedApp } from "./slackapp";
|
||||
import pidusage from "pidusage"
|
||||
const THRESHOLD_CPU = 80; // In percentage
|
||||
const THRESHOLD_MEM = 700 * 1024 * 1024; // 700MB
|
||||
export default function monitorMemCpu(app: ModifiedApp) {
|
||||
setInterval(() => {
|
||||
pidusage(process.pid, (err, stats) => {
|
||||
if (stats.cpu > THRESHOLD_CPU) {
|
||||
console.warn(`⚠️ High CPU: ${stats.cpu}%`);
|
||||
app.client.chat.postMessage({
|
||||
channel: `C07LEEB50KD`,
|
||||
text: `⚠️ High CPU: ${stats.cpu}%`
|
||||
})
|
||||
}
|
||||
if (stats.memory > THRESHOLD_MEM) {
|
||||
console.warn(`⚠️ High Memory: ${(stats.memory / 1024 / 1024).toFixed(2)} MB`);
|
||||
app.client.chat.postMessage({
|
||||
channel: `C07LEEB50KD`,
|
||||
text: `⚠️ High Memory: ${(stats.memory / 1024 / 1024).toFixed(2)} MB`
|
||||
})
|
||||
}
|
||||
});
|
||||
}, 3000);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue