Skip to content

Commit 7f5f195

Browse files
committed
Enable all configuration except authentication
1 parent e87d1bc commit 7f5f195

12 files changed

+160
-42
lines changed

examples/test-status-monitor/src/app.module.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,59 @@ import { Module } from '@nestjs/common';
22
import { AppController } from './app.controller';
33
import { AppService } from './app.service';
44
import { StatusMonitorModule } from '../../../dist/status.monitor.module';
5+
import { StatusMonitorConfiguration } from '../../../dist/config/status.monitor.configuration';
56
import { HealtController } from './healtController';
67

8+
const statusMonitorConfig: StatusMonitorConfiguration = {
9+
pageTitle: 'Nest.js Monitoring Page',
10+
port: 3001,
11+
path: 'status',
12+
theme: 'default.css',
13+
ignoreStartsWith: '',
14+
healthChecks: [
15+
{
16+
protocol: 'http',
17+
host: 'localhost',
18+
path: '/healt/alive',
19+
port: 3001,
20+
},
21+
{
22+
protocol: 'http',
23+
host: 'localhost',
24+
path: '/healt/dead',
25+
port: 3001,
26+
},
27+
],
28+
spans: [
29+
{
30+
interval: 1, // Every second
31+
retention: 60, // Keep 60 datapoints in memory
32+
},
33+
{
34+
interval: 5, // Every 5 seconds
35+
retention: 60,
36+
},
37+
{
38+
interval: 15, // Every 15 seconds
39+
retention: 60,
40+
},
41+
{
42+
interval: 60, // Every 60 seconds
43+
retention: 600,
44+
},
45+
],
46+
chartVisibility: {
47+
cpu: true,
48+
mem: true,
49+
load: true,
50+
responseTime: true,
51+
rps: true,
52+
statusCodes: true,
53+
},
54+
};
55+
756
@Module({
8-
imports: [StatusMonitorModule],
57+
imports: [StatusMonitorModule.setUp(statusMonitorConfig)],
958
controllers: [AppController, HealtController],
1059
providers: [AppService],
1160
})

examples/test-status-monitor/src/main.hmr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare const module: any;
55

66
async function bootstrap() {
77
const app = await NestFactory.create(AppModule);
8-
await app.listen(3000);
8+
await app.listen(3001);
99

1010
if (module.hot) {
1111
module.hot.accept();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface ChartVisibilityConfiguration {
2+
cpu: boolean;
3+
mem: boolean;
4+
load: boolean;
5+
responseTime: boolean;
6+
rps: boolean;
7+
statusCodes: boolean;
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface HealthCheckConfiguration {
2+
protocol: string;
3+
host: string;
4+
path: string;
5+
port: number;
6+
}

src/config/spans.configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface SpansConfiguration {
2+
interval: number;
3+
retention: number;
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { HealthCheckConfiguration } from './health.check.configuration';
2+
import { SpansConfiguration } from './spans.configuration';
3+
import { ChartVisibilityConfiguration } from './chart.visibility.configuration';
4+
5+
export interface StatusMonitorConfiguration {
6+
path: string;
7+
port: number;
8+
pageTitle: string;
9+
theme: string;
10+
ignoreStartsWith: string;
11+
healthChecks: HealthCheckConfiguration[];
12+
spans: SpansConfiguration[];
13+
chartVisibility: ChartVisibilityConfiguration;
14+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Injectable, Inject, forwardRef } from '@nestjs/common';
1+
import { Injectable } from '@nestjs/common';
22
import axios from 'axios';
33

44
@Injectable()
5-
export class HealtCheckService {
5+
export class HealthCheckService {
66
healthChecks = [
77
{
88
protocol: 'http',

src/status.monitor.constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const STATUS_MONITOR_OPTIONS_PROVIDER =
2+
'STATUS_MONITOR_OPTIONS_PROVIDER';

src/status.monitor.controller.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1-
import { Get, Controller, HttpCode } from '@nestjs/common';
1+
import { Get, Controller, HttpCode, Inject } from '@nestjs/common';
22
import * as fs from 'fs';
33
import * as path from 'path';
44
import Handlebars from 'handlebars';
5-
import { HealtCheckService } from './healt.check.service';
5+
import { HealthCheckService } from './health.check.service';
6+
import { PATH_METADATA } from '@nestjs/common/constants';
7+
import { STATUS_MONITOR_OPTIONS_PROVIDER } from './status.monitor.constants';
8+
import { StatusMonitorConfiguration } from './config/status.monitor.configuration';
69

7-
const controllerPath = 'monitor';
8-
9-
@Controller(controllerPath)
10+
@Controller()
1011
export class StatusMonitorController {
1112
data;
1213
render;
1314

14-
constructor(private readonly healtCheckService: HealtCheckService) {
15+
constructor(
16+
private readonly healtCheckService: HealthCheckService,
17+
@Inject(STATUS_MONITOR_OPTIONS_PROVIDER)
18+
private readonly config: StatusMonitorConfiguration,
19+
) {
20+
const bodyClasses = Object.keys(config.chartVisibility)
21+
.reduce((accumulator, key) => {
22+
if (config.chartVisibility[key] === false) {
23+
accumulator.push(`hide-${key}`);
24+
}
25+
return accumulator;
26+
}, [])
27+
.join(' ');
28+
1529
this.data = {
16-
title: 'Nest.js Status',
17-
port: 3001,
18-
bodyClasses: '',
30+
title: config.pageTitle,
31+
port: config.port,
32+
bodyClasses: bodyClasses,
1933
script: fs.readFileSync(
2034
path.join(__dirname, '../src/public/javascripts/app.js'),
2135
),
@@ -31,6 +45,11 @@ export class StatusMonitorController {
3145
this.render = Handlebars.compile(htmlTmpl, { strict: true });
3246
}
3347

48+
public static forRoot(rootPath: string = 'monitor') {
49+
Reflect.defineMetadata(PATH_METADATA, rootPath, StatusMonitorController);
50+
return StatusMonitorController;
51+
}
52+
3453
@Get()
3554
@HttpCode(200)
3655
async root() {

src/status.monitor.gateway.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
SubscribeMessage,
33
WebSocketGateway,
44
WebSocketServer,
5-
WsResponse,
65
OnGatewayConnection,
76
} from '@nestjs/websockets';
87
import { StatusMonitoringService } from './status.monitoring.service';

0 commit comments

Comments
 (0)