@digikare/nestjs-prom

中文文档
1.0.0发布于 2020/10/24MITTypeScriptCommonJS近 30 天下载 7337

巢穴代言模块

中文使用文档
文档目录12 节
  1. 说明
  2. 安装
  3. 如何使用
  4. 设置参数
  5. 计量类案例
  6. 计量方法呼叫
  7. 计量终点
  8. API 密码
  9. PromModule.forRoot () 选项
  10. 认证/安全
  11. 开始
  12. 许可证

说明

雀巢的相机舱.

安装

$ npm install --save @digikare/nestjs-prom prom-client

如何使用

导入 PromModule 输入根 ApplicationModule

import { Module } from '@nestjs/common';
import { PromModule } from '@digikare/nestjs-prom';

@Module({
  imports: [
    PromModule.forRoot({
      defaultLabels: {
        app: 'my_app',
      }
    }),
  ]
})
export class ApplicationModule {}

设置参数

在您的模块中,使用 forMetrics() 定义所需指标的方法.

import { Module } from '@nestjs/common';
import { PromModule, MetricType } from '@digikare/nestjs-prom';

@Module({
  imports: [
    PromModule.forMetrics([
      {
        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 MyModule

{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你还可以用 @InjectCounterMetric() 获得衡量标准的装饰器

import { Injectable } from '@nestjs/common';
import {
  InjectCounterMetric,
  InjectGaugeMetric,
  InjectHistogramMetric,
  InjectSummaryMetric,
  CounterMetric,
  GaugeMetric,
  HistogramMetric,
  SummaryMetric,
} from '@digikare/nestjs-prom';

@Injectable()
export class MyService {
  constructor(
    @InjectCounterMetric('my_counter') private readonly _counterMetric: CounterMetric,
    @InjectGaugeMetric('my_gauge') private readonly _gaugeMetric: GaugeMetric,
    @InjectHistogramMetric('my_histogram') private readonly _histogramMetric: HistogramMetric,
    @InjectSummaryMetric('my_summary') private readonly _summaryMetric: SummaryMetric,
  ) {}

  doStuff() {
    this._counterMetric.inc();
  }

  resetCounter() {
    this._counterMetric.reset();
  }
}

计量类案例

@PromInstanceCounter
export class MyClass {

}

将生成一个名为: app_MyClass_instances_total

计量方法呼叫

@Injectable()
export class MyService {
  @PromMethodCounter()
  doMyStuff() {

  }
}

将生成一个名为: app_MyService_doMyStuff_calls_total

计量终点

默认的度量衡终点是 /metrics 使用自定义 URl 选项更改此选项

@Module({
  imports: [
    PromModule.forRoot({
      defaultLabels: {
        app: 'my_app',
      },
      customUrl: 'custom/uri',
    }),
  ],
})
export class MyModule

现在,你的衡量标准可以在 /custom/uri。 。 。 .

PS: 如果你有一个全局前缀, 路径将是 {globalPrefix}/metrics 页:1 现在.

API 密码

PromModule.forRoot () 选项

  • withDefaultsMetrics: boolean (default true) 启用由 prom 客户端提供的默认计量
  • withDefaultController: boolean (default true) 添加内部控制器以曝光/ 测量端点
  • useHttpCounterMiddleware: boolean (default false) 注册 http requests total 计数器

认证/安全

我不提供任何授权/安全 /metrics 结束点. 这不是本单元的目的,但取决于认证策略,你可以 应用中间软件 /metrics 来保证安全.

开始

  • 更新读取器
    • 高盖
    • 直方图
    • 内容提要
  • 管理登记册
  • 测试
  • 提供自定义度量终点的可能性
  • 添加如何安全的实例 /metrics 结束点
    • 隐藏
    • 竖起

许可证

麻省理工学院执照

版本与发布记录

@digikare/nestjs-prom 共发布 12 个版本,首次发布于 2018/10/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.52020/10/246 年前
1.0.0latest2020/10/246 年前
0.2.42020/07/296 年前
0.2.32020/07/276 年前
0.2.22019/12/186 年前
0.2.12019/08/267 年前

关于 @digikare/nestjs-prom 的常见问题

@digikare/nestjs-prom 是什么?

巢穴代言模块

如何安装 @digikare/nestjs-prom?

在项目目录运行 npm install @digikare/nestjs-prom,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@nestjs/common(^6.0.0 || ^7.0.0)、@nestjs/core(^6.0.0 || ^7.0.0)、reflect-metadata(^0.1.12)、rxjs(^6.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@digikare/nestjs-prom 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@digikare/nestjs-prom 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@digikare/nestjs-prom 可以商用吗?

@digikare/nestjs-prom 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@digikare/nestjs-prom 的下载量有多少?

根据 npm 官方下载统计,@digikare/nestjs-prom 在 2026/10/12 – 2026/11/10 这 30 天内被下载 7,337 次,日均约 245 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@digikare/nestjs-prom 还在维护吗?

最新版本 1.0.0 发布于 2020/10/24(6 年前);至今共发布 12 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/10/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。