PMX
raw JSON → 1.6.8 verified Sat May 09 auth: no javascript
PMX is the programmatic integration library for PM2 and Keymetrics.io (v1.6.8, latest stable). It enables Node.js applications to expose custom metrics (simple values, counters, meters, histograms), triggerable remote functions, exception alerts, custom events, and network traffic monitoring to the PM2 CLI and Keymetrics dashboard. Released irregularly with minor version bumps, it supports Node.js >= 0.10. Key differentiators: deep PM2/Keymetrics integration, low-overhead metric probes, and production monitoring without external monitoring services.
Common errors
error Cannot find module 'pmx' ↓
cause PMX not installed or not in node_modules.
fix
Run
npm install pmx --save to add it to dependencies. error pmx.probe is not a function ↓
cause Used named import instead of default import: `import { probe } from 'pmx'`.
fix
Use default import:
import pmx from 'pmx' then pmx.probe(). error TypeError: pmx.metric is not a function ↓
cause Calling `pmx.metric()` directly instead of via probe.
fix
First create probe:
const probe = pmx.probe() then use probe.metric(). Warnings
breaking pmx@1.0 removed the old 'pmx.init()' API; use 'pmx.init()' is now imported as default. ↓
fix Use default import `import pmx from 'pmx'` and call `pmx.init()` with options if needed.
gotcha The 'probe' object is obtained via `pmx.probe()` – it is not a direct export. ↓
fix Always call `const probe = pmx.probe()` before using metric, counter, meter, or histogram.
deprecated The 'event' method (pmx.event()) is deprecated; use custom events via Keymetrics API or pm2.io. ↓
fix Avoid using pmx.event(); instead emit custom events using pm2.connect or pm2.io packages.
gotcha Meter samples default to 1 (per second); to get per-minute rate set samples to 60. ↓
fix Set `samples: 60` in meter options if you need per-minute averaging.
gotcha Histogram measurement must be one of 'mean', 'median', 'p75', etc.; invalid values silently produce no data. ↓
fix Use only valid measurement strings: 'mean', 'median', 'p75', 'p95', 'p99', 'p999'.
Install
npm install pmx yarn add pmx pnpm add pmx Imports
- pmx wrong
const pmx = require('pmx')correctimport pmx from 'pmx' - probe wrong
const probe = require('pmx').probe()correctimport pmx from 'pmx'; const probe = pmx.probe() - Metric (type)
import type { Metric } from 'pmx'
Quickstart
import pmx from 'pmx';
import http from 'http';
const probe = pmx.probe();
const users = {};
const metric = probe.metric({
name: 'Realtime user',
value: () => Object.keys(users).length
});
const counter = probe.counter({ name: 'req/sec' });
http.createServer((req, res) => {
counter.inc();
res.end('ok');
}).listen(3000);
console.log('Server running on port 3000');