Skip to content

Instantly share code, notes, and snippets.

View yekver's full-sized avatar
🙂

Ivan Panteleev yekver

🙂
  • Deutsche Bank AG
  • Berlin, Germany
View GitHub Profile
@yekver
yekver / prom-client_pm2_cluster.js
Last active August 11, 2023 18:47
Instead of `cluster` module there is no direct access to the master process in `pm2`. To return metrics for the whole cluster you can do IPC calls from the active instance to the rest of them and wait while all their locally collected metrics will be sent. Finally you have to aggregate all received metrics.
const prom = require('prom-client');
const pm2 = require('pm2');
let pm2Bus;
const REQ_TOPIC = 'get_prom_register';
function pm2exec(cmd, ...args) {
return new Promise((resolve, reject) => {
pm2[cmd](...args, (err, resp) => (err ? reject(err) : resolve(resp)));