added health check

This commit is contained in:
hannathkadher
2025-04-24 12:22:03 +04:00
parent 2594c1229b
commit 9844e13f42
3 changed files with 36 additions and 0 deletions

View File

@ -4,8 +4,10 @@ import { TerminusModule } from '@nestjs/terminus';
import { TypeOrmModule } from '@nestjs/typeorm';
import { HealthController } from './controllers';
import { HttpModule } from '@nestjs/axios';
import { HealthService } from './services';
@Module({
imports: [TerminusModule, HttpModule, TypeOrmModule],
controllers: [HealthController],
providers: [HealthService],
})
export class HealthModule {}

View 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),
]);
}
}

View File

@ -0,0 +1 @@
export * from './health.service';