{"_id":"@afsalk/nestjs-prom","_rev":"1-690ec6aa3528433883355600a2443ff0","name":"@afsalk/nestjs-prom","dist-tags":{"next":"1.0.1","latest":"1.0.0"},"versions":{"1.0.0":{"name":"@afsalk/nestjs-prom","version":"1.0.0","description":"A promotheus module for nestjs","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"rm -rf dist && tsc -p tsconfig.json","precommit":"lint-staged","prepublish:npm":"npm run build","publish:npm":"npm publish --access public","prepublish:next":"npm run build","publish:next":"npm publish --access public --tag next","test:e2e":"jest --config ./tests/jest-e2e.json --runInBand","test:e2e:dev":"jest --config ./tests/jest-e2e.json --runInBand --watch","test:debug":"node --inspect-brk ./node_modules/.bin/ts-node tests/src/main.ts","test:live":"ts-node tests/src/main.ts"},"author":{"name":"Tieu-Philippe KHIM","email":"pkhim@digikare.com"},"license":"MIT","devDependencies":{"@nestjs/common":"^7.0.0","@nestjs/core":"^7.0.0","@nestjs/platform-express":"^7.3.2","@types/jest":"^26.0.7","@types/node":"^12.12.53","@types/response-time":"^2.3.4","@types/supertest":"^2.0.10","jest":"^26.1.0","reflect-metadata":"^0.1.13","rxjs":"^6.6.0","supertest":"^4.0.2","ts-jest":"^26.1.4","ts-node":"^8.3.0","typescript":"^5.1.6"},"peerDependencies":{"@nestjs/common":"^10.1.3","@nestjs/core":"^10.1.3","reflect-metadata":"^0.1.13","rxjs":"^7.0.0"},"dependencies":{"@nestjs/testing":"^7.3.2","prom-client":"^12.0.0","response-time":"^2.3.2","url-value-parser":"^2.0.1"},"repository":{"type":"git","url":"git+https://github.com/digikare/nestjs-prom.git"},"keywords":["nestjs","promotheus"],"bugs":{"url":"https://github.com/digikare/nestjs-prom/issues"},"homepage":"https://github.com/digikare/nestjs-prom#readme","contributors":[{"name":"Michael Yankelev @FSM1"},{"name":"Ashleigh Simonelli @bashleigh"},{"name":"@blackkopcap"},{"name":"@litichevskiydv"}],"publishConfig":{"tag":"next"},"gitHead":"7ea411cc710ca9bf1370585a2265427c654dc5ba","_id":"@afsalk/nestjs-prom@1.0.0","_nodeVersion":"18.16.1","_npmVersion":"9.5.1","dist":{"integrity":"sha512-SJ4TUh87pL+3OOdXgKUdUp0D8Ed2gscABaSnd4lQGOAqekkXOzWjyZjNosApIbrs3W4AmWVCAwIoM6XtG6jaeA==","shasum":"abc4ebc148b91f3685b2aedfb420139711645fd0","tarball":"https://registry.npmjs.org/@afsalk/nestjs-prom/-/nestjs-prom-1.0.0.tgz","fileCount":52,"unpackedSize":65688,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDjBpmoMPv48J0P4Pp3sIO/JGCWvbJDTKk3dyb2A0JR3gIhAPjhDd/rU9azVVFcsefEgMfXijL+Or7Qs9VRebzPZM92"}]},"_npmUser":{"name":"afsalk","email":"makafsal@gmail.com"},"directories":{},"maintainers":[{"name":"afsalk","email":"makafsal@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-prom_1.0.0_1692009316716_0.20430513812599815"},"_hasShrinkwrap":false},"1.0.1":{"name":"@afsalk/nestjs-prom","version":"1.0.1","description":"A promotheus module for nestjs","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"rm -rf dist && tsc -p tsconfig.json","precommit":"lint-staged","prepublish:npm":"npm run build","publish:npm":"npm publish --access public","prepublish:next":"npm run build","publish:next":"npm publish --access public --tag next","test:e2e":"jest --config ./tests/jest-e2e.json --runInBand","test:e2e:dev":"jest --config ./tests/jest-e2e.json --runInBand --watch","test:debug":"node --inspect-brk ./node_modules/.bin/ts-node tests/src/main.ts","test:live":"ts-node tests/src/main.ts"},"author":{"name":"Tieu-Philippe KHIM","email":"pkhim@digikare.com"},"license":"MIT","devDependencies":{"@nestjs/common":"^10.1.3","@nestjs/core":"^10.1.3","@nestjs/platform-express":"^10.1.3","@types/jest":"^26.0.7","@types/node":"^20.5.0","@types/response-time":"^2.3.4","@types/supertest":"^2.0.10","jest":"^29.5.0","reflect-metadata":"^0.1.13","rxjs":"^7.0.0","supertest":"^4.0.2","ts-jest":"^29.0.0","ts-node":"^8.3.0","typescript":"^5.1.6"},"peerDependencies":{"@nestjs/common":"^10.1.3","@nestjs/core":"^10.1.3","reflect-metadata":"^0.1.13","rxjs":"^7.0.0"},"dependencies":{"@nestjs/testing":"^10.1.3","prom-client":"^14.2.0","response-time":"^2.3.2","url-value-parser":"^2.0.1"},"repository":{"type":"git","url":"git+https://github.com/digikare/nestjs-prom.git"},"keywords":["nestjs","promotheus"],"bugs":{"url":"https://github.com/digikare/nestjs-prom/issues"},"homepage":"https://github.com/digikare/nestjs-prom#readme","contributors":[{"name":"Michael Yankelev @FSM1"},{"name":"Ashleigh Simonelli @bashleigh"},{"name":"@blackkopcap"},{"name":"@litichevskiydv"}],"publishConfig":{"tag":"next"},"readme":"# nestjs-prom v1.x\n\nA prometheus module for Nest.\n\n__BREAKING CHANGE__\n\n> nestjs-prom v0.2.x has been moved to [stable/0.2](https://github.com/digikare/nestjs-prom/tree/stable/0.2) branch.\n>\n> To migrate from v0.2 to v1.x please see [Migrate from 0.2.x to 1.x](./doc/migrate_0.2_1.x.md)\n\n## Installation\n\n```bash\n$ npm install --save @digikare/nestjs-prom prom-client\n```\n\n## How to use\n\nImport `PromModule` into the root `ApplicationModule`\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { PromModule } from '@digikare/nestjs-prom';\n\n@Module({\n  imports: [\n    PromModule.forRoot({\n      defaultLabels: {\n        app: 'my_app',\n        version: 'x.y.z',\n      }\n    }),\n  ]\n})\nexport class ApplicationModule {}\n```\n\n### PromModule.forRoot options\n\nHere the options available for PromModule.forRoot:\n\n|Option|Type|Default|Description|\n|---|---|---|---|\n|defaultLabels|Object<string, string|number>|`{}`|The defaults labels to set|\n|metricPath|string|`/metrics`|Path to use to service metrics|\n|withDefaultsMetrics|boolean|`true`|enable defaultMetrics provided by prom-client|\n|withDefaultController|boolean|`true`|add internal controller to expose /metrics endpoints|\n|withHttpMiddleware|object|`{}`|Tttp middleware options for http requests metrics|\n|withHttpMiddleware.enable|boolean|`false`|Enable the middleware for http requests|\n|withHttpMiddleware.timeBuckets|number[]|`[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 10]`|The time buckets wanted|\n|withHttpMiddleware.pathNormalizationExtraMasks|RegEx[]| `[]` |The regexp mask for normalization|\n\n### Http requests\n\nTo track the http requests metrics, simply set  `withHttpMiddleware.enable = true`\n\nBy default, this feature is disabled.\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { PromModule } from '@digikare/nestjs-prom';\n\n@Module({\n  imports: [\n    PromModule.forRoot({\n      withHttpMiddleware: {\n        enable: true,\n      }\n    }),\n  ]\n})\nexport class ApplicationModule {}\n```\n\n### Setup metric\n\nTo setup a metric, the module provide multiple ways to get a metric.\n\n#### Using PromService and Dependency Injection\n\nBy using `PromService` service with DI to get a metric.\n\n```typescript\n@Injectable()\nexport class MyService {\n\n  private readonly _counter: CounterMetric;\n  private readonly _gauge: GaugeMetric,\n  private readonly _histogram: HistogramMetric,\n  private readonly _summary: SummaryMetric,\n\n  constructor(\n    private readonly promService: PromService,\n  ) {\n    this._counter = this.promService.getCounter({ name: 'my_counter' });\n  }\n\n  doSomething() {\n    this._counter.inc(1);\n  }\n\n  reset() {\n    this._counter.reset();\n  }\n}\n```\n\n#### Using Param Decorator\n\nYou have the following decorators:\n\n- `@PromCounter()`\n- `@PromGauge()`\n- `@PromHistogram()`\n- `@PromSummary()`\n\nBelow how to use it\n\n```typescript\nimport { CounterMetric, PromCounter } from '@digikare/nest-prom';\n\n@Controller()\nexport class AppController {\n\n  @Get('/home')\n  home(\n    @PromCounter('app_counter_1_inc') counter1: CounterMetric,\n    @PromCounter({ name: 'app_counter_2_inc', help: 'app_counter_2_help' }) counter2: CounterMetric,\n  ) {\n    counter1.inc(1);\n    counter2.inc(2);\n  }\n\n  @Get('/home2')\n  home2(\n    @PromCounter({ name: 'app_counter_2_inc', help: 'app_counter_2_help' }) counter: CounterMetric,\n  ) {\n    counter.inc(2);\n  }\n}\n```\n\n```typescript\nimport { GaugeMetric, PromGauge } from '@digikare/nest-prom';\n\n@Controller()\nexport class AppController {\n\n  @Get('/home')\n  home(\n    @PromGauge('app_gauge_1') gauge1: GaugeMetric,\n  ) {\n    gauge1.inc(); // 1\n    gauge1.inc(5); // 6\n    gauge1.dec(); // 5\n    gauge1.dec(2); // 3\n    gauge1.set(10); // 10\n  }\n}\n```\n\n### Metric class instances\n\nIf you want to counthow many instance of a specific class has been created:\n\n```typescript\n@PromInstanceCounter()\nexport class MyClass {\n\n}\n```\n\nWill generate a counter called: `app_MyClass_instances_total`\n\n### Metric method calls\n\nIf you want to increment a counter on each call of a specific method:\n\n```typescript\n@Injectable()\nexport class MyService {\n  @PromMethodCounter()\n  doMyStuff() {\n\n  }\n}\n```\n\nWill generate a counter called: `app_MyService_doMyStuff_calls_total` and auto increment on each call\n\nYou can use that to monitor an endpoint\n\n```typescript\n@Controller()\nexport class AppController {\n  @Get()\n  @PromMethodCounter() // will generate `app_AppController_root_calls_total` counter\n  root() {\n    // do your stuff\n  }\n\n  @Get('/login')\n  @PromMethodCounter({ name: 'app_login_endpoint_counter' })  // set the counter name\n  login() {\n    // do your stuff\n  }\n}\n```\n\n### Metric endpoint\n\nThe default metrics endpoint is `/metrics` this can be changed with the metricPath option\n\n```ts\n@Module({\n  imports: [\n    PromModule.forRoot({\n      defaultLabels: {\n        app: 'my_app',\n      },\n      metricPath: 'custom/uri',\n    }),\n  ],\n})\nexport class MyModule\n```\n\nNow your metrics can be found at `/custom/uri`.\n\n> PS: If you have a global prefix, the path will be `{globalPrefix}/metrics` for\nthe moment.\n\n## API\n\n### PromModule.forRoot() options\n\n|Option|Type|Default|Description|\n|---|---|---|---|\n|defaultLabels|Object<string, string|number>|`{}`|The defaults labels to set|\n|metricPath|string|`/metrics`|Path to use to service metrics|\n|withDefaultsMetrics|boolean|`true`|enable defaultMetrics provided by prom-client|\n|withDefaultController|boolean|`true`|add internal controller to expose /metrics endpoints|\n|withHttpMiddleware|object|`{}`|To enable the http middleware for http metrics|\n|withHttpMiddleware.enable|boolean|`false`|Enable http middleware|\n|withHttpMiddleware.timeBuckets|number[]|`[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 10]`|The time buckets wanted|\n|withHttpMiddleware.pathNormalizationExtraMasks|RegEx[]| `[]` |The regexp mask for normalization|\n\n### Decorators\n\n- `@PromInstanceCounter()` Class decorator, create and increment on each instance created\n- `@PromMethodCounter()` Method decorator, create and increment each time the method is called\n- `@PromCounter()` Param decorator, create/find counter metric\n- `@PromGauge()` Param decorator, create/find gauge metric\n- `@PromHistogram()` Param decorator, create/find histogram metric\n- `@PromSummary()` Param decorator, create/find summary metric\n\n## Auth/security\n\nI do not provide any auth/security for `/metrics` endpoints.\nThis is not the aim of this module, but depending of the auth strategy, you can\napply a middleware on `/metrics` to secure it.\n\n## License\n\nMIT licensed\n","readmeFilename":"README.md","gitHead":"d101e33a9d01c653b5edaf2a02c068183f72c1d3","_id":"@afsalk/nestjs-prom@1.0.1","_nodeVersion":"18.16.1","_npmVersion":"9.5.1","dist":{"integrity":"sha512-Rh/o5n+yC73/x10JlFLm4Tiu89U+0R1JGUbskvhrQl1O9NtPZmlgaFjFfsakNL7+wKD7XS8sjE5ULKMvDN+iIw==","shasum":"703dd4c2c6ba2a2c688db79ea3aaafcdfc697f4f","tarball":"https://registry.npmjs.org/@afsalk/nestjs-prom/-/nestjs-prom-1.0.1.tgz","fileCount":52,"unpackedSize":65690,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID0uvtbmrSdmwAUzLMWOxhAJETJSwA0o9s+0USVsEoddAiBpdS7jujR4g4gbMUa/whryCEGUBzzy8+WvS1mu71a0nQ=="}]},"_npmUser":{"name":"afsalk","email":"makafsal@gmail.com"},"directories":{},"maintainers":[{"name":"afsalk","email":"makafsal@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-prom_1.0.1_1692015662280_0.1501326695459968"},"_hasShrinkwrap":false}},"time":{"created":"2023-08-14T10:35:16.650Z","1.0.0":"2023-08-14T10:35:16.903Z","modified":"2023-08-14T12:21:02.617Z","1.0.1":"2023-08-14T12:21:02.435Z"},"maintainers":[{"name":"afsalk","email":"makafsal@gmail.com"}],"description":"A promotheus module for nestjs","homepage":"https://github.com/digikare/nestjs-prom#readme","keywords":["nestjs","promotheus"],"repository":{"type":"git","url":"git+https://github.com/digikare/nestjs-prom.git"},"contributors":[{"name":"Michael Yankelev @FSM1"},{"name":"Ashleigh Simonelli @bashleigh"},{"name":"@blackkopcap"},{"name":"@litichevskiydv"}],"author":{"name":"Tieu-Philippe KHIM","email":"pkhim@digikare.com"},"bugs":{"url":"https://github.com/digikare/nestjs-prom/issues"},"license":"MIT","readme":"","readmeFilename":""}