diff --git a/ServerStatus/src/main/kotlin/co/caadiq/serverstatus/data/ServerDataCollector.kt b/ServerStatus/src/main/kotlin/co/caadiq/serverstatus/data/ServerDataCollector.kt index db1bb9c..ed9227a 100644 --- a/ServerStatus/src/main/kotlin/co/caadiq/serverstatus/data/ServerDataCollector.kt +++ b/ServerStatus/src/main/kotlin/co/caadiq/serverstatus/data/ServerDataCollector.kt @@ -22,6 +22,10 @@ class ServerDataCollector { /** 전체 서버 상태 수집 */ fun collectStatus(): ServerStatus { val server = getServer() + val runtime = Runtime.getRuntime() + val memoryUsedMb = (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024 + val memoryMaxMb = runtime.maxMemory() / 1024 / 1024 + val mspt = getMspt(server) return ServerStatus( online = server != null, @@ -29,12 +33,40 @@ class ServerDataCollector { modLoader = getModLoaderInfo(), difficulty = getDifficulty(), uptimeMinutes = getUptimeMinutes(), + tps = getTps(mspt), + mspt = mspt, + memoryUsedMb = memoryUsedMb, + memoryMaxMb = memoryMaxMb, players = getPlayersInfo(), gameRules = getGameRules(), mods = getModsList() ) } + /** MSPT (Milliseconds Per Tick) 계산 */ + private fun getMspt(server: MinecraftServer?): Double { + if (server == null) return 0.0 + return try { + val averageTickTimeNs = server.averageTickTimeNanos + val mspt = averageTickTimeNs / 1_000_000.0 + "%.2f".format(mspt).toDouble() + } catch (e: Exception) { + 0.0 + } + } + + /** TPS (Ticks Per Second) 계산 */ + private fun getTps(mspt: Double): Double { + if (mspt <= 0) return 20.0 + return try { + // TPS = 1000ms / msPerTick, 최대 20 + val tps = 1000.0 / mspt + minOf(tps, 20.0).let { "%.1f".format(it).toDouble() } + } catch (e: Exception) { + 20.0 + } + } + /** 마인크래프트 버전 */ private fun getMinecraftVersion(): String { return try { diff --git a/ServerStatus/src/main/kotlin/co/caadiq/serverstatus/network/MessageTypes.kt b/ServerStatus/src/main/kotlin/co/caadiq/serverstatus/network/MessageTypes.kt index b0aabd3..7fe3ba0 100644 --- a/ServerStatus/src/main/kotlin/co/caadiq/serverstatus/network/MessageTypes.kt +++ b/ServerStatus/src/main/kotlin/co/caadiq/serverstatus/network/MessageTypes.kt @@ -10,6 +10,10 @@ data class ServerStatus( val modLoader: String, val difficulty: String, val uptimeMinutes: Long, + val tps: Double, // TPS (Ticks Per Second) + val mspt: Double, // MSPT (Milliseconds Per Tick) + val memoryUsedMb: Long, // 사용 중인 메모리 (MB) + val memoryMaxMb: Long, // 최대 메모리 (MB) val players: PlayersInfo, val gameRules: Map, val mods: List