Files
esg/src/health/health.controller.ts
T

41 lines
1.1 KiB
TypeScript

import { Controller, Get } from '@nestjs/common';
import {
DiskHealthIndicator,
HealthCheck,
HealthCheckService,
MemoryHealthIndicator,
TypeOrmHealthIndicator,
} from '@nestjs/terminus';
import { HealthService } from './health.service';
@Controller('health')
export class HealthController {
constructor(
private readonly health: HealthCheckService,
private readonly database: TypeOrmHealthIndicator,
private readonly memory: MemoryHealthIndicator,
private readonly disk: DiskHealthIndicator,
private readonly healthService: HealthService,
) {}
@Get('live')
@HealthCheck({ swaggerDocumentation: false })
liveness() {
return this.health.check([]);
}
@Get('ready')
@HealthCheck({ swaggerDocumentation: false })
readiness() {
return this.health.check([
() => this.database.pingCheck('postgres', { timeout: 1000 }),
() => this.memory.checkHeap('memory_heap', this.healthService.heapThresholdBytes()),
() =>
this.disk.checkStorage('disk', {
path: this.healthService.diskPath(),
thresholdPercent: this.healthService.diskThresholdPercent(),
}),
]);
}
}