{"id":28048,"library":"pmx","title":"PMX","description":"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.","status":"active","version":"1.6.8","language":"javascript","source_language":"en","source_url":"https://github.com/keymetrics/pmx","tags":["javascript","cli","fault tolerant","sysadmin","tools","pm2","logs","log","json"],"install":[{"cmd":"npm install pmx","lang":"bash","label":"npm"},{"cmd":"yarn add pmx","lang":"bash","label":"yarn"},{"cmd":"pnpm add pmx","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default ESM import; CJS require works in Node but may conflict with type module.","wrong":"const pmx = require('pmx')","symbol":"pmx","correct":"import pmx from 'pmx'"},{"note":"probe() is a method on the default export, not a named export.","wrong":"const probe = require('pmx').probe()","symbol":"probe","correct":"import pmx from 'pmx'; const probe = pmx.probe()"},{"note":"TypeScript users should use `import type` for type-only imports; pmx ships its own types.","wrong":"","symbol":"Metric (type)","correct":"import type { Metric } from 'pmx'"}],"quickstart":{"code":"import pmx from 'pmx';\nimport http from 'http';\n\nconst probe = pmx.probe();\n\nconst users = {};\nconst metric = probe.metric({\n  name: 'Realtime user',\n  value: () => Object.keys(users).length\n});\n\nconst counter = probe.counter({ name: 'req/sec' });\n\nhttp.createServer((req, res) => {\n  counter.inc();\n  res.end('ok');\n}).listen(3000);\n\nconsole.log('Server running on port 3000');","lang":"javascript","description":"Initializes PMX, creates a metric tracking user count and a counter for HTTP requests."},"warnings":[{"fix":"Use default import `import pmx from 'pmx'` and call `pmx.init()` with options if needed.","message":"pmx@1.0 removed the old 'pmx.init()' API; use 'pmx.init()' is now imported as default.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always call `const probe = pmx.probe()` before using metric, counter, meter, or histogram.","message":"The 'probe' object is obtained via `pmx.probe()` – it is not a direct export.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid using pmx.event(); instead emit custom events using pm2.connect or pm2.io packages.","message":"The 'event' method (pmx.event()) is deprecated; use custom events via Keymetrics API or pm2.io.","severity":"deprecated","affected_versions":">=1.5.0"},{"fix":"Set `samples: 60` in meter options if you need per-minute averaging.","message":"Meter samples default to 1 (per second); to get per-minute rate set samples to 60.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use only valid measurement strings: 'mean', 'median', 'p75', 'p95', 'p99', 'p999'.","message":"Histogram measurement must be one of 'mean', 'median', 'p75', etc.; invalid values silently produce no data.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Run `npm install pmx --save` to add it to dependencies.","cause":"PMX not installed or not in node_modules.","error":"Cannot find module 'pmx'"},{"fix":"Use default import: `import pmx from 'pmx'` then `pmx.probe()`.","cause":"Used named import instead of default import: `import { probe } from 'pmx'`.","error":"pmx.probe is not a function"},{"fix":"First create probe: `const probe = pmx.probe()` then use `probe.metric()`.","cause":"Calling `pmx.metric()` directly instead of via probe.","error":"TypeError: pmx.metric is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}