mirror of
https://bitbucket.org/seefoe/src.git
synced 2026-07-31 01:15:45 -04:00
Added serverMetrics library
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
|
||||
add_subdirectory(serverKeyShare)
|
||||
add_subdirectory(serverKeyShare)
|
||||
add_subdirectory(serverMetrics)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(serverMetrics)
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public)
|
||||
|
||||
add_subdirectory(src)
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/FirstServerMetrics.h"
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/MetricsConnection.h"
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/MetricsData.h"
|
||||
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/MetricsManager.h"
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
set(SHARED_SOURCES
|
||||
shared/ConfigServerMetrics.cpp
|
||||
shared/ConfigServerMetrics.h
|
||||
shared/FirstServerMetrics.h
|
||||
shared/MetricsConnection.cpp
|
||||
shared/MetricsConnection.h
|
||||
shared/MetricsData.cpp
|
||||
shared/MetricsData.h
|
||||
shared/MetricsManager.cpp
|
||||
shared/MetricsManager.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(PLATFORM_SOURCES
|
||||
win32/FirstServerMetrics.cpp
|
||||
)
|
||||
else()
|
||||
set(PLATFORM_SOURCES "")
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shared
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetwork/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetworkMessages/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedUtility/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/serverNetworkMessages/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/serverUtility/include/public
|
||||
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include
|
||||
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/singleton/include
|
||||
)
|
||||
|
||||
add_library(serverMetrics STATIC
|
||||
${SHARED_SOURCES}
|
||||
${PLATFORM_SOURCES}
|
||||
)
|
||||
@@ -0,0 +1,47 @@
|
||||
// ConfigServerMetrics.cpp
|
||||
// copyright 2000 Verant Interactive
|
||||
// Author: Justin Randall
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverMetrics/FirstServerMetrics.h"
|
||||
#include "sharedFoundation/ConfigFile.h"
|
||||
#include "ConfigServerMetrics.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ConfigServerMetrics::Data * ConfigServerMetrics::data = 0;
|
||||
|
||||
#define KEY_INT(a,b) (data->a = ConfigFile::getKeyInt("ServerMetrics", #a, b))
|
||||
#define KEY_BOOL(a,b) (data->a = ConfigFile::getKeyBool("ServerMetrics", #a, b))
|
||||
#define KEY_REAL(a,b) (data->a = ConfigFile::getKeyReal("ServerMetrics", #a, b))
|
||||
#define KEY_STRING(a,b) (data->a = ConfigFile::getKeyString("ServerMetrics", #a, b))
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConfigServerMetrics::install(void)
|
||||
{
|
||||
data = new ConfigServerMetrics::Data;
|
||||
|
||||
KEY_STRING(metricsServerAddress, "localhost");
|
||||
|
||||
data->secondsBetweenUpdates = static_cast<uint16>(ConfigFile::getKeyInt("ServerMetrics", "secondsBetweenUpdates", 5));
|
||||
data->metricsServerPort = static_cast<uint16>(ConfigFile::getKeyInt("ServerMetrics", "metricsServerPort", 44480));
|
||||
|
||||
KEY_STRING(primaryName, "unknownProcess");
|
||||
KEY_STRING(secondaryName, "");
|
||||
KEY_INT(frameTimeAveragingSize, 11);
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConfigServerMetrics::remove(void)
|
||||
{
|
||||
delete data;
|
||||
data = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// ConfigServerMetrics.h
|
||||
// copyright 2000 Verant Interactive
|
||||
|
||||
|
||||
#ifndef _ConfigServerMetrics_H
|
||||
#define _ConfigServerMetrics_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ConfigServerMetrics
|
||||
{
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
const char * metricsServerAddress;
|
||||
uint16 metricsServerPort;
|
||||
uint16 secondsBetweenUpdates;
|
||||
const char * primaryName;
|
||||
const char * secondaryName;
|
||||
int frameTimeAveragingSize;
|
||||
|
||||
};
|
||||
static void install ();
|
||||
static void remove ();
|
||||
|
||||
static const char* getMetricsServerAddress();
|
||||
static uint16 getMetricsServerPort();
|
||||
static uint16 getSecondsBetweenUpdates();
|
||||
static const char* getPrimaryName();
|
||||
static const char* getSecondaryName();
|
||||
static int getFrameTimeAveragingSize();
|
||||
|
||||
private:
|
||||
static Data * data;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char* ConfigServerMetrics::getMetricsServerAddress()
|
||||
{
|
||||
return data->metricsServerAddress;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline uint16 ConfigServerMetrics::getMetricsServerPort()
|
||||
{
|
||||
return data->metricsServerPort;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline uint16 ConfigServerMetrics::getSecondsBetweenUpdates()
|
||||
{
|
||||
return data->secondsBetweenUpdates;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
inline const char* ConfigServerMetrics::getPrimaryName()
|
||||
{
|
||||
return data->primaryName;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char* ConfigServerMetrics::getSecondaryName()
|
||||
{
|
||||
return data->secondaryName;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigServerMetrics::getFrameTimeAveragingSize()
|
||||
{
|
||||
return data->frameTimeAveragingSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _ConfigServerMetrics_H
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// FirstServerMetrics.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_FirstServerMetrics_H
|
||||
#define _INCLUDED_FirstServerMetrics_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#pragma warning ( disable : 4702 )
|
||||
|
||||
#include "Archive/ByteStream.h"
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
#include "sharedNetwork/Connection.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
// MetricsConnection.cpp
|
||||
// copyright 2000 Verant Interactive
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverMetrics/FirstServerMetrics.h"
|
||||
#include "serverMetrics/MetricsConnection.h"
|
||||
|
||||
#include "serverMetrics/MetricsManager.h"
|
||||
#include "sharedNetwork/NetworkSetupData.h"
|
||||
#include "sharedNetworkMessages/GameNetworkMessage.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
MetricsConnection::MetricsConnection(const std::string & a, const unsigned short p) :
|
||||
ServerConnection(a, p, NetworkSetupData())
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
MetricsConnection::MetricsConnection(UdpConnectionMT * u, TcpClient * t) :
|
||||
ServerConnection(u, t)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
MetricsConnection::~MetricsConnection()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void MetricsConnection::onConnectionClosed()
|
||||
{
|
||||
DEBUG_REPORT_LOG(true, ("Connection with Metrics Server closed\n"));
|
||||
MetricsManager::disconnect();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void MetricsConnection::onConnectionOpened()
|
||||
{
|
||||
DEBUG_REPORT_LOG(true, ("Connection with Metrics Server opened\n"));
|
||||
MetricsManager::connect(*this);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void MetricsConnection::onReceive(const Archive::ByteStream & message)
|
||||
{
|
||||
Archive::ReadIterator r(message);
|
||||
GameNetworkMessage m(r);
|
||||
UNREF(m);
|
||||
// DEBUG_WARNING(true, ("This connection should receive no data (metrics) \n"));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -0,0 +1,32 @@
|
||||
// MetricsConnection.h
|
||||
// copyright 2001 Verant Interactive
|
||||
|
||||
|
||||
#ifndef _MetricsConnection_H
|
||||
#define _MetricsConnection_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverUtility/ServerConnection.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class MetricsConnection : public ServerConnection
|
||||
{
|
||||
public:
|
||||
MetricsConnection(const std::string & remoteAddress, const unsigned short remotePort);
|
||||
MetricsConnection(UdpConnectionMT * u, TcpClient * t);
|
||||
virtual ~MetricsConnection();
|
||||
|
||||
virtual void onConnectionClosed();
|
||||
virtual void onConnectionOpened();
|
||||
virtual void onReceive(const Archive::ByteStream & message);
|
||||
|
||||
private:
|
||||
MetricsConnection(const MetricsConnection&);
|
||||
MetricsConnection& operator= (const MetricsConnection&);
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,128 @@
|
||||
//MetricsData.cpp
|
||||
//Copyright 2002 Sony Online Entertainment
|
||||
|
||||
|
||||
#include "serverMetrics/FirstServerMetrics.h"
|
||||
#include "serverMetrics/MetricsData.h"
|
||||
|
||||
#include "serverNetworkMessages/MetricsDataMessage.h"
|
||||
#include "sharedFoundation/Clock.h"
|
||||
#include "sharedFoundation/ConfigFile.h"
|
||||
#include "sharedFoundation/Os.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
MetricsData* MetricsData::m_spInstance = 0;
|
||||
|
||||
|
||||
MetricsData::MetricsData() :
|
||||
m_data(),
|
||||
m_message(),
|
||||
m_memoryUtilization(0),
|
||||
m_memoryUtilizationNoLeakTest(0),
|
||||
m_memoryAllocated(0),
|
||||
#ifndef _WIN32
|
||||
m_memoryVmSize(0),
|
||||
#endif
|
||||
m_loopTimeMs(0),
|
||||
m_frameTimeHistory(),
|
||||
m_frameTimeHistoryIndex(0),
|
||||
m_frameTimeHistorySize(0),
|
||||
m_frameTimeHistoryTotalTime(0.0f)
|
||||
{
|
||||
MetricsPair p;
|
||||
ADD_METRICS_DATA(memoryUtilization, 0, true);
|
||||
ADD_METRICS_DATA(memoryUtilizationNoLeakTest, 0, true);
|
||||
ADD_METRICS_DATA(memoryAllocated, 0, true);
|
||||
#ifndef _WIN32
|
||||
ADD_METRICS_DATA(memoryVmSize, 0, true);
|
||||
#endif
|
||||
ADD_METRICS_DATA(loopTimeMs, 0, true);
|
||||
|
||||
m_frameTimeHistorySize = ConfigFile::getKeyInt("ServerMetrics", "frameTimeAveragingSize", 11);
|
||||
if (m_frameTimeHistorySize <= 0)
|
||||
{
|
||||
m_frameTimeHistorySize = 1;
|
||||
}
|
||||
m_frameTimeHistory.reserve(m_frameTimeHistorySize);
|
||||
for (int i = 0; i < m_frameTimeHistorySize; ++i)
|
||||
{
|
||||
m_frameTimeHistory[i] = 0.0f;
|
||||
}
|
||||
|
||||
m_spInstance = this;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
|
||||
MetricsData::~MetricsData()
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
const GameNetworkMessage & MetricsData::getDataToSend()
|
||||
{
|
||||
updateData();
|
||||
m_message.setData(m_data);
|
||||
return m_message;
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
void MetricsData::updateData()
|
||||
{
|
||||
m_data[m_memoryUtilization].m_value = static_cast<int>(MemoryManager::getCurrentNumberOfBytesAllocated(static_cast<int>(Os::getProcessId())) / 1024);
|
||||
m_data[m_memoryUtilizationNoLeakTest].m_value = static_cast<int>(MemoryManager::getCurrentNumberOfBytesAllocatedNoLeakTest() / 1024);
|
||||
m_data[m_memoryAllocated].m_value = MemoryManager::getSystemMemoryAllocatedMegabytes() * 1024;
|
||||
#ifndef _WIN32
|
||||
m_data[m_memoryVmSize].m_value = MemoryManager::getProcessVmSizeKBytes(static_cast<int>(Os::getProcessId()));
|
||||
#endif
|
||||
|
||||
//deal with frame time
|
||||
float frameTime = Clock::frameTime() * 1000;
|
||||
float oldFrameTime = m_frameTimeHistory[m_frameTimeHistoryIndex];
|
||||
|
||||
m_frameTimeHistoryTotalTime += (frameTime - oldFrameTime);
|
||||
m_frameTimeHistory[m_frameTimeHistoryIndex] = frameTime;
|
||||
++m_frameTimeHistoryIndex;
|
||||
if (m_frameTimeHistoryIndex >= m_frameTimeHistorySize)
|
||||
m_frameTimeHistoryIndex = 0;
|
||||
|
||||
m_data[m_loopTimeMs].m_value = std::max(0, static_cast<int>(m_frameTimeHistoryTotalTime / m_frameTimeHistorySize));
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
int MetricsData::addMetric( const char* sLabel, int iValue, const char* sDescription, bool bPersist, bool bSummary)
|
||||
{
|
||||
MetricsPair p;
|
||||
p.m_label = sLabel;
|
||||
p.m_value = iValue;
|
||||
p.m_description = sDescription ? sDescription : "";
|
||||
p.m_persistData = bPersist;
|
||||
p.m_summary = bSummary;
|
||||
m_data.push_back(p);
|
||||
return( m_data.size()-1 );
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
void MetricsData::updateMetric( int iKey, int iValue )
|
||||
{
|
||||
if ( iKey >= int(m_data.size()) )
|
||||
return;
|
||||
if ( iKey < 0 )
|
||||
return;
|
||||
m_data[ iKey ].m_value = iValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
// MetricsData.h
|
||||
// Copyright 2002 Sony Online Entertainment
|
||||
|
||||
|
||||
#ifndef _MetricsData_H
|
||||
#define _MetricsData_H
|
||||
|
||||
class GameNetworkMessage;
|
||||
|
||||
#include "serverNetworkMessages/MetricsDataMessage.h"
|
||||
|
||||
class MetricsData
|
||||
{
|
||||
friend class MetricsManager;
|
||||
public:
|
||||
MetricsData();
|
||||
virtual ~MetricsData() = 0;
|
||||
|
||||
const GameNetworkMessage & getDataToSend();
|
||||
virtual void updateData();
|
||||
|
||||
virtual int addMetric( const char* sLabel, int iValue=0, const char* sDescription=0, bool bPersist=true, bool bSummary=false);
|
||||
virtual void updateMetric( int iKey, int iValue );
|
||||
|
||||
static MetricsData* getInstance() { return m_spInstance; }
|
||||
|
||||
protected:
|
||||
std::vector<MetricsPair> m_data;
|
||||
|
||||
private:
|
||||
|
||||
MetricsDataMessage m_message;
|
||||
unsigned long m_memoryUtilization;
|
||||
unsigned long m_memoryUtilizationNoLeakTest;
|
||||
unsigned long m_memoryAllocated;
|
||||
#ifndef _WIN32
|
||||
unsigned long m_memoryVmSize;
|
||||
#endif
|
||||
unsigned long m_loopTimeMs;
|
||||
|
||||
private:
|
||||
|
||||
static MetricsData* m_spInstance;
|
||||
|
||||
// Disabled.
|
||||
MetricsData(const MetricsData&);
|
||||
MetricsData &operator =(const MetricsData&);
|
||||
|
||||
std::vector<float> m_frameTimeHistory;
|
||||
int m_frameTimeHistoryIndex;
|
||||
int m_frameTimeHistorySize;
|
||||
float m_frameTimeHistoryTotalTime;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,135 @@
|
||||
// MetricsManager.h
|
||||
// copyright 2002 Verant Interactive
|
||||
|
||||
#include "serverMetrics/FirstServerMetrics.h"
|
||||
#include "MetricsManager.h"
|
||||
|
||||
#include "ConfigServerMetrics.h"
|
||||
#include "serverMetrics/MetricsConnection.h"
|
||||
#include "serverMetrics/MetricsData.h"
|
||||
#include "serverNetworkMessages/MetricsInitiationMessage.h"
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
MetricsManager::ConnectionState MetricsManager::m_connectionState = MetricsManager::CS_Unconnected;
|
||||
bool MetricsManager::m_isDynamic = false;
|
||||
bool MetricsManager::m_isInstalled = false;
|
||||
MetricsConnection* MetricsManager::m_metricsServerConnection = 0;
|
||||
MetricsData* MetricsManager::m_metricsData = 0;
|
||||
std::string MetricsManager::m_primaryName;
|
||||
std::string MetricsManager::m_secondaryName;
|
||||
float MetricsManager::m_timer = 0.0f;
|
||||
int MetricsManager::m_index = 0;
|
||||
|
||||
//-------------------------------------------------------
|
||||
MetricsManager::MetricsManager()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
MetricsManager::~MetricsManager()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
void MetricsManager::connect(MetricsConnection& c)
|
||||
{
|
||||
DEBUG_FATAL(!m_isInstalled, ("MetricsManager not installed\n"));
|
||||
DEBUG_REPORT_LOG(true, ("Metrics server connected\n"));
|
||||
m_metricsServerConnection = &c;
|
||||
m_connectionState = CS_Connected;
|
||||
|
||||
MetricsInitiationMessage m(m_isDynamic, m_primaryName, m_secondaryName, m_index);
|
||||
c.send(m, true);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
void MetricsManager::install(MetricsData* d, bool isDynamic, const std::string & primaryName, const std::string & secondaryName, const int index)
|
||||
{
|
||||
DEBUG_FATAL(m_isInstalled, ("MetricsManager already installed\n"));
|
||||
NOT_NULL(d);
|
||||
ConfigServerMetrics::install();
|
||||
m_isInstalled = true;
|
||||
m_metricsData = d;
|
||||
m_index = index;
|
||||
|
||||
if (ConfigServerMetrics::getMetricsServerPort()!=0)
|
||||
{
|
||||
DEBUG_REPORT_LOG(true, ("Attempting to connect to metrics server\n"));
|
||||
m_metricsServerConnection = new MetricsConnection(ConfigServerMetrics::getMetricsServerAddress(), ConfigServerMetrics::getMetricsServerPort());
|
||||
m_connectionState = CS_Connecting;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_REPORT_LOG(true,("Metrics server disabled in config file (port is set to 0)\n"));
|
||||
m_connectionState = CS_Disabled;
|
||||
}
|
||||
|
||||
m_isDynamic = isDynamic;
|
||||
|
||||
if (primaryName == "")
|
||||
m_primaryName = ConfigServerMetrics::getPrimaryName();
|
||||
else
|
||||
m_primaryName = primaryName;
|
||||
|
||||
if (secondaryName == "")
|
||||
m_secondaryName = ConfigServerMetrics::getSecondaryName();
|
||||
else
|
||||
m_secondaryName = secondaryName;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
void MetricsManager::remove()
|
||||
{
|
||||
DEBUG_FATAL(!m_isInstalled, ("MetricsManager not installed\n"));
|
||||
m_metricsServerConnection = 0;
|
||||
ConfigServerMetrics::remove();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
void MetricsManager::update(float time)
|
||||
{
|
||||
DEBUG_FATAL(!m_isInstalled, ("MetricsManager not installed\n"));
|
||||
//each update time send out metrics data to the metrics server.
|
||||
//if we are unconnected, try to connect to metrics server
|
||||
//if we are connecting do nothing
|
||||
//if we are connected, send data
|
||||
|
||||
switch(m_connectionState)
|
||||
{
|
||||
case CS_Unconnected:
|
||||
DEBUG_REPORT_LOG(true, ("Attempting to connect to metrics server\n"));
|
||||
m_metricsServerConnection = new MetricsConnection(ConfigServerMetrics::getMetricsServerAddress(), ConfigServerMetrics::getMetricsServerPort());
|
||||
m_connectionState = CS_Connecting;
|
||||
break;
|
||||
|
||||
case CS_Connecting:
|
||||
break;
|
||||
|
||||
case CS_Connected:
|
||||
|
||||
m_timer -= time;
|
||||
if (m_timer <= 0)
|
||||
{
|
||||
// DEBUG_REPORT_LOG(true, ("Sending data to Metrics server"));
|
||||
NOT_NULL(m_metricsData);
|
||||
const GameNetworkMessage& m = m_metricsData->getDataToSend();
|
||||
if (m_metricsServerConnection)
|
||||
m_metricsServerConnection->send(m, true);
|
||||
m_timer = static_cast<float>(ConfigServerMetrics::getSecondsBetweenUpdates()) * 1000;
|
||||
}
|
||||
break;
|
||||
|
||||
case CS_Disabled:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
@@ -0,0 +1,64 @@
|
||||
// MetricsManager.h
|
||||
// Copyright 2002 Sony Online Entertainment
|
||||
|
||||
|
||||
#ifndef _MetricsManager_H
|
||||
#define _MetricsManager_H
|
||||
|
||||
#include "Singleton/Singleton.h"
|
||||
|
||||
class GameNetworkMessage;
|
||||
class MetricsConnection;
|
||||
class MetricsData;
|
||||
|
||||
class MetricsManager
|
||||
{
|
||||
friend class MetricsConnection;
|
||||
public:
|
||||
static void install(MetricsData*, bool, const std::string & primaryName, const std::string & secondaryName, const int index);
|
||||
static void remove();
|
||||
static void update(float time);
|
||||
|
||||
private:
|
||||
|
||||
MetricsManager();
|
||||
~MetricsManager();
|
||||
|
||||
private:
|
||||
|
||||
enum ConnectionState
|
||||
{
|
||||
CS_Unconnected,
|
||||
CS_Connecting,
|
||||
CS_Connected,
|
||||
CS_Disabled
|
||||
};
|
||||
static void connect(MetricsConnection &);
|
||||
static void disconnect();
|
||||
|
||||
static ConnectionState m_connectionState;
|
||||
static bool m_isDynamic;
|
||||
static bool m_isInstalled;
|
||||
static MetricsConnection* m_metricsServerConnection;
|
||||
static MetricsData* m_metricsData;
|
||||
static std::string m_primaryName;
|
||||
static std::string m_secondaryName;
|
||||
static int m_index;
|
||||
static float m_timer;
|
||||
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
inline void MetricsManager::disconnect()
|
||||
{
|
||||
DEBUG_REPORT_LOG(true, ("Metrics server disconnected\n"));
|
||||
m_connectionState = CS_Unconnected;
|
||||
m_metricsServerConnection = 0;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
// FirstServerMetrics.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverMetrics/FirstServerMetrics.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user