feat: TPS/MSPT/메모리 성능 모니터링 API 추가
- ServerStatus에 tps, mspt, memoryUsedMb, memoryMaxMb 필드 추가 - getMspt() 함수 구현 (averageTickTimeNanos 기반) - getTps()를 mspt 기반으로 리팩토링
This commit is contained in:
parent
d4faf31b73
commit
f9fa94bf38
2 changed files with 36 additions and 0 deletions
|
|
@ -22,6 +22,10 @@ class ServerDataCollector {
|
||||||
/** 전체 서버 상태 수집 */
|
/** 전체 서버 상태 수집 */
|
||||||
fun collectStatus(): ServerStatus {
|
fun collectStatus(): ServerStatus {
|
||||||
val server = getServer()
|
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(
|
return ServerStatus(
|
||||||
online = server != null,
|
online = server != null,
|
||||||
|
|
@ -29,12 +33,40 @@ class ServerDataCollector {
|
||||||
modLoader = getModLoaderInfo(),
|
modLoader = getModLoaderInfo(),
|
||||||
difficulty = getDifficulty(),
|
difficulty = getDifficulty(),
|
||||||
uptimeMinutes = getUptimeMinutes(),
|
uptimeMinutes = getUptimeMinutes(),
|
||||||
|
tps = getTps(mspt),
|
||||||
|
mspt = mspt,
|
||||||
|
memoryUsedMb = memoryUsedMb,
|
||||||
|
memoryMaxMb = memoryMaxMb,
|
||||||
players = getPlayersInfo(),
|
players = getPlayersInfo(),
|
||||||
gameRules = getGameRules(),
|
gameRules = getGameRules(),
|
||||||
mods = getModsList()
|
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 {
|
private fun getMinecraftVersion(): String {
|
||||||
return try {
|
return try {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@ data class ServerStatus(
|
||||||
val modLoader: String,
|
val modLoader: String,
|
||||||
val difficulty: String,
|
val difficulty: String,
|
||||||
val uptimeMinutes: Long,
|
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 players: PlayersInfo,
|
||||||
val gameRules: Map<String, Boolean>,
|
val gameRules: Map<String, Boolean>,
|
||||||
val mods: List<ModInfo>
|
val mods: List<ModInfo>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue