说明
雀巢的相机舱.
安装
$ 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结束点- 隐藏
- 竖起
许可证
麻省理工学院执照