From aff1127b9fd0147172d9828a7de3e6aab6791783 Mon Sep 17 00:00:00 2001 From: Tekaoh <45337851+Tekaoh@users.noreply.github.com> Date: Thu, 23 Apr 2020 09:44:36 -0400 Subject: [PATCH] Metrics enhancements --- .../src/shared/CentralServer.cpp | 46 ++++++++++--------- .../src/shared/ConfigCentralServer.cpp | 5 +- .../src/shared/ConfigCentralServer.h | 15 ++++-- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/engine/server/application/CentralServer/src/shared/CentralServer.cpp b/engine/server/application/CentralServer/src/shared/CentralServer.cpp index 101ffd00..1cdb83bb 100755 --- a/engine/server/application/CentralServer/src/shared/CentralServer.cpp +++ b/engine/server/application/CentralServer/src/shared/CentralServer.cpp @@ -275,9 +275,9 @@ m_timeCharacterMatchStatisticsNextRefresh(0) connectToMessage("TaskConnectionOpened"); connectToMessage("RandomNameRequest"); // from connection server connectToMessage("RandomNameResponse"); // from game server - connectToMessage("VerifyAndLockNameRequest"); // from connection server - connectToMessage("VerifyAndLockNameResponse"); // from game server - + connectToMessage("VerifyAndLockNameRequest"); // from connection server + connectToMessage("VerifyAndLockNameResponse"); // from game server + //Object Messages connectToMessage("RequestObjectMessage"); connectToMessage("RequestChunkMessage"); @@ -386,7 +386,7 @@ m_timeCharacterMatchStatisticsNextRefresh(0) connectToMessage("RestartServerByRoleMessage"); connectToMessage("ExcommunicateGameServerMessage"); connectToMessage("RestartPlanetMessage"); - + // Cluster state connectToMessage("UpdateClusterLockedAndSecretState"); @@ -432,7 +432,7 @@ m_timeCharacterMatchStatisticsNextRefresh(0) CentralServer::~CentralServer() { ConsoleManager::remove(); - + CentralCSHandler::remove(); ms_sceneToHostMap.clear(); @@ -1315,7 +1315,7 @@ void CentralServer::receiveMessage(const MessageDispatch::Emitter & source, cons Archive::ReadIterator ri = static_cast(message).getByteStream().begin(); GenericValueTypeMessage reply(ri); // If this request has a CS Tool Id associated with it, it is an admin request for the CSTool, - // and so we should send it directly to the connection server, and not depend on a + // and so we should send it directly to the connection server, and not depend on a // transfer server existing. if (reply.getValue().getCSToolId() > 0) { @@ -2634,7 +2634,7 @@ void CentralServer::removeGameServer(GameServerConnection const *gameServer) ExcommunicateGameServerMessage const excommunicateMessage(pid, 0, ""); sendToAllGameServersExceptDBProcess(excommunicateMessage, true); } - else + else { DEBUG_WARNING(true, ("A game server crashed but our process ID ptr is nullptr.")); } @@ -2697,7 +2697,7 @@ void CentralServer::run(void) setup.port = ConfigCentralServer::getCommodityServerServicePort(); setup.bindInterface = ConfigCentralServer::getCommodityServerServiceBindInterface(); s_commodityServerService = new Service(ConnectionAllocator(), setup); - + setup.port = ConfigCentralServer::getLoginServicePort(); if (ConfigCentralServer::getDevelopmentMode()) cserver.connectToLoginServer(); @@ -2709,7 +2709,7 @@ void CentralServer::run(void) // connect to the task manager cserver.m_taskManager = new TaskConnection("127.0.0.1", ConfigCentralServer::getTaskManagerPort()); - + unsigned long startTime = Clock::timeMs(); unsigned long nextLoadingLogTime=0; unsigned long nextPingTime=0; @@ -2743,7 +2743,7 @@ void CentralServer::run(void) { unsigned long lastFrameTime = 0; unsigned long frameStartTime = Clock::timeMs(); - + PROFILER_AUTO_BLOCK_DEFINE("main loop"); bool barrierReached = true; @@ -2847,7 +2847,7 @@ void CentralServer::update() static int shutdownCheckLoopCount = 0; m_curTime = static_cast(time(0)); - + // Tell the LoginServers if necessary if ((++loopCount > ConfigCentralServer::getUpdatePlayerCountFrequency())) { @@ -2877,7 +2877,7 @@ void CentralServer::update() const short port[1] = { (short)ConfigCentralServer::getAuctionPort() }; std::string s_id = ConfigCentralServer::getAuctionIDPrefix(); - s_id += ConfigCentralServer::getClusterName(); + s_id += ConfigCentralServer::getClusterName(); const char *identifier[1]; identifier[ 0 ] = s_id.c_str(); @@ -2914,7 +2914,7 @@ void CentralServer::sendPopulationUpdateToLoginServer() m_totalTutorialSceneCount = 0; m_totalFalconSceneCount = 0; - + ConnectionServerConnectionList::const_iterator i; for (i=m_connectionServerConnections.begin(); i!=m_connectionServerConnections.end(); ++i) { @@ -2939,7 +2939,7 @@ void CentralServer::sendPopulationUpdateToLoginServer() void CentralServer::sendMetricsToWebAPI() { static const std::string metricsURL(ConfigCentralServer::getMetricsDataURL()); - + if (!metricsURL.empty()) { StellaBellum::webAPI api(metricsURL); @@ -2952,23 +2952,25 @@ void CentralServer::sendMetricsToWebAPI() api.addJsonData("lastLoadingStateTime", m_lastLoadingStateTime); api.addJsonData("clusterStartupTime", m_clusterStartupTime); api.addJsonData("timeClusterWentIntoLoadingState", m_timeClusterWentIntoLoadingState); - + api.addJsonData("webUpdateIntervalSeconds", ConfigCentralServer::getWebUpdateIntervalSeconds()); + api.addJsonData("secretKey", ConfigCentralServer::getMetricsSecretKey()); + #ifdef _DEBUG if (api.submit()) { bool status = api.getNullableValue("status"); - + if (status) { std::string message = api.getString("message"); - + if (message.empty()) { message = "No message returned."; } - + WARNING(true, ("Error sending stats: %s", message.c_str())); } - + WARNING(true, ("Success sending server stats to API.")); } else @@ -3200,7 +3202,7 @@ void CentralServer::startPlanetServer(const std::string & host, const std::strin portBase += 100; options += " gameServerDebuggingPortBase="; options += buffer; - + TaskSpawnProcess spawn(host.empty() ? std::string("any") : host, "PlanetServer", options, spawnDelay); CentralServer::getInstance().sendTaskMessage(spawn); m_pendingPlanetServers[sceneId] = std::make_pair(std::make_pair(host, options), ::time(nullptr)); @@ -3218,7 +3220,7 @@ void CentralServer::startPlanetServer(const std::string & host, const std::strin getInstance().m_transferServerConnection = 0; s_retryTransferServerConnection = false; } - + if(getInstance().m_stationPlayersCollectorConnection != nullptr && ! isPreloadFinished()) { getInstance().m_stationPlayersCollectorConnection->disconnect(); @@ -4133,7 +4135,7 @@ std::pair > const *, std::mapa = ConfigFile::getKeyInt("CentralServer", #a, b)) -#define KEY_BOOL(a,b) (data->a = ConfigFile::getKeyBool("CentralServer", #a, b)) +#define KEY_BOOL(a,b) (data->a = ConfigFile::getKeyBool("CentralServer", #a, b)) #define KEY_STRING(a,b) (data->a = ConfigFile::getKeyString("CentralServer", #a, b)) //----------------------------------------------------------------------- @@ -110,7 +110,7 @@ void ConfigCentralServer::install(void) KEY_STRING (transferServerAddress, "127.0.0.1"); KEY_INT (transferServerPort, 0); // TransferServer listens on 50005, default to "off" KEY_STRING (stationPlayersCollectorAddress, "127.0.0.1"); - KEY_INT (stationPlayersCollectorPort, 0); // StationPlayersCollector listens on 50010, default to "off" + KEY_INT (stationPlayersCollectorPort, 0); // StationPlayersCollector listens on 50010, default to "off" KEY_BOOL (allowZeroConnectionServerPort, true); KEY_INT (clusterWideDataLockTimeout, 300); // seconds KEY_STRING (commodityServerServiceBindInterface, ""); @@ -129,6 +129,7 @@ void ConfigCentralServer::install(void) KEY_INT (maxTimeToWaitForPlanetServerStartSeconds, 5*60); // seconds KEY_STRING (metricsDataURL, ""); KEY_INT (webUpdateIntervalSeconds, 5); + KEY_STRING (metricsSecretKey, ""); int index = 0; char const * result = 0; diff --git a/engine/server/application/CentralServer/src/shared/ConfigCentralServer.h b/engine/server/application/CentralServer/src/shared/ConfigCentralServer.h index 79e08d55..bc2769c9 100755 --- a/engine/server/application/CentralServer/src/shared/ConfigCentralServer.h +++ b/engine/server/application/CentralServer/src/shared/ConfigCentralServer.h @@ -74,6 +74,7 @@ public: const char * metricsDataURL; int webUpdateIntervalSeconds; + const char * metricsSecretKey; }; static const unsigned short getChatServicePort (); @@ -137,7 +138,7 @@ public: static const char * getAuctionServer(); static int getAuctionPort(); static const char * getAuctionIDPrefix(); - + static bool getDisconnectDuplicateConnectionsOnOtherGalaxies(); static bool getRequestDbSaveOnPlanetServerCrash(); @@ -146,13 +147,14 @@ public: static const char * getMetricsDataURL(); static int getWebUpdateIntervalSeconds(); + static const char * getMetricsSecretKey(); private: static Data * data; }; //----------------------------------------------------------------------- -inline const unsigned short ConfigCentralServer::getChatServicePort() +inline const unsigned short ConfigCentralServer::getChatServicePort() { return static_cast(data->chatServicePort); } @@ -173,7 +175,7 @@ inline const unsigned short ConfigCentralServer::getConnectionServicePort() //----------------------------------------------------------------------- -inline const unsigned short ConfigCentralServer::getCustomerServicePort() +inline const unsigned short ConfigCentralServer::getCustomerServicePort() { return static_cast(data->customerServicePort); } @@ -529,6 +531,13 @@ inline int ConfigCentralServer::getWebUpdateIntervalSeconds() return data->webUpdateIntervalSeconds; } +// ---------------------------------------------------------------------- + +inline const char * ConfigCentralServer::getMetricsSecretKey() +{ + return data->metricsSecretKey; +} + // ====================================================================== #endif // _ConfigCentralServer_H