Caracteristicas:
- Consumo de memoria del servidor
- Usuarios online
- Estado del cache html
NOTA: este programa se ejecuta cada X tiempo y las estadisticas seran representadas en la consola del servidor y en los logs del servidor.
package com.l2jserver.gameserver.instancemanager.statistics;
import java.awt.Toolkit;
import java.util.logging.Logger;
import com.l2jserver.Config;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.cache.HtmCache;
import com.l2jserver.gameserver.model.L2World;
/**
* @author fissban
*/
public class Statistics
{
static Logger _log = Logger.getLogger(Statistics.class.getName());
static final int Reuse = Config.STATISTICS_TIME * 1000;
Statistics()
{
if (Config.STATISTICS_GS)
{
_log.info("[ Statistics ] Enable");
ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new StatisticsGS(), Reuse, Reuse);
}
else
{
_log.info("[ Statistics ] Disable");
}
}
class StatisticsGS implements Runnable
{
@Override
public void run()
{
_log.info("------------------ Statistics GameServer -------------");
_log.info(" ");
_log.info("Users online : " + L2World.getInstance().getAllPlayersCount() + " out of " + Config.MAXIMUM_ONLINE_USERS);
long freeMem = ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory()) + Runtime.getRuntime().freeMemory()) / 1048576;
long totalMem = Runtime.getRuntime().maxMemory() / 1048576;
_log.info("Gameserver free memory " + freeMem + " Mb out of " + totalMem + " Mb");
Toolkit.getDefaultToolkit().beep();
_log.info("Cache[HTML]: " + String.format("%.3f", HtmCache.getInstance().getMemoryUsage()) + " megabytes");
_log.info(" ");
_log.info("------------------------------------------------------");
}
}
public static Statistics getInstance()
{
return SingletonHolder._instance;
}
static class SingletonHolder
{
protected static final Statistics _instance = new Statistics();
}
}
Gameserver.java
+ // Statistics
+ printSection("Load Statistics");
+ Statistics.getInstance();
if (Config.DEADLOCK_DETECTOR)
{
_deadDetectThread = new DeadLockDetector();
_deadDetectThread.setDaemon(true);
_deadDetectThread.start();
}
Config.java
public static final String EMAIL_CONFIG_FILE = "./config/Email.properties";
public static final String CH_SIEGE_FILE = "./config/ConquerableHallSiege.properties";
+ // --------------------------------------------------
+ // Property File Definitions
+ // --------------------------------------------------
+ public static final String VARIOS_CONFIG_FILE = "./config/custom/Varios.properties";
public static boolean CUSTOM_EFFECT_CHAMPION;
public static boolean ADVENTURER_GUIDE_STYLE_GOD;
+ // Statistics GS
+ public static boolean STATISTICS_GS;
+ public static int STATISTICS_TIME;
// Clan Hall Custom
public static boolean USE_CUSTOM_CLANHALLS;
// START
L2Properties VariosSettings = new L2Properties();
final File varios = new File(VARIOS_CONFIG_FILE);
try (InputStream is = new FileInputStream(varios))
{
VariosSettings.load(is);
// Statistics GS
STATISTICS_GS = Boolean.parseBoolean(VariosSettings.getProperty("StatisticsGS", "false"));
STATISTICS_TIME = Integer.parseInt(VariosSettings.getProperty("StatisticsReuse", "20"));
}
catch (Exception e)
{
_log.log(Level.SEVERE, "Error while loading Varios.properties!", e);
}
Luego crean dentro de la carpeta config una carpeta llamada Custom y dentro un archivo llamado varios.properties y pegan esto
###########################################
# Statistics GS #
###########################################
# author: fissban
# Statistics Gameserver
# Enable / Disable
# Players online/ maximo players
# memory in use / memory allocated
StatisticsGS = True
# Seconds to Statistics the server ( 720 = 5 Minutos )
# default = 720
StatisticsReuse = 720