@aidra/pmx-io
v9.70.0
Published
In-process instrumentation for Node.js and Bun apps run by pmx, or reporting to prodman on their own (@pm2/io compatible)
Readme
@aidra/pmx-io
In-process instrumentation for Node.js and Bun apps that report to
prodman: metrics, custom actions, exceptions, events,
logs, CPU and heap profiling, and distributed tracing with database and message-broker
integrations. It keeps the @pm2/io API, so code written for PM2.io works unchanged.
- Run by pmx: pmx injects this library into every app it starts; nothing to install. An
installed copy stays idle and
requirereturns the injected instance. - Run by PM2 / pm2_prodman: reports through the pmx daemon, like
@pm2/io. - Standalone (a container's
node app.js, an ECS task, a worker): connects to prodman itself as a one-process agent.
Node.js 18 or later, or Bun 1.1 or later. No dependencies.
Install
npm install @aidra/pmx-ioCode that requires @pm2/io can keep doing so: install the package under that name.
npm install @pm2/io@npm:@aidra/pmx-ioStandalone mode
Set the bucket keys (prodman: Bucket settings → Connect servers) and an app name:
PRODMAN_URL=https://prodman.example.com
PMX_PUBLIC_KEY=<public key>
PMX_SECRET_KEY=<secret key>
PMX_APP_NAME=orders-apiThe pm2 names (PM2_PUBLIC_KEY, PM2_SECRET_KEY, PM2_APP_NAME, PM2_MACHINE_NAME) are still
accepted for pm2 compatibility. When both forms are set, the PMX_ name wins (one warning names
both, never the values). The PMX_ forms need @aidra/pmx-io 9.33 or later (pmx 9.33+); the
standalone root removes the keys under both names from its environment, so children never see
them. See the environment variable reference.
Then load the library without changing code:
npx pmx-io-node run -- node server.js
node --require @aidra/pmx-io/standalone server.js
NODE_OPTIONS='--import @aidra/pmx-io/standalone.mjs' node server.mjsor require it first thing in the app:
const io = require('@aidra/pmx-io')
io.init({ apmOptions: { sendLogs: true, application: 'shop' } })Settings, server names, containers and troubleshooting: prodman's documentation page
Node.js apps without pmx (/docs/node-apm).
API
const io = require('@aidra/pmx-io')
io.metric({ name: 'Queue length' }).set(12)
io.counter({ name: 'Jobs done' }).inc()
io.action('flush cache', (reply) => reply({ ok: true }))
io.notifyError(new Error('payment failed'), { custom: { orderId } })TypeScript declarations are included (index.d.ts), a superset of @pm2/io's.
License
Apache-2.0 (see LICENSE and NOTICE). This client library is open source; the pmx
daemon/CLI and Prodman are commercial software.
