{"_id":"elysia-prometheus","_rev":"3-d64b3b6e41caf7fe91036c7880624f05","name":"elysia-prometheus","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"elysia-prometheus","version":"1.0.0","keywords":["elysia","prometheus","metrics","monitoring"],"author":{"url":"https://github.com/m1handr","name":"m1handr"},"license":"MIT","_id":"elysia-prometheus@1.0.0","maintainers":[{"name":"mihandr","email":"m1handr@proton.me"}],"homepage":"https://github.com/m1handr/elysia-prometheus","bugs":{"url":"https://github.com/m1handr/elysia-prometheus/issues"},"dist":{"shasum":"b9e9717c2cfa5e20d21819633764bafe3dddbd17","tarball":"https://registry.npmjs.org/elysia-prometheus/-/elysia-prometheus-1.0.0.tgz","fileCount":7,"integrity":"sha512-imyEWHOXfkhBBTedSp1uM6W7BylkkUE0g7hCWBgpCDE99z7Y3l5MIOPFkqcAloIC2tCgx4dKRkkEfvCL4nhlYg==","signatures":[{"sig":"MEUCIH7HQv29cNHIRXqneR+Vo7UKy2TYV5+3pNxnRklYKp5UAiEAgTXc4sBKoORHus8ORniQfGu02mz7wci4M9wis0pdJaI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15235},"main":"./dist/cjs/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/cjs/index.js"}},"gitHead":"7c66c0ab42a268c40ad285b2f26479cb6852445b","scripts":{"dev":"bun example/index.ts --watch","build":"bun build.ts","format":"prettier --write .","release":"npm run format && npm run build && npm publish --access public"},"_npmUser":{"name":"mihandr","email":"m1handr@proton.me"},"repository":{"url":"git+https://github.com/m1handr/elysia-prometheus.git","type":"git"},"_npmVersion":"10.9.2","description":"Prometheus metrics plugin for Elysia framework","directories":{},"_nodeVersion":"23.7.0","dependencies":{"prom-client":"^15.1.3"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.4.0","elysia":">= 1.2.0","prettier":"^3.5.3","@types/bun":"latest","typescript":"^5.5.3"},"peerDependencies":{"elysia":">= 1.2.0"},"_npmOperationalInternal":{"tmp":"tmp/elysia-prometheus_1.0.0_1744974302761_0.36662985397422365","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"elysia-prometheus","version":"1.1.0","keywords":["elysia","prometheus","metrics","monitoring"],"author":{"url":"https://github.com/m1handr","name":"m1handr"},"license":"MIT","_id":"elysia-prometheus@1.1.0","maintainers":[{"name":"mihandr","email":"m1handr@proton.me"}],"homepage":"https://github.com/m1handr/elysia-prometheus","bugs":{"url":"https://github.com/m1handr/elysia-prometheus/issues"},"dist":{"shasum":"315855a6d26483e8f1086122b1001d02991f990a","tarball":"https://registry.npmjs.org/elysia-prometheus/-/elysia-prometheus-1.1.0.tgz","fileCount":7,"integrity":"sha512-btmov1WeseuUSbcm8+V/vPT4lYGP0+0kmt5NOW2mvlqf3kaZKiFOY4wH1tg/A/7RWrvWh2bjAWxEdjlrqhLmbg==","signatures":[{"sig":"MEUCIQDP8SQ3qM9cbp4mZAtdfGFXHyS7QYGC0nd+3AhwD3j6+AIgBDCmgk4q/qqAiIAfAHVvKCLydEwtDdINKIEmOsYEfyw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15227},"main":"./dist/cjs/index.js","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/cjs/index.js"}},"gitHead":"42a9778a8baff2d5d20ca5dc625e8dc9167ab7b4","scripts":{"dev":"bun example/index.ts --watch","build":"bun build.ts","format":"prettier --write .","release":"npm run format && npm run build && npm publish --access public"},"_npmUser":{"name":"mihandr","email":"m1handr@proton.me"},"repository":{"url":"git+https://github.com/m1handr/elysia-prometheus.git","type":"git"},"_npmVersion":"10.9.2","description":"Prometheus metrics plugin for Elysia framework","directories":{},"_nodeVersion":"23.7.0","dependencies":{"prom-client":"^15.1.3"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.4.0","elysia":">= 1.2.0","prettier":"^3.5.3","@types/bun":"latest","typescript":"^5.5.3"},"peerDependencies":{"elysia":">= 1.2.0"},"_npmOperationalInternal":{"tmp":"tmp/elysia-prometheus_1.1.0_1770555734821_0.4747531949298669","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"elysia-prometheus","version":"1.1.1","description":"Prometheus metrics plugin for Elysia framework","author":{"name":"m1handr","url":"https://github.com/m1handr"},"main":"./dist/cjs/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/cjs/index.js"}},"keywords":["elysia","prometheus","metrics","monitoring"],"homepage":"https://github.com/m1handr/elysia-prometheus","repository":{"type":"git","url":"git+https://github.com/m1handr/elysia-prometheus.git"},"bugs":{"url":"https://github.com/m1handr/elysia-prometheus/issues"},"license":"MIT","scripts":{"dev":"bun example/index.ts --watch","format":"prettier --write .","build":"bun build.ts","release":"npm run format && npm run build && npm publish --access public"},"devDependencies":{"@types/bun":"latest","prettier":"^3.5.3","tsup":"^8.4.0","elysia":">= 1.2.0","typescript":"^5.5.3"},"peerDependencies":{"elysia":">= 1.2.0"},"dependencies":{"prom-client":"^15.1.3"},"_id":"elysia-prometheus@1.1.1","gitHead":"8a717cda4e692b71034b4a18cef0f698cc879d0d","_nodeVersion":"23.7.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-1IdzkmViDuOehUIMuB7+TbKYNpu04pXLncZVMQpFOV4Kn26Jfv3me606TmBKsrcw0jD3jB3dnpf+qXDQ6Q+fAw==","shasum":"a3e0e0ff77d76a048ed4838e6a20355b5850cf27","tarball":"https://registry.npmjs.org/elysia-prometheus/-/elysia-prometheus-1.1.1.tgz","fileCount":7,"unpackedSize":14861,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC3tJV2xN6LK/5ndpYWjsO0Fyji5dKJu2xiaFR+yCjRPAIgBZFI1Jf6MRwBevRxVoPy1S06oGf6LzkrapmSGe9R+aM="}]},"_npmUser":{"name":"mihandr","email":"m1handr@proton.me"},"directories":{},"maintainers":[{"name":"mihandr","email":"m1handr@proton.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/elysia-prometheus_1.1.1_1771967584444_0.17552653654666783"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-18T11:05:02.660Z","modified":"2026-02-24T21:13:04.770Z","1.0.0":"2025-04-18T11:05:02.936Z","1.1.0":"2026-02-08T13:02:14.957Z","1.1.1":"2026-02-24T21:13:04.631Z"},"bugs":{"url":"https://github.com/m1handr/elysia-prometheus/issues"},"author":{"name":"m1handr","url":"https://github.com/m1handr"},"license":"MIT","homepage":"https://github.com/m1handr/elysia-prometheus","keywords":["elysia","prometheus","metrics","monitoring"],"repository":{"type":"git","url":"git+https://github.com/m1handr/elysia-prometheus.git"},"description":"Prometheus metrics plugin for Elysia framework","maintainers":[{"name":"mihandr","email":"m1handr@proton.me"}],"readme":"# Elysia Prometheus Plugin\n\nA lightweight plugin for [Elysia](https://elysiajs.com/) that exposes HTTP metrics for Prometheus using [`prom-client`](https://github.com/siimon/prom-client). Automatically tracks request count, duration, method, status code, and more — with support for custom labels.\n\n## Features\n\n- ✅ Exposes `/metrics` endpoint (configurable)\n- 📊 Collects request duration and total request count\n- 🏷 Supports static and dynamic labels\n- 🧠 Route normalization for consistent metric names\n- 🪝 Integrates with `derive` and `onAfterHandle` lifecycle hooks\n\n## Installation\n\n```bash\nbun install elysia-prometheus\n```\n\n## Usage\n\n```ts\nimport { sleep } from 'bun'\nimport { Elysia, error } from 'elysia'\nimport prometheusPlugin from 'elysia-prometheus'\n\nconst app = new Elysia()\n\t.use(\n\t\tprometheusPlugin({\n\t\t\tmetricsPath: '/metrics',\n\t\t\tstaticLabels: { service: 'my-app' },\n\t\t\tdynamicLabels: {\n\t\t\t\tuserAgent: (ctx) =>\n\t\t\t\t\tctx.request.headers.get('user-agent') ?? 'unknown'\n\t\t\t}\n\t\t})\n\t)\n\t.get('/', () => 'GET /')\n\t.post('/', () => 'POST /')\n\t.get('/delay', () => {\n\t\tsleep(1000)\n\t\treturn 'GET /delay'\n\t})\n\t.get('/error/:code', ({ params }) => {\n\t\treturn error(Number.parseInt(params.code))\n\t})\n\t.listen(3000)\n```\n\n## Metrics Exposed\n\n- `http_requests_total` — Counter of total HTTP requests\n\n- `http_request_duration_seconds` — Histogram of request durations\n\n### Default Labels\n\n- `method` – HTTP method (`GET`, `POST`, etc.)\n\n- `path` – Normalized route path (e.g., `/users/:id`)\n\n- `status` – HTTP status code (`200`, `404`, etc.)\n\n### Custom Labels\n\n- `staticLabels`: Adds the same label value for every request\n\n- `dynamicLabels`: Functions that extract values from each request context\n\n## Plugin Options\n\n| Option            | Type                                       | Default                            | Description                                                                      |\n| ----------------- | ------------------------------------------ | ---------------------------------- | -------------------------------------------------------------------------------- |\n| `metricsPath`     | `string`                                   | `\"/metrics\"`                       | URL path to expose metrics                                                       |\n| `durationBuckets` | `number[]`                                 | `[0.003, 0.03, 0.1, 0.3, 1.5, 10]` | Histogram buckets for request duration                                           |\n| `staticLabels`    | `Record<string, string>`                   | `{}`                               | Static labels added to all metrics                                               |\n| `dynamicLabels`   | `Record<string, (ctx: Context) => string>` | `{}`                               | Dynamic labels based on request context                                          |\n| `useRoutePath`    | `boolean`                                  | `true`                             | Use route pattern instead of raw URL (e.g. `/users/:id` instead of `/users/123`) |\n\n> ⚠️ Label names `method`, `path`, and `status` are reserved and cannot be overridden.\n\n## Route Normalization\n\nThe plugin automatically normalizes paths like:\n\n```\n/users/123/orders/456 → /users/:id/orders/:id\n```\n\nThis prevents metric explosion from unique IDs in URLs.\n\n## License\n\nMIT\n\n## Contributing\n\nIf you want to add or improve the library or its documentation, make a pull request to this repository. Please use [bun](https://bun.sh) and format js and ts code with [prettier](https://prettier.io/) to make everything look nice.\n","readmeFilename":"README.md"}