auto commit
This commit is contained in:
parent
11341ce428
commit
435c758c1b
@ -16,7 +16,8 @@ NEXTAUTH_SECRET=wacefems-secret-work-in-progress-PPw09!keep!
|
|||||||
# Backend API
|
# Backend API
|
||||||
API_PORT=3001
|
API_PORT=3001
|
||||||
API_PREFIX=/api/v1
|
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_SECRET=wacefems-secret-work-in-progress-PPw09!keep
|
||||||
JWT_EXPIRES_IN=1d
|
JWT_EXPIRES_IN=1d
|
||||||
|
|
||||||
|
@ -27,7 +27,8 @@ NEXTAUTH_SECRET=wacefems-secret-work-in-progress-PPw09!keep!
|
|||||||
# Backend API
|
# Backend API
|
||||||
API_PORT=3001
|
API_PORT=3001
|
||||||
API_PREFIX=/api/v1
|
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_SECRET=wacefems-secret-work-in-progress-PPw09!keep
|
||||||
JWT_EXPIRES_IN=1d
|
JWT_EXPIRES_IN=1d
|
||||||
|
|
||||||
|
@ -1,29 +1,21 @@
|
|||||||
// src/services/system.service.js
|
// src/services/system.service.js
|
||||||
const Redis = require("ioredis");
|
|
||||||
const mongoose = require("mongoose");
|
|
||||||
const logger = require("../config/logger");
|
const logger = require("../config/logger");
|
||||||
const config = require("../config/config");
|
const os = require("os");
|
||||||
|
|
||||||
class SystemService {
|
class SystemService {
|
||||||
constructor() {
|
|
||||||
this.redis = new Redis(config.redis);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getSystemStatus() {
|
async getSystemStatus() {
|
||||||
try {
|
try {
|
||||||
// Redis 상태 체크
|
|
||||||
// const redisStatus = await this.checkRedisStatus();
|
|
||||||
|
|
||||||
// 데이터베이스 상태 체크
|
|
||||||
// const dbStatus = await this.checkDatabaseStatus();
|
|
||||||
|
|
||||||
// 서비스 상태 체크
|
// 서비스 상태 체크
|
||||||
const servicesStatus = await this.checkServicesStatus();
|
const servicesStatus = await this.checkServicesStatus();
|
||||||
|
|
||||||
|
// 시스템 리소스 상태 체크
|
||||||
|
const systemResources = this.checkSystemResources();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// database: dbStatus,
|
timestamp: new Date().toISOString(),
|
||||||
// redis: redisStatus,
|
status: "healthy",
|
||||||
services: servicesStatus,
|
services: servicesStatus,
|
||||||
|
system: systemResources,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Failed to get system status:", 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() {
|
async checkServicesStatus() {
|
||||||
// 필요한 서비스들의 상태 체크
|
// 필요한 서비스들의 상태 체크
|
||||||
const services = {
|
const services = {
|
||||||
@ -82,29 +34,34 @@ class SystemService {
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
async measureRedisLatency() {
|
checkSystemResources() {
|
||||||
const start = process.hrtime();
|
const totalMemory = os.totalmem();
|
||||||
await this.redis.ping();
|
const freeMemory = os.freemem();
|
||||||
const [seconds, nanoseconds] = process.hrtime(start);
|
const usedMemory = totalMemory - freeMemory;
|
||||||
return (seconds * 1000 + nanoseconds / 1000000).toFixed(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
async measureDatabaseLatency() {
|
return {
|
||||||
const start = process.hrtime();
|
cpu: {
|
||||||
await mongoose.connection.db.admin().ping();
|
loadAverage: os.loadavg(),
|
||||||
const [seconds, nanoseconds] = process.hrtime(start);
|
cores: os.cpus().length,
|
||||||
return (seconds * 1000 + nanoseconds / 1000000).toFixed(2);
|
},
|
||||||
|
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() {
|
async checkAPIStatus() {
|
||||||
return {
|
return {
|
||||||
status: "healthy",
|
status: "healthy",
|
||||||
uptime: process.uptime(),
|
uptime: this.formatUptime(process.uptime()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkSchedulerStatus() {
|
async checkSchedulerStatus() {
|
||||||
// 스케줄러 상태 체크 로직
|
|
||||||
return {
|
return {
|
||||||
status: "healthy",
|
status: "healthy",
|
||||||
lastRun: new Date().toISOString(),
|
lastRun: new Date().toISOString(),
|
||||||
@ -112,12 +69,42 @@ class SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async checkWorkerStatus() {
|
async checkWorkerStatus() {
|
||||||
// 워커 상태 체크 로직
|
|
||||||
return {
|
return {
|
||||||
status: "healthy",
|
status: "healthy",
|
||||||
activeWorkers: 0,
|
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();
|
module.exports = new SystemService();
|
||||||
|
Loading…
Reference in New Issue
Block a user