# @donews/nestjs-prom

> nestjs prom module

Latest version **0.11.1** (published 2025-03-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @donews/nestjs-prom
pnpm add @donews/nestjs-prom
yarn add @donews/nestjs-prom
bun add @donews/nestjs-prom
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.11.1 |
| Published | 2025-03-07 |
| First published | 2020-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 25.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | toonewLi <litaixin01@163.com> |
| Maintainers | litaixin01, stringang |

## Links

- npm: https://www.npmjs.com/package/@donews/nestjs-prom
- Repository: https://github.com/DoNewsCode/nestjs
- Issues: https://github.com/DoNewsCode/nestjs/issues
- npm.io page: https://npm.io/package/@donews/nestjs-prom

## Dependencies (1)

- [prom-client](https://npm.io/package/prom-client.md) ^15.0.0

## Recent versions

- 0.11.1 (latest) — 2025-03-07
- 0.11.1-alpha.0 (beta) — 2025-03-06
- 0.10.2 — 2022-03-22
- 0.10.0 — 2022-03-02
- 0.9.3 — 2021-09-22
- 0.9.2 — 2021-07-13
- 0.9.1 — 2021-07-13
- 0.9.0 — 2021-07-12
- 0.8.4 — 2021-06-22
- 0.8.3 — 2021-06-07
- 0.8.1 — 2021-04-14
- 0.8.0 — 2021-04-13
- 0.1.0 — 2021-03-09
- 0.0.1 — 2020-07-30

## README

# nest prometheus module

取消多 register 设计，没啥必要，感觉不到多个 register 的用处和意义，
并且不同 register 同 name 合并时，会直接 throw 没啥意义，以后由更加完善的需求再研究吧

## 描述

## Install

```bash
$ npm i @donews/nestjs-prom prom-client
```

## Quick Start

假定一个目录结构

```
/root
    /src
        app.module.ts
```

### 1. 模块导入

```typescript
import { LoggerModule } from '@donews/nestjs-prom';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    PromModule.forRoot(
      {
        withDefaultsMetrics: false,
      },
      [
        {
          type: MetricType.Counter,
          configuration: {
            name: 'my_counter',
            help: 'my_counter a simple counter',
          },
        },
        {
          type: MetricType.Gauge,
          configuration: {
            name: 'my_gauge',
            help: 'my_gauge a simple gauge',
          },
        },
        {
          type: MetricType.Histogram,
          configuration: {
            name: 'my_histogram',
            help: 'my_histogram a simple histogram',
          },
        },
        {
          type: MetricType.Summary,
          configuration: {
            name: 'my_summary',
            help: 'my_summary a simple summary',
          },
        },
      ],
    ),
  ],
})
export class AppModule {}
```

### 2. 增加 asynchronous provider

```typescript
@Module({
  imports: [
    PromModule.forRootAsync(
      {
        useFactory(configService: ConfigService) {
          return {
            withDefaultsMetrics: configService.get(false),
          };
        },
        inject: [ConfigService],
        imports: [ConfigModule],
      },
      [
        {
          type: MetricType.Counter,
          configuration: {
            name: 'my_counter',
            help: 'my_counter a simple counter',
          },
        },
        {
          type: MetricType.Gauge,
          configuration: {
            name: 'my_gauge',
            help: 'my_gauge a simple gauge',
          },
        },
        {
          type: MetricType.Histogram,
          configuration: {
            name: 'my_histogram',
            help: 'my_histogram a simple histogram',
          },
        },
        {
          type: MetricType.Summary,
          configuration: {
            name: 'my_summary',
            help: 'my_summary a simple summary',
          },
        },
      ],
    ),
  ],
})
export class AppModule {}
```

### 3. 使用

```typescript
import { Inject, Injectable } from '@nestjs/common';

@Injectable()
class TestService {
  constructor(
    @Inject('my_counter')
    private readonly counter: Counter<string>,
  ) {}

  say() {
    this.counter.inr();
  }
}
```

## License

Nest is [MIT licensed](LICENSE).

---
_Source: https://npm.io/package/@donews/nestjs-prom · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
