Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_checkMemory() {
console.log('check memory called')
const _this = this;
pm2.list((err, list) => {
if (err || list.length === 0) {
console.error('something went wrong with your processes, please check you processes list via pm2 l')
process.exit()
}
list.forEach((proc) => {
// if process is being enabled to monitoring then check memory of process
if (_this._processes.indexOf(proc.name) !== -1) {
// if process memory more than alert.maxMemroySize then send notification
if (proc.monit.memory >= _this._config.memory.maxMemroySize) {
function addWatchdogOfExistingProcesses() {
console.trace('Getting list of processes.');
// Gets list of process managed by pm2
pm2.list(
/**
*
* @param {Error|null} err
* @param {ProcessDescription[]} apps
*/
function(err, apps) {
if (err) {
console.error(`PM2 get process list failed. ${err.message || err}`);
pm2.disconnect();
return;
}
apps.forEach((/*ProcessDescription*/ processDescription) => {
if (processDescription.pm2_env.axm_options.isModule) {
console.trace(`Process ${processDescription.name} - is PM2 module. Ignoring it`);
_waitRemainingRequests (resolve) {
const remaining = this.kuzzle.funnel.remainingRequests;
if (remaining !== 0) {
console.log(`Waiting: ${remaining} remaining requests`);
return setTimeout(() => this._waitRemainingRequests(resolve), 1000);
}
resolve();
pm2.list((listerr, processes) => {
if (listerr) {
return this._halt();
}
const kuzzleProcess = processes
.filter(pm2Process => pm2Process.pid === process.pid);
// not started with PM2 or development mode => exit immediately
if (kuzzleProcess.length === 0 || kuzzleProcess[0].pm2_env.watch) {
if (kuzzleProcess.length !== 0) {
console.log('PM2 Watch activated: restarting Kuzzle');
return pm2.restart(kuzzleProcess[0].pm_id);
}
return this._halt();
pm2.connect(() => {
pm2.list((err, procs) => {
const _ids = _.without(procs.map((proc) => proc.name), 'pmteor');
// stop list applications.
_.forEach(_ids, (_id) => pm2.stop(_id, () => {
}));
});
});
});
pm2.start(self.options(port), Meteor.bindEnvironment((start_error) => {
if (_.isNull(start_error)) {
// LIST
return pm2.list(Meteor.bindEnvironment((list_error, procs) => {
const application = _.findWhere(procs, {
name: self.bundleId
});
if (application) {
const { name, monit } = application;
const { pm_uptime, restart_time } = application.pm2_env;
Applications.update({ bundleId: name }, {
$set: {
monit: {
// UPTIME AND RESTART TIME
pm_uptime,
restart_time,
pm2.connect(Meteor.bindEnvironment((connect_err) => {
if (_.isNull(connect_err)) {
pm2.list(Meteor.bindEnvironment((list_err, procs) => {
const onlines = _.reject(procs, (proc) => _.isEqual(proc.pid, 0));
if (onlines.length) {
onlines.forEach(Meteor.bindEnvironment((proc) => {
const { name, monit } = proc;
const { pm_uptime, restart_time } = proc.pm2_env;
Applications.update({ bundleId: name }, {
$set: {
monit: {
// UPTIME AND RESTART TIME
pm_uptime,
restart_time,
// MONIT OBJECT INJECT
testProbes() {
Log_1.debug("testing probes");
const alerts = [];
PM2.list(async (ex, list) => {
stopIfEx(ex);
for (const app of list) {
if (!this.isAppIncluded(app.name))
continue;
let monit = app.pm2_env["axm_monitor"];
if (!monit)
monit = {};
// add memory + cpu metrics
if (app.monit) {
monit["memory"] = { value: app.monit.memory / 1048576 };
monit["cpu"] = { value: app.monit.cpu };
}
if (app.pm2_env) {
if (app.pm2_env["_pm2_version"])
monit["pm2"] = { value: app.pm2_env["_pm2_version"], direct: true };
if (app.pm2_env["node_version"])
function chooseProcess(filterStr, notDoneYet, command) {
pm2.list(function(err, ret) {
if (err) onError(err);
var askForFilter = [{
type: "input",
name: "filter",
message: "Filter processes",
default: function() { return filterStr || ''; }
}];
if (filterStr && !notDoneYet) {
chooseFromList({
filter: filterStr
});
} else {
inquirer.prompt(askForFilter, chooseFromList);
.then(() => Promise.fromNode(callback => pm2.list(callback)))
.then(list => {
return new Promise((resolve, reject) => {
pm2.list((err, processDescriptionList) => {
if (err) {
disconnect()
reject(err)
} else {
disconnect()
resolve(processDescriptionList)
}
})
})
}