# @digikare/nestjs-prom 中文文档

规范地址：https://npmcn.com/package/%40digikare/nestjs-prom/

版本：1\.0\.0
npm 元数据更新时间：2022-04-05T04:33:45.700Z
中文译文更新时间：2026-11-12T08:16:54.460Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40digikare/nestjs-prom
原文对照：https://npmcn.com/package/%40digikare/nestjs-prom/?lang=original
项目主页：https://github.com/digikare/nestjs-prom#readme
源码仓库：https://github.com/digikare/nestjs-prom

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：63.8 kB，53 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：4 个
- 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
- 首次发布：2018-10-01T21:04:13.118Z
- 最新版本发布：2020-10-23T22:40:06.802Z
- 近 30 天下载量：7337（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：12（近 12 个月 0 个）

## 中文简介

巢穴代言模块

## 安装

```sh
npm install @digikare/nestjs-prom
```

也可以使用：`pnpm add @digikare/nestjs-prom`、`yarn add @digikare/nestjs-prom`、`bun add @digikare/nestjs-prom`

## README

## 说明

雀巢的相机舱.

## 安装

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

## 如何使用

导入 `PromModule` 输入根 `ApplicationModule`

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

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

### 设置参数

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

```typescript
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()` 获得衡量标准的装饰器

```typescript
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();
  }
}
```

### 计量类案例

```typescript
@PromInstanceCounter
export class MyClass {

}
```

将生成一个名为: `app_MyClass_instances_total`

### 计量方法呼叫

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

  }
}
```

将生成一个名为: `app_MyService_doMyStuff_calls_total`

### 计量终点

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

```ts
@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 是什么？

巢穴代言模块

### 如何安装 @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 和提交记录判断。

