mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 07:34:54 +00:00
added health check
This commit is contained in:
@ -12,7 +12,7 @@ import { UserNotificationModule } from './user-notification/user-notification.mo
|
||||
import { DeviceMessagesSubscriptionModule } from './device-messages/device-messages.module';
|
||||
import { SceneModule } from './scene/scene.module';
|
||||
import { DoorLockModule } from './door-lock/door.lock.module';
|
||||
import { APP_INTERCEPTOR } from '@nestjs/core';
|
||||
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
|
||||
import { LoggingInterceptor } from './interceptors/logging.interceptor';
|
||||
import { AutomationModule } from './automation/automation.module';
|
||||
import { RegionModule } from './region/region.module';
|
||||
@ -34,11 +34,17 @@ import { DeviceCommissionModule } from './commission-device/commission-device.mo
|
||||
import { PowerClampModule } from './power-clamp/power-clamp.module';
|
||||
import { WinstonModule } from 'nest-winston';
|
||||
import { winstonLoggerOptions } from './common/filters/http-exception/logger/winston.logger';
|
||||
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
|
||||
import { HealthModule } from './health/health.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
load: config,
|
||||
}),
|
||||
ThrottlerModule.forRoot({
|
||||
throttlers: [{ ttl: 60000, limit: 10 }],
|
||||
}),
|
||||
WinstonModule.forRoot(winstonLoggerOptions),
|
||||
ClientModule,
|
||||
AuthenticationModule,
|
||||
@ -70,12 +76,17 @@ import { winstonLoggerOptions } from './common/filters/http-exception/logger/win
|
||||
TagModule,
|
||||
DeviceCommissionModule,
|
||||
PowerClampModule,
|
||||
HealthModule,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: APP_INTERCEPTOR,
|
||||
useClass: LoggingInterceptor,
|
||||
},
|
||||
{
|
||||
provide: APP_GUARD,
|
||||
useClass: ThrottlerGuard,
|
||||
},
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
35
src/health/controllers/health.controller.ts
Normal file
35
src/health/controllers/health.controller.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import {
|
||||
HealthCheck,
|
||||
HealthCheckService,
|
||||
TypeOrmHealthIndicator,
|
||||
DiskHealthIndicator,
|
||||
MemoryHealthIndicator,
|
||||
HttpHealthIndicator,
|
||||
} from '@nestjs/terminus';
|
||||
|
||||
@Controller('health')
|
||||
export class HealthController {
|
||||
constructor(
|
||||
private health: HealthCheckService,
|
||||
private db: TypeOrmHealthIndicator,
|
||||
private memory: MemoryHealthIndicator,
|
||||
private disk: DiskHealthIndicator,
|
||||
private http: HttpHealthIndicator,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@HealthCheck()
|
||||
check() {
|
||||
return this.health.check([
|
||||
() => this.db.pingCheck('database'),
|
||||
() =>
|
||||
this.disk.checkStorage('disk', {
|
||||
thresholdPercent: 0.9,
|
||||
path: '/',
|
||||
}),
|
||||
() => this.memory.checkHeap('memory_heap', 300 * 1024 * 1024),
|
||||
() => this.http.pingCheck('tuya', 'https://openapi.tuya.com'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
1
src/health/controllers/index.ts
Normal file
1
src/health/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './health.controller';
|
||||
11
src/health/health.module.ts
Normal file
11
src/health/health.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
// src/health/health.module.ts
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TerminusModule } from '@nestjs/terminus';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { HealthController } from './controllers';
|
||||
|
||||
@Module({
|
||||
imports: [TerminusModule, TypeOrmModule],
|
||||
controllers: [HealthController],
|
||||
})
|
||||
export class HealthModule {}
|
||||
Reference in New Issue
Block a user