操作
バグ #341
未完了Monitoring-1: ヘルスチェック・性能監視 (4h)
ステータス:
新規
優先度:
高め
担当者:
-
開始日:
2025-06-07
期日:
進捗率:
0%
予定工数:
説明
ヘルスチェックシステムと統合監視機能を実装する。
実装内容¶
総合ヘルスチェック¶
class HealthCheckManager {
async performHealthCheck(): Promise<HealthStatus> {
const checks = await Promise.allSettled([
this.checkOAuthService(),
this.checkSSHConnections(),
this.checkRedisConnection(),
this.checkDockerHosts(),
this.checkRedmineAPI(),
this.checkSSLCertificate(),
this.checkDiskSpace(),
this.checkMemoryUsage()
]);
const results = checks.map((check, index) => ({
service: this.serviceNames[index],
status: check.status === 'fulfilled' ? 'healthy' : 'unhealthy',
details: check.status === 'fulfilled' ? check.value : check.reason
}));
return {
overall: results.every(r => r.status === 'healthy') ? 'healthy' : 'degraded',
services: results,
timestamp: new Date().toISOString()
};
}
private async checkSSHConnections(): Promise<any> {
const hosts = ['85.131.243.51', '160.251.155.93'];
const results = [];
for (const host of hosts) {
try {
await this.sshManager.execute('health', host, 'echo "health-check"', 5000);
results.push({ host, status: 'healthy' });
} catch (error) {
results.push({ host, status: 'unhealthy', error: error.message });
}
}
return results;
}
}
パフォーマンス監視¶
class PerformanceMonitor {
async collectMetrics() {
const metrics = {
response_times: await this.measureResponseTimes(),
memory_usage: process.memoryUsage(),
cpu_usage: await this.getCPUUsage(),
active_connections: {
ssh: this.sshManager.getActiveConnections(),
redis: await this.redis.info('clients'),
oauth_sessions: await this.getActiveSessions()
},
error_rates: await this.calculateErrorRates()
};
// メトリクスをRedisに保存(24時間保持)
await this.redis.setex(
`metrics:${Date.now()}`,
24 * 60 * 60,
JSON.stringify(metrics)
);
// 閾値チェック・アラート
await this.checkThresholds(metrics);
return metrics;
}
private async checkThresholds(metrics: any) {
// メモリ使用量チェック
if (metrics.memory_usage.heapUsed > 500 * 1024 * 1024) { // 500MB
await this.auditLogger.log({
userId: 'system',
action: 'high_memory_usage',
severity: 'medium',
details: metrics.memory_usage
});
}
// レスポンス時間チェック
if (metrics.response_times.average > 5000) { // 5秒
await this.auditLogger.log({
userId: 'system',
action: 'slow_response_time',
severity: 'high',
details: metrics.response_times
});
}
}
}
成果物¶
- 総合ヘルスチェック機能
- パフォーマンス監視システム
- 自動アラート機能
作業時間: 4時間¶
依存: Security-3完了¶
表示するデータがありません
操作