@galaxy-stack/orbit-terminus
v0.1.9
Published
Health check module for Orbit framework
Readme
@galaxy-stack/orbit-terminus
Mô tả
Module Health Check cho Orbit, giúp kiểm tra tình trạng của ứng dụng và các dependencies.
Tính năng chính
1. Health Indicators
- MemoryHealthIndicator: Kiểm tra memory usage
- HttpHealthIndicator: Kiểm tra external HTTP services
- DatabaseHealthIndicator: Kiểm tra database connection
2. Health Check Service
import { HealthCheckService } from '@galaxy-stack/orbit-terminus';
class HealthController {
constructor(
private health: HealthCheckService,
private memory: MemoryHealthIndicator,
private db: DatabaseHealthIndicator,
) {}
@Get('health')
async check() {
return this.health.check('app', [
() => this.memory.checkHeap('memory', { heapUsedThreshold: 150 * 1024 * 1024 }),
() => this.db.pingCheck('database', this.dataSource),
]);
}
}Cấu hình Module
import { TerminusModule } from '@galaxy-stack/orbit-terminus';
@Module({
imports: [TerminusModule.forRoot()],
controllers: [HealthController],
})
class AppModule {}Health Indicators
Memory Check
@Get('health')
async check() {
return this.health.check('app', [
() => this.memory.checkHeap('memory_heap', {
heapUsedThreshold: 150 * 1024 * 1024, // 150MB
}),
() => this.memory.checkRSS('memory_rss', {
rssThreshold: 300 * 1024 * 1024, // 300MB
}),
]);
}HTTP Check
() => this.http.pingCheck('google', 'https://google.com', {
timeout: 5000,
expectedStatus: 200,
})Database Check
() => this.db.pingCheck('database', dataSource, 5000)Response Format
Healthy
{
"status": "ok",
"info": {
"memory": { "status": "up", "details": { "heapUsed": "50.25 MB" } },
"database": { "status": "up", "details": { "responseTime": "5ms" } }
},
"details": {
"memory": { "status": "up" },
"database": { "status": "up" }
}
}Unhealthy
{
"status": "error",
"error": {
"database": { "status": "down", "message": "Connection refused" }
},
"details": {
"memory": { "status": "up" },
"database": { "status": "down" }
}
}Graceful Shutdown
import { HealthCheckService } from '@galaxy-stack/orbit-terminus';
// Đánh dấu app đang shutdown
healthService.setShuttingDown();
// Response sẽ trả về
{
"status": "shutting_down",
"details": {}
}Use Cases
- Kubernetes liveness/readiness probes
- Load balancer health checks
- Monitoring systems
- Service mesh integration
