auto commit

This commit is contained in:
bangdk 2024-11-10 09:27:53 +09:00
parent 11341ce428
commit 435c758c1b
3 changed files with 60 additions and 71 deletions

View File

@ -16,7 +16,8 @@ NEXTAUTH_SECRET=wacefems-secret-work-in-progress-PPw09!keep!
# Backend API
API_PORT=3001
API_PREFIX=/api/v1
CORS_ORIGIN=http://localhost:3002,http://localhost:3003
# CORS_ORIGIN=http://localhost:3002,http://localhost:3003
CORS_ORIGIN=*
JWT_SECRET=wacefems-secret-work-in-progress-PPw09!keep
JWT_EXPIRES_IN=1d

View File

@ -27,7 +27,8 @@ NEXTAUTH_SECRET=wacefems-secret-work-in-progress-PPw09!keep!
# Backend API
API_PORT=3001
API_PREFIX=/api/v1
CORS_ORIGIN=https://${DOMAIN},https://www.admin.${DOMAIN}
# CORS_ORIGIN=https://${DOMAIN},https://www.admin.${DOMAIN}
CORS_ORIGIN=*
JWT_SECRET=wacefems-secret-work-in-progress-PPw09!keep
JWT_EXPIRES_IN=1d

View File

@ -1,29 +1,21 @@
// src/services/system.service.js
const Redis = require("ioredis");
const mongoose = require("mongoose");
const logger = require("../config/logger");
const config = require("../config/config");
const os = require("os");
class SystemService {
constructor() {
this.redis = new Redis(config.redis);
}
async getSystemStatus() {
try {
// Redis 상태 체크
// const redisStatus = await this.checkRedisStatus();
// 데이터베이스 상태 체크
// const dbStatus = await this.checkDatabaseStatus();
// 서비스 상태 체크
const servicesStatus = await this.checkServicesStatus();
// 시스템 리소스 상태 체크
const systemResources = this.checkSystemResources();
return {
// database: dbStatus,
// redis: redisStatus,
timestamp: new Date().toISOString(),
status: "healthy",
services: servicesStatus,
system: systemResources,
};
} catch (error) {
logger.error("Failed to get system status:", error);
@ -31,46 +23,6 @@ class SystemService {
}
}
// async checkRedisStatus() {
// try {
// await this.redis.ping();
// return {
// status: "healthy",
// latency: await this.measureRedisLatency(),
// };
// } catch (error) {
// logger.error("Redis health check failed:", error);
// return {
// status: "unhealthy",
// error: error.message,
// };
// }
// }
// async checkDatabaseStatus() {
// try {
// const status = mongoose.connection.readyState;
// const statusMap = {
// 0: "disconnected",
// 1: "connected",
// 2: "connecting",
// 3: "disconnecting",
// };
// return {
// status: status === 1 ? "healthy" : "unhealthy",
// state: statusMap[status],
// latency: await this.measureDatabaseLatency(),
// };
// } catch (error) {
// logger.error("Database health check failed:", error);
// return {
// status: "unhealthy",
// error: error.message,
// };
// }
// }
async checkServicesStatus() {
// 필요한 서비스들의 상태 체크
const services = {
@ -82,29 +34,34 @@ class SystemService {
return services;
}
async measureRedisLatency() {
const start = process.hrtime();
await this.redis.ping();
const [seconds, nanoseconds] = process.hrtime(start);
return (seconds * 1000 + nanoseconds / 1000000).toFixed(2);
}
checkSystemResources() {
const totalMemory = os.totalmem();
const freeMemory = os.freemem();
const usedMemory = totalMemory - freeMemory;
async measureDatabaseLatency() {
const start = process.hrtime();
await mongoose.connection.db.admin().ping();
const [seconds, nanoseconds] = process.hrtime(start);
return (seconds * 1000 + nanoseconds / 1000000).toFixed(2);
return {
cpu: {
loadAverage: os.loadavg(),
cores: os.cpus().length,
},
memory: {
total: this.formatBytes(totalMemory),
used: this.formatBytes(usedMemory),
free: this.formatBytes(freeMemory),
usagePercent: ((usedMemory / totalMemory) * 100).toFixed(2),
},
uptime: this.formatUptime(os.uptime()),
};
}
async checkAPIStatus() {
return {
status: "healthy",
uptime: process.uptime(),
uptime: this.formatUptime(process.uptime()),
};
}
async checkSchedulerStatus() {
// 스케줄러 상태 체크 로직
return {
status: "healthy",
lastRun: new Date().toISOString(),
@ -112,12 +69,42 @@ class SystemService {
}
async checkWorkerStatus() {
// 워커 상태 체크 로직
return {
status: "healthy",
activeWorkers: 0,
};
}
formatBytes(bytes) {
const units = ["B", "KB", "MB", "GB", "TB"];
let value = bytes;
let unitIndex = 0;
while (value >= 1024 && unitIndex < units.length - 1) {
value /= 1024;
unitIndex++;
}
return {
value: value.toFixed(2),
unit: units[unitIndex],
};
}
formatUptime(seconds) {
const days = Math.floor(seconds / 86400);
const hours = Math.floor((seconds % 86400) / 3600);
const minutes = Math.floor(((seconds % 86400) % 3600) / 60);
const remainingSeconds = Math.floor(((seconds % 86400) % 3600) % 60);
return {
days,
hours,
minutes,
seconds: remainingSeconds,
formatted: `${days}d ${hours}h ${minutes}m ${remainingSeconds}s`,
};
}
}
module.exports = new SystemService();