Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
pm2-messages
Advanced tools
Library to retrieve messages within a PM2 cluster
This package provides a communication interface to retrieve messages of processes managed by pm2. It can be used to aggregate Prometheus metrics such that the aggregated registry represents cluster metrics.
Install the package with:
npm install pm2-messages --save
or
yarn add pm2-messages
const pm2mes = require('pm2-messages');
const prom = require('prom-client');
pm2mes.onMessage('get_prom_register', () => prom.register.getMetricsAsJSON());
await pm2mes.connect();
const metricsArr = await pm2mes.getMessages('get_prom_register');
await pm2mes.disconnect();
const metrics = prom.AggregatorRegistry.aggregate(metricsArr).metrics();
Use the connect
and disconnect
methods to connect and disconnect from pm2, respectively. Use isConnected
to determine whether there is a connection with pm2.
connect()
before using getMessages
.disconnect()
after having called connect()
when you would like the process to gracefully exit.The following example demonstrates how to properly use connect
and disconnect
once, instead of calling them around every getMessages
call.
Note that the latter will cause issues when concurrent requests are happening, i.e. when two processes in a cluster are using getMessages
at the same time. Calling disconnect()
in one process will wrongly affect the connections by other processes, resulting in an error when trying to use the connection (see issue #5).
const pm2mes = require('pm2-messages');
const gracefulShutdown = async function gracefulShutdown() {
try {
if (pm2mes.isConnected()) await pm2mes.disconnect();
process.exit();
} catch (err) {
console.error(err);
process.exit(1);
}
};
process.on('SIGINT', gracefulShutdown);
process.on('SIGTERM', gracefulShutdown);
(async () => {
await pm2mes.connect();
// Your code here, e.g. init server
})().catch(async (err) => {
console.error(err);
await gracefulShutdown();
});
Message handlers return the requested message for a specific topic. Handlers may be asynchronous, i.e. return a promise. Requests may carry additional data, available as first argument.
pm2mes.onMessage('get_something', async (data) => {
if (data.val === myVal) return doSomethingAsync();
});
Messages can be collected using the getMessages
function. The first argument is required and denotes the topic, the second argument is optional and contains additional request data, and the third argument is optional and contains configuration options.
const somethingArr = await pm2mes.getMessages(
'get_something',
{ val: 'value' },
{ filter: (process) => process.name === 'my process', timeout: 100 }
);
(process): boolean => process.name === process.env.name
.FAQs
Package to request messages from processes managed by pm2.
The npm package pm2-messages receives a total of 941 weekly downloads. As such, pm2-messages popularity was classified as not popular.
We found that pm2-messages demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.