diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/Metric/Metric.cpp | 19 | ||||
-rw-r--r-- | src/common/Metric/Metric.h | 7 | ||||
-rw-r--r-- | src/server/game/Server/WorldSession.cpp | 5 | ||||
-rw-r--r-- | src/server/worldserver/worldserver.conf.dist | 14 |
4 files changed, 42 insertions, 3 deletions
diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp index d22839e8a79..b5762dbd8e2 100644 --- a/src/common/Metric/Metric.cpp +++ b/src/common/Metric/Metric.cpp @@ -69,6 +69,15 @@ void Metric::LoadFromConfigs() _overallStatusTimerInterval = 1; } + _thresholds.clear(); + std::vector<std::string> thresholdSettings = sConfigMgr->GetKeysByString("Metric.Threshold."); + for (std::string const& thresholdSetting : thresholdSettings) + { + int thresholdValue = sConfigMgr->GetIntDefault(thresholdSetting, 0); + std::string thresholdName = thresholdSetting.substr(strlen("Metric.Threshold.")); + _thresholds[thresholdName] = thresholdValue; + } + // Schedule a send at this point only if the config changed from Disabled to Enabled. // Cancel any scheduled operation if the config changed from Enabled to Disabled. if (_enabled && !previousValue) @@ -106,6 +115,14 @@ void Metric::Update() } } +bool Metric::ShouldLog(std::string const& category, int64 value) const +{ + auto threshold = _thresholds.find(category); + if (threshold == _thresholds.end()) + return false; + return value >= threshold->second; +} + void Metric::LogEvent(std::string const& category, std::string const& title, std::string const& description) { using namespace std::chrono; @@ -281,7 +298,7 @@ std::string Metric::FormatInfluxDBTagValue(std::string const& value) std::string Metric::FormatInfluxDBValue(std::chrono::nanoseconds value) { - return FormatInfluxDBValue(std::chrono::duration_cast<std::chrono::milliseconds>(value).count()); + return FormatInfluxDBValue(std::chrono::duration_cast<Milliseconds>(value).count()); } Metric::Metric() diff --git a/src/common/Metric/Metric.h b/src/common/Metric/Metric.h index 11c156653d0..599d432d65d 100644 --- a/src/common/Metric/Metric.h +++ b/src/common/Metric/Metric.h @@ -25,6 +25,7 @@ #include <iosfwd> #include <memory> #include <string> +#include <unordered_map> #include <vector> #include <utility> @@ -77,6 +78,7 @@ private: std::string _databaseName; std::function<void()> _overallStatusLogger; std::string _realmName; + std::unordered_map<std::string, int64> _thresholds; bool Connect(); void SendBatch(); @@ -104,6 +106,7 @@ public: void Initialize(std::string const& realmName, Trinity::Asio::IoContext& ioContext, std::function<void()> overallStatusLogger); void LoadFromConfigs(); void Update(); + bool ShouldLog(std::string const& category, int64 value) const; template<class T> void LogValue(std::string const& category, T value, std::vector<MetricTag> tags) @@ -206,7 +209,9 @@ MetricStopWatch<LoggerType> MakeMetricStopWatch(LoggerType&& loggerFunc) #define TC_METRIC_DETAILED_TIMER(category, ...) \ MetricStopWatch TC_METRIC_UNIQUE_NAME(__tc_metric_stop_watch) = MakeMetricStopWatch([&](TimePoint start) \ { \ - sMetric->LogValue(category, std::chrono::steady_clock::now() - start, { __VA_ARGS__ }); \ + int64 duration = int64(std::chrono::duration_cast<Milliseconds>(std::chrono::steady_clock::now() - start).count()); \ + if (sMetric->ShouldLog(category, duration)) \ + sMetric->LogValue(category, duration, { __VA_ARGS__ }); \ }); # else #define TC_METRIC_DETAILED_TIMER(category, ...) ((void)0) diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index abbf28c8bae..9ec0d9244b3 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -291,7 +291,10 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater) while (m_Socket && _recvQueue.next(packet, updater)) { - ClientOpcodeHandler const* opHandle = opcodeTable[static_cast<OpcodeClient>(packet->GetOpcode())]; + OpcodeClient opcode = static_cast<OpcodeClient>(packet->GetOpcode()); + ClientOpcodeHandler const* opHandle = opcodeTable[opcode]; + TC_METRIC_DETAILED_TIMER("worldsession_update_opcode_time", TC_METRIC_TAG("opcode", opHandle->Name)); + try { switch (opHandle->Status) diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index d5d11cf956d..801d2bbcb57 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -4067,4 +4067,18 @@ Metric.ConnectionInfo = "127.0.0.1;8086;worldserver" Metric.OverallStatusInterval = 1 # +# Metric threshold values: Given a metric "name" +# Metric.Threshold.name +# Description: Skips sending statistics with a value lower than the config value. +# If the threshold is commented out, the metric will be ignored. +# Only metrics logged with TC_METRIC_DETAILED_TIMER in the sources are affected. +# Disabled by default. Requires WITH_DETAILED_METRICS CMake flag. +# +# Format: Value as integer +# + +#Metric.Threshold.world_update_sessions_time = 100 +#Metric.Threshold.worldsession_update_opcode_time = 50 + +# ################################################################################################### |