8.3.0 • Published 1 year ago

@betsys-nestjs/monitoring v8.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Dependencies

PackageVersion
on-headers^1.0.0
prom-client^14.0.0
@betsys-nestjs/config-utils^2.0.0
@hapi/joi^17.0.0
@nestjs/common^10.0.0
@nestjs/config^3.0.0
@nestjs/core^10.0.0
@nestjs/platform-express^10.0.0
@nestjs/swagger^7.0.0
express^4.0.0
reflect-metadata<1.0.0
rxjs^7.0.0

Usage

Just register the module in your application module. If you are not using cluster, use the SimpleMonitoringModule

import {Module} from '@nestjs/common';
import {SimpleMonitoringModule} from '@betsys/nestjs-monitoring';

@Module({
    imports: [
        SimpleMonitoringModule.forRoot({platformType: express}),
    ],
})
class AppModule {
}

The forRoot module factory function accepts the following parameters:

class SimpleMonitoringModule {
    static forRoot({contextType, registerControllers, hasClusterMetrics}): DynamicModule;
}
  • platformType You can chose between grpc and express that automatically initialize request logging
  • registerController (default = true) allows you to disable metrics controllers completely
  • hasClusterMetrics (default = false) bootstraps the module in cluster mode

If you are using cluster, use the ClusterMonitoringModule

import {Module} from '@nestjs/common';
import {ClusterMonitoringModule} from '@betsys/nestjs-monitoring';

@Module({
    imports: [
        ClusterMonitoringModule.forRoot({ registerController: true}),
    ],
})
class AppModule {
}

You can use cluster only with express platform.

The forRoot module factory function accepts the following parameters:

class ClusterMonitoringModule {
    static forRoot({registerController}): DynamicModule;
}
  • registerController (default = true) allows you to disable metrics controllers completely

Creating your own metrics

To create your own metrics, just create new metrics object and call its methods to add new value to metric. You can use MonitoringConfig to resolve metrics name to add configured prefix.

For example, simple monitoring service:

import {Injectable} from '@nestjs/common';
import {
    MonitoringConfig,
    Counter,
    Gauge,
    InjectMonitoringConfig,
    InjectRegistry,
    MonitoringConfigInterface,
    Registry
} from '@betsys/nestjs-monitoring';

@Injectable()
export class WebsocketMonitoringService {
    private readonly messagesSent: Counter<string>;

    constructor(
        @InjectMonitoringConfig() private readonly config: MonitoringConfigInterface,
        @InjectMonitoringRegistry() private readonly registry: Registry,
    ) {
        this.messagesSent = new Counter({
            name: this.config.getMetricsName('websocket_messages_sent'),
            help: 'count of messages sent over websocket',
            labelNames: ['event'],
            registers: [registry]
        });
    }

    incrementMessagesSent(event: string): void {
        this.messagesSent.inc({event});
    }
}

To see complete list of options and metrics, check prom-client.

8.3.0

1 year ago

8.2.0

2 years ago

8.1.0

2 years ago

8.0.0

2 years ago

5.1.0

2 years ago

6.0.1

2 years ago

7.0.0

2 years ago

5.0.0

2 years ago

6.0.0

2 years ago

4.5.0

2 years ago

4.4.0

2 years ago

4.3.0

2 years ago

4.2.1

2 years ago

3.2.0

2 years ago

3.1.1

3 years ago

3.1.0

3 years ago

4.0.5

2 years ago

4.0.4

2 years ago

4.1.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.2.0

2 years ago

4.0.2

2 years ago

3.0.8

3 years ago

3.0.7

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago