From 87da6ee3bab9ed0d15803144746b89255c98529b Mon Sep 17 00:00:00 2001
From: mobius <8391001+MobiusDevelopment@users.noreply.github.com>
Date: Fri, 2 Jan 2015 14:09:41 +0000
Subject: [PATCH] Admin server info menu.
---
trunk/dist/game/config/adminCommands.xml | 3 +
.../dist/game/data/html/admin/server_menu.htm | 1 +
.../dist/game/data/html/admin/serverinfo.htm | 105 +++++++++++
.../data/scripts/handlers/MasterHandler.java | 2 +
.../admincommandhandlers/AdminServerInfo.java | 176 ++++++++++++++++++
.../gameserver/ThreadPoolManager.java | 95 ++++++++++
6 files changed, 382 insertions(+)
create mode 100644 trunk/dist/game/data/html/admin/serverinfo.htm
create mode 100644 trunk/dist/game/data/scripts/handlers/admincommandhandlers/AdminServerInfo.java
diff --git a/trunk/dist/game/config/adminCommands.xml b/trunk/dist/game/config/adminCommands.xml
index 3768ca09f3..da71b2db68 100644
--- a/trunk/dist/game/config/adminCommands.xml
+++ b/trunk/dist/game/config/adminCommands.xml
@@ -589,6 +589,9 @@
+
+
+
diff --git a/trunk/dist/game/data/html/admin/server_menu.htm b/trunk/dist/game/data/html/admin/server_menu.htm
index 124a04c339..672de155d8 100644
--- a/trunk/dist/game/data/html/admin/server_menu.htm
+++ b/trunk/dist/game/data/html/admin/server_menu.htm
@@ -35,6 +35,7 @@ Development:
|
|
+ |
|
diff --git a/trunk/dist/game/data/html/admin/serverinfo.htm b/trunk/dist/game/data/html/admin/serverinfo.htm
new file mode 100644
index 0000000000..83519c879d
--- /dev/null
+++ b/trunk/dist/game/data/html/admin/serverinfo.htm
@@ -0,0 +1,105 @@
+Admin Server Info
+
+
+
+
+General:
+
+
+ OS: |
+ %os_name% |
+
+
+ OS version: |
+ %os_ver% |
+
+
+ Server slots: |
+ %slots% |
+
+
+ Server UpTime: |
+ %serverUpTime% |
+
+
+ Server Time: |
+ %serverTime% |
+
+
+ Game Time: |
+ %gameTime% (%dayNight%) |
+
+
+ Geodata: |
+ %geodata% |
+
+
+
+Players:
+
+
+ Total players count: |
+ %onlineAll% |
+
+
+ Offline trade count: |
+ %offlineTrade% |
+
+
+ Online GM count: |
+ %onlineGM% |
+
+
+ Real player count: |
+ %onlineReal% |
+
+
+
+Memory:
+
+
+ Used Memory: |
+ %usedMem% MB |
+
+
+ Free Memory: |
+ %freeMem% MB |
+
+
+ Total Memory: |
+ %totalMem% MB |
+
+
+
+Thread - General (STP):
+ %theardInfoGen%
+
+Thread - Effects (STP):
+ %theardInfoEff%
+
+Thread - AI (STP):
+ %theardInfoAi%
+
+Thread - Event (STP):
+ %theardInfoEvent%
+
+Thread - Packets (TP):
+ %theardInfoPack%
+
+Thread - I/O Packets (TP):
+ %theardInfoIOPack%
+
+Thread - General Tasks (TP):
+ %theardInfoGenTask%
+
+Thread - Event Tasks (TP):
+ %theardInfoEvnTask%
+
+
+
\ No newline at end of file
diff --git a/trunk/dist/game/data/scripts/handlers/MasterHandler.java b/trunk/dist/game/data/scripts/handlers/MasterHandler.java
index c85a69924e..92ee334486 100644
--- a/trunk/dist/game/data/scripts/handlers/MasterHandler.java
+++ b/trunk/dist/game/data/scripts/handlers/MasterHandler.java
@@ -112,6 +112,7 @@ import handlers.admincommandhandlers.AdminRepairChar;
import handlers.admincommandhandlers.AdminRes;
import handlers.admincommandhandlers.AdminRide;
import handlers.admincommandhandlers.AdminScan;
+import handlers.admincommandhandlers.AdminServerInfo;
import handlers.admincommandhandlers.AdminShop;
import handlers.admincommandhandlers.AdminShowQuests;
import handlers.admincommandhandlers.AdminShutdown;
@@ -378,6 +379,7 @@ public class MasterHandler
AdminRes.class,
AdminRide.class,
AdminScan.class,
+ AdminServerInfo.class,
AdminShop.class,
AdminShowQuests.class,
AdminShutdown.class,
diff --git a/trunk/dist/game/data/scripts/handlers/admincommandhandlers/AdminServerInfo.java b/trunk/dist/game/data/scripts/handlers/admincommandhandlers/AdminServerInfo.java
new file mode 100644
index 0000000000..960e672486
--- /dev/null
+++ b/trunk/dist/game/data/scripts/handlers/admincommandhandlers/AdminServerInfo.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2004-2014 L2J DataPack
+ *
+ * This file is part of L2J DataPack.
+ *
+ * L2J DataPack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * L2J DataPack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package handlers.admincommandhandlers;
+
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import javolution.text.TextBuilder;
+
+import com.l2jserver.Config;
+import com.l2jserver.gameserver.GameServer;
+import com.l2jserver.gameserver.GameTimeController;
+import com.l2jserver.gameserver.ThreadPoolManager;
+import com.l2jserver.gameserver.cache.HtmCache;
+import com.l2jserver.gameserver.handler.IAdminCommandHandler;
+import com.l2jserver.gameserver.model.L2World;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
+
+/**
+ * @author St3eT
+ */
+public class AdminServerInfo implements IAdminCommandHandler
+{
+ private static final SimpleDateFormat fmt = new SimpleDateFormat("hh:mm a");
+
+ private static final String[] ADMIN_COMMANDS =
+ {
+ "admin_serverinfo"
+ };
+
+ @Override
+ public boolean useAdminCommand(String command, L2PcInstance activeChar)
+ {
+ if (command.equals("admin_serverinfo"))
+ {
+ final NpcHtmlMessage html = new NpcHtmlMessage();
+ final Runtime RunTime = Runtime.getRuntime();
+ final int mb = 1024 * 1024;
+ html.setHtml(HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/serverinfo.htm"));
+
+ html.replace("%os_name%", System.getProperty("os.name"));
+ html.replace("%os_ver%", System.getProperty("os.version"));
+ html.replace("%slots%", getPlayersCount("ALL") + "/" + Config.MAXIMUM_ONLINE_USERS);
+ html.replace("%gameTime%", GameTimeController.getInstance().getGameHour() + ":" + GameTimeController.getInstance().getGameMinute());
+ html.replace("%dayNight%", GameTimeController.getInstance().isNight() ? "Night" : "Day");
+ html.replace("%geodata%", Config.GEODATA > 0 ? "Enabled" : "Disabled");
+ html.replace("%serverTime%", fmt.format(new Date(System.currentTimeMillis())));
+ html.replace("%serverUpTime%", getServerUpTime());
+ html.replace("%onlineAll%", getPlayersCount("ALL"));
+ html.replace("%offlineTrade%", getPlayersCount("OFF_TRADE"));
+ html.replace("%onlineGM%", getPlayersCount("GM"));
+ html.replace("%onlineReal%", getPlayersCount("ALL_REAL"));
+ html.replace("%usedMem%", (RunTime.maxMemory() / mb) - (((RunTime.maxMemory() - RunTime.totalMemory()) + RunTime.freeMemory()) / mb));
+ html.replace("%freeMem%", ((RunTime.maxMemory() - RunTime.totalMemory()) + RunTime.freeMemory()) / mb);
+ html.replace("%totalMem%", Runtime.getRuntime().maxMemory() / 1048576);
+ html.replace("%theardInfoGen%", buildTheardInfo("GENERAL"));
+ html.replace("%theardInfoEff%", buildTheardInfo("EFFECTS"));
+ html.replace("%theardInfoAi%", buildTheardInfo("AI"));
+ html.replace("%theardInfoEvent%", buildTheardInfo("EVENT"));
+ html.replace("%theardInfoPack%", buildTheardInfo("PACKETS"));
+ html.replace("%theardInfoIOPack%", buildTheardInfo("IOPACKETS"));
+ html.replace("%theardInfoGenTask%", buildTheardInfo("GENERAL_TASKS"));
+ html.replace("%theardInfoEvnTask%", buildTheardInfo("EVENT_TASKS"));
+ activeChar.sendPacket(html);
+ }
+ return true;
+ }
+
+ private String getServerUpTime()
+ {
+ long time = System.currentTimeMillis() - GameServer.dateTimeServerStarted.getTimeInMillis();
+
+ final long days = TimeUnit.MILLISECONDS.toDays(time);
+ time -= TimeUnit.DAYS.toMillis(days);
+ final long hours = TimeUnit.MILLISECONDS.toHours(time);
+ time -= TimeUnit.HOURS.toMillis(hours);
+ final long minutes = TimeUnit.MILLISECONDS.toMinutes(time);
+
+ return days + " Days, " + hours + " Hours, " + minutes + " Minutes";
+ }
+
+ private String buildTheardInfo(String category)
+ {
+ final TextBuilder tb = new TextBuilder();
+
+ tb.append("");
+ for (Entry info : ThreadPoolManager.getInstance().getStats(category).getSet().entrySet())
+ {
+ tb.append("");
+ tb.append("" + info.getKey() + ": | ");
+ tb.append("" + info.getValue() + " | ");
+ tb.append("
");
+ }
+ tb.append("
");
+ return tb.toString();
+ }
+
+ private int getPlayersCount(String type)
+ {
+ switch (type)
+ {
+ case "ALL":
+ {
+ return L2World.getInstance().getAllPlayersCount();
+ }
+ case "OFF_TRADE":
+ {
+ int offlineCount = 0;
+
+ final Collection objs = L2World.getInstance().getPlayers();
+ for (L2PcInstance player : objs)
+ {
+ if ((player.getClient() == null) || player.getClient().isDetached())
+ {
+ offlineCount++;
+ }
+ }
+ return offlineCount;
+ }
+ case "GM":
+ {
+ int onlineGMcount = 0;
+ for (L2PcInstance gm : L2World.getInstance().getAllGMs())
+ {
+ if ((gm != null) && gm.isOnline() && (gm.getClient() != null) && !gm.getClient().isDetached())
+ {
+ onlineGMcount++;
+ }
+ }
+ return onlineGMcount;
+ }
+ case "ALL_REAL":
+ {
+ Set realPlayers = new HashSet<>();
+
+ for (L2PcInstance onlinePlayer : L2World.getInstance().getPlayers())
+ {
+ if (((onlinePlayer != null) && (onlinePlayer.getClient() != null)) && !onlinePlayer.getClient().isDetached())
+ {
+ realPlayers.add(onlinePlayer.getIPAddress());
+ }
+ }
+ return realPlayers.size();
+ }
+ }
+ return 0;
+ }
+
+ @Override
+ public String[] getAdminCommandList()
+ {
+ return ADMIN_COMMANDS;
+ }
+}
diff --git a/trunk/java/com/l2jserver/gameserver/ThreadPoolManager.java b/trunk/java/com/l2jserver/gameserver/ThreadPoolManager.java
index 8f43c4842f..6a92947ade 100644
--- a/trunk/java/com/l2jserver/gameserver/ThreadPoolManager.java
+++ b/trunk/java/com/l2jserver/gameserver/ThreadPoolManager.java
@@ -35,6 +35,7 @@ import javolution.util.FastMap;
import javolution.util.FastSet;
import com.l2jserver.Config;
+import com.l2jserver.gameserver.model.StatsSet;
import com.l2jserver.util.StringUtil;
/**
@@ -449,6 +450,100 @@ public class ThreadPoolManager
}
}
+ public StatsSet getStats(String category)
+ {
+ final StatsSet StatsSet = new StatsSet();
+
+ switch (category)
+ {
+ case "EFFECTS":
+ {
+ StatsSet.set("ActiveThreads", _effectsScheduledThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _effectsScheduledThreadPool.getCorePoolSize());
+ StatsSet.set("PoolSize", _effectsScheduledThreadPool.getPoolSize());
+ StatsSet.set("MaximumPoolSize", _effectsScheduledThreadPool.getMaximumPoolSize());
+ StatsSet.set("CompletedTasks", (int) _effectsScheduledThreadPool.getCompletedTaskCount());
+ StatsSet.set("ScheduledTasks", _effectsScheduledThreadPool.getQueue().size());
+ break;
+ }
+ case "GENERAL":
+ {
+ StatsSet.set("ActiveThreads", _generalScheduledThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSizes", _generalScheduledThreadPool.getCorePoolSize());
+ StatsSet.set("PoolSizes", _generalScheduledThreadPool.getPoolSize());
+ StatsSet.set("MaximumPoolSizes", _generalScheduledThreadPool.getMaximumPoolSize());
+ StatsSet.set("CompletedTasks", (int) _generalScheduledThreadPool.getCompletedTaskCount());
+ StatsSet.set("ScheduledTasks", _generalScheduledThreadPool.getQueue().size());
+ break;
+ }
+ case "AI":
+ {
+ StatsSet.set("ActiveThreads", _aiScheduledThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _aiScheduledThreadPool.getCorePoolSize());
+ StatsSet.set("PoolSize", _aiScheduledThreadPool.getPoolSize());
+ StatsSet.set("MaximumPoolSize", _aiScheduledThreadPool.getMaximumPoolSize());
+ StatsSet.set("CompletedTasks", (int) _aiScheduledThreadPool.getCompletedTaskCount());
+ StatsSet.set("ScheduledTasks", _aiScheduledThreadPool.getQueue().size());
+ break;
+ }
+ case "EVENT":
+ {
+ StatsSet.set("ActiveThreads", _eventScheduledThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _eventScheduledThreadPool.getCorePoolSize());
+ StatsSet.set("PoolSize", _eventScheduledThreadPool.getPoolSize());
+ StatsSet.set("MaximumPoolSize", _eventScheduledThreadPool.getMaximumPoolSize());
+ StatsSet.set("CompletedTasks", (int) _eventScheduledThreadPool.getCompletedTaskCount());
+ StatsSet.set("ScheduledTasks", _eventScheduledThreadPool.getQueue().size());
+ break;
+ }
+ case "PACKETS":
+ {
+ StatsSet.set("ActiveThreads", _generalPacketsThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _generalPacketsThreadPool.getCorePoolSize());
+ StatsSet.set("MaximumPoolSize", _generalPacketsThreadPool.getMaximumPoolSize());
+ StatsSet.set("LargestPoolSize", _generalPacketsThreadPool.getLargestPoolSize());
+ StatsSet.set("PoolSize", _generalPacketsThreadPool.getPoolSize());
+ StatsSet.set("CompletedTasks", (int) _generalPacketsThreadPool.getCompletedTaskCount());
+ StatsSet.set("QueuedTasks", _generalPacketsThreadPool.getQueue().size());
+ break;
+ }
+ case "IOPACKETS":
+ {
+ StatsSet.set("ActiveThreads", _ioPacketsThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _ioPacketsThreadPool.getCorePoolSize());
+ StatsSet.set("MaximumPoolSize", _ioPacketsThreadPool.getMaximumPoolSize());
+ StatsSet.set("LargestPoolSize", _ioPacketsThreadPool.getLargestPoolSize());
+ StatsSet.set("PoolSize", _ioPacketsThreadPool.getPoolSize());
+ StatsSet.set("CompletedTasks", (int) _ioPacketsThreadPool.getCompletedTaskCount());
+ StatsSet.set("QueuedTasks", _ioPacketsThreadPool.getQueue().size());
+ break;
+ }
+ case "GENERAL_TASKS":
+ {
+ StatsSet.set("ActiveThreads", _generalThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _generalThreadPool.getCorePoolSize());
+ StatsSet.set("MaximumPoolSize", _generalThreadPool.getMaximumPoolSize());
+ StatsSet.set("LargestPoolSize", _generalThreadPool.getLargestPoolSize());
+ StatsSet.set("PoolSize", _generalThreadPool.getPoolSize());
+ StatsSet.set("CompletedTasks", (int) _generalThreadPool.getCompletedTaskCount());
+ StatsSet.set("QueuedTasks", _generalThreadPool.getQueue().size());
+ break;
+ }
+ case "EVENT_TASKS":
+ {
+ StatsSet.set("ActiveThreads", _eventThreadPool.getActiveCount());
+ StatsSet.set("getCorePoolSize", _eventThreadPool.getCorePoolSize());
+ StatsSet.set("MaximumPoolSize", _eventThreadPool.getMaximumPoolSize());
+ StatsSet.set("LargestPoolSize", _eventThreadPool.getLargestPoolSize());
+ StatsSet.set("PoolSize", _eventThreadPool.getPoolSize());
+ StatsSet.set("CompletedTasks", (int) _eventThreadPool.getCompletedTaskCount());
+ StatsSet.set("QueuedTasks", _eventThreadPool.getQueue().size());
+ break;
+ }
+ }
+ return StatsSet;
+ }
+
public String[] getStats()
{
return new String[]