Reputation: 3407
I am using pm2 to supervise a node app, and occasionally the app is hanging. I need to detect that this has happened so that pm2 can restart the app. The easiest way seems to be to create a metric with a timestamp and update it from the app every few seconds, then the supervisor will also check the value of the metric to see if it still being updated.
The problem I am having is that I am not finding any documentation on how to read the pm2/io metrics programmatically from the pm2 supervision code.
How do I read the metrics programmatically from the pm2 supervision code?
Or is there a better way to do what I am trying to do?
Upvotes: 1
Views: 371
Reputation: 81
It's late but here's the code
const pm2 = require('pm2')
pm2.connect(function (err) {
if (err) {
console.error(err)
process.exit(2)
}
pm2.list((err2, processList) => {
if (err2) {
console.error(err2)
process.exit(2)
}
for (eachProcess of processList) {
console.log(eachProcess.pm2_env.axm_monitor)
}
})
});
Upvotes: 1