0.10.2 • Published 2 years ago

@donews/nestjs-prom v0.10.2

Weekly downloads
39
License
MIT
Repository
github
Last release
2 years ago

nest prometheus module

取消多 register 设计,没啥必要,感觉不到多个 register 的用处和意义, 并且不同 register 同 name 合并时,会直接 throw 没啥意义,以后由更加完善的需求再研究吧

描述

Install

$ npm i @donews/nestjs-prom prom-client

Quick Start

假定一个目录结构

/root
    /src
        app.module.ts

1. 模块导入

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

@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. 使用

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.

0.10.2

2 years ago

0.10.0

2 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.8.4

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.1.0

3 years ago

0.0.1

4 years ago