Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/.nvm/versions/node/v18.17.1/lib/node_modules/pm2/node_modules/pm2-sysmonit/src/ drwxr-xr-x |
Viewing file: Select action/file-type: const fs = require('fs') const path = require('path') const pidusage = require('pidusage') class PM2Monitoring { constructor() { this.pm2_monitoring = { cpu: 0, mem: 0 } this.pm2_agent_monitoring = { cpu: 0, mem: 0 } } startCollection() { setInterval(() => { this.monitorPM2Agent() this.monitorPM2() }, 900) } getDefaultPM2Home() { var PM2_ROOT_PATH; if (process.env.PM2_HOME) PM2_ROOT_PATH = process.env.PM2_HOME; else if (process.env.HOME && !process.env.HOMEPATH) PM2_ROOT_PATH = path.resolve(process.env.HOME, '.pm2'); else if (process.env.HOME || process.env.HOMEPATH) PM2_ROOT_PATH = path.resolve(process.env.HOMEDRIVE, process.env.HOME || process.env.HOMEPATH, '.pm2'); else { console.error('[PM2][Initialization] Environment variable HOME (Linux) or HOMEPATH (Windows) are not set!'); console.error('[PM2][Initialization] Defaulting to /etc/.pm2'); PM2_ROOT_PATH = path.resolve('/etc', '.pm2'); } return PM2_ROOT_PATH; } report() { return { pm2: this.pm2_monitoring, agent: this.pm2_agent_monitoring } } monitorPM2() { let pm2_pid_file = path.join(this.getDefaultPM2Home(), 'pm2.pid') fs.readFile(pm2_pid_file, (err, pm2_pid) => { if (err) return console.error(`Could not read ${pm2_pid_file}`) if (!pm2_pid) return console.error(`PID is null`) pm2_pid = parseInt(pm2_pid) pidusage(pm2_pid, (err, stats) => { if (err) return console.error(err) this.pm2_monitoring = { cpu: stats.cpu.toFixed(1), mem: (stats.memory / 1024 / 1024).toFixed(1) } }) }) } monitorPM2Agent() { let pm2_agent_pid_file = path.join(this.getDefaultPM2Home(), 'agent.pid') fs.readFile(pm2_agent_pid_file, (err, pm2_agent_pid) => { if (err) return if (!pm2_agent_pid) return pidusage(pm2_agent_pid, (err, stats) => { if (err) return this.pm2_agent_monitoring = { cpu: stats.cpu.toFixed(1), mem: (stats.memory / 1024 / 1024).toFixed(1) } }) }) } } module.exports = PM2Monitoring |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0038 ]-- |