mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
added health check
This commit is contained in:
@ -4,8 +4,10 @@ import { TerminusModule } from '@nestjs/terminus';
|
|||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { HealthController } from './controllers';
|
import { HealthController } from './controllers';
|
||||||
import { HttpModule } from '@nestjs/axios';
|
import { HttpModule } from '@nestjs/axios';
|
||||||
|
import { HealthService } from './services';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TerminusModule, HttpModule, TypeOrmModule],
|
imports: [TerminusModule, HttpModule, TypeOrmModule],
|
||||||
controllers: [HealthController],
|
controllers: [HealthController],
|
||||||
|
providers: [HealthService],
|
||||||
})
|
})
|
||||||
export class HealthModule {}
|
export class HealthModule {}
|
||||||
|
33
src/health/services/health.service.ts
Normal file
33
src/health/services/health.service.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
HealthCheckService,
|
||||||
|
TypeOrmHealthIndicator,
|
||||||
|
DiskHealthIndicator,
|
||||||
|
MemoryHealthIndicator,
|
||||||
|
HttpHealthIndicator,
|
||||||
|
HealthCheckResult,
|
||||||
|
} from '@nestjs/terminus';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class HealthService {
|
||||||
|
constructor(
|
||||||
|
private health: HealthCheckService,
|
||||||
|
private db: TypeOrmHealthIndicator,
|
||||||
|
private memory: MemoryHealthIndicator,
|
||||||
|
private disk: DiskHealthIndicator,
|
||||||
|
private http: HttpHealthIndicator,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
check(): Promise<HealthCheckResult> {
|
||||||
|
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', process.env.TUYA_EU_URL),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
1
src/health/services/index.ts
Normal file
1
src/health/services/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './health.service';
|
Reference in New Issue
Block a user