aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2020-06-19 22:04:01 +0000
committerShauren <shauren.trinity@gmail.com>2022-01-06 23:15:07 +0100
commit07f42907c65e63d21a00f4af3eb20efe3491acbe (patch)
tree0ff40bfb53a6d0bbdf149de1d4fc6f9f62b9383e /src
parentfc43a95729109286d8ce0e0ecf3a2c3dcdbe2d5b (diff)
Log number of Creatures and GameObject per map (#24809)
* Shared/Metric: Allow to specify tags in metrics * Core/Metric: Log number of Creatures and GameObject per map * Apply feedback * Codestyle changes * Codestyle changes * Remove whitespace * Update Grafana dashboards to v7.0.3 * Fix missing filter on realm * Include Creatures and Gameobjects in Maps dashboard * Show instances with a different color (cherry picked from commit 4e1dbd1cf808c9cf1f310b6d498f7e304dfb4147)
Diffstat (limited to 'src')
-rw-r--r--src/common/Metric/Metric.cpp3
-rw-r--r--src/common/Metric/Metric.h54
-rw-r--r--src/server/game/Maps/Map.cpp9
3 files changed, 43 insertions, 23 deletions
diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp
index f4d0661dcaf..b1302aacb5a 100644
--- a/src/common/Metric/Metric.cpp
+++ b/src/common/Metric/Metric.cpp
@@ -136,6 +136,9 @@ void Metric::SendBatch()
if (!_realmName.empty())
batchedData << ",realm=" << _realmName;
+ for (MetricTag const& tag : data->Tags)
+ batchedData << "," << tag.first << "=" << tag.second;
+
batchedData << " ";
switch (data->Type)
diff --git a/src/common/Metric/Metric.h b/src/common/Metric/Metric.h
index 1182db6b501..d46e0566130 100644
--- a/src/common/Metric/Metric.h
+++ b/src/common/Metric/Metric.h
@@ -25,6 +25,8 @@
#include <iosfwd>
#include <memory>
#include <string>
+#include <vector>
+#include <utility>
namespace Trinity
{
@@ -41,11 +43,14 @@ enum MetricDataType
METRIC_DATA_EVENT
};
+typedef std::pair<std::string, std::string> MetricTag;
+
struct MetricData
{
std::string Category;
std::chrono::system_clock::time_point Timestamp;
MetricDataType Type;
+ std::vector<MetricTag> Tags;
// LogValue-specific fields
std::string Value;
@@ -100,7 +105,7 @@ public:
void Update();
template<class T>
- void LogValue(std::string const& category, T value)
+ void LogValue(std::string const& category, T value, std::vector<MetricTag> tags)
{
using namespace std::chrono;
@@ -109,6 +114,7 @@ public:
data->Timestamp = system_clock::now();
data->Type = METRIC_DATA_VALUE;
data->Value = FormatInfluxDBValue(value);
+ data->Tags = std::move(tags);
_queuedData.Enqueue(data);
}
@@ -121,36 +127,38 @@ public:
#define sMetric Metric::instance()
+#define TC_METRIC_TAG(name, value) { name, value }
+
#ifdef PERFORMANCE_PROFILING
#define TC_METRIC_EVENT(category, title, description) ((void)0)
#define TC_METRIC_VALUE(category, value) ((void)0)
#elif TRINITY_PLATFORM != TRINITY_PLATFORM_WINDOWS
-#define TC_METRIC_EVENT(category, title, description) \
- do { \
- if (sMetric->IsEnabled()) \
- sMetric->LogEvent(category, title, description); \
+#define TC_METRIC_EVENT(category, title, description) \
+ do { \
+ if (sMetric->IsEnabled()) \
+ sMetric->LogEvent(category, title, description); \
} while (0)
-#define TC_METRIC_VALUE(category, value) \
- do { \
- if (sMetric->IsEnabled()) \
- sMetric->LogValue(category, value); \
+#define TC_METRIC_VALUE(category, value, ...) \
+ do { \
+ if (sMetric->IsEnabled()) \
+ sMetric->LogValue(category, value, { __VA_ARGS__ }); \
} while (0)
#else
-#define TC_METRIC_EVENT(category, title, description) \
- __pragma(warning(push)) \
- __pragma(warning(disable:4127)) \
- do { \
- if (sMetric->IsEnabled()) \
- sMetric->LogEvent(category, title, description); \
- } while (0) \
+#define TC_METRIC_EVENT(category, title, description) \
+ __pragma(warning(push)) \
+ __pragma(warning(disable:4127)) \
+ do { \
+ if (sMetric->IsEnabled()) \
+ sMetric->LogEvent(category, title, description); \
+ } while (0) \
__pragma(warning(pop))
-#define TC_METRIC_VALUE(category, value) \
- __pragma(warning(push)) \
- __pragma(warning(disable:4127)) \
- do { \
- if (sMetric->IsEnabled()) \
- sMetric->LogValue(category, value); \
- } while (0) \
+#define TC_METRIC_VALUE(category, value, ...) \
+ __pragma(warning(push)) \
+ __pragma(warning(disable:4127)) \
+ do { \
+ if (sMetric->IsEnabled()) \
+ sMetric->LogValue(category, value, { __VA_ARGS__ }); \
+ } while (0) \
__pragma(warning(pop))
#endif
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 1df76fd4f0a..d3d32e55846 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -36,6 +36,7 @@
#include "Log.h"
#include "MapInstanced.h"
#include "MapManager.h"
+#include "Metric.h"
#include "MiscPackets.h"
#include "MMapFactory.h"
#include "MotionMaster.h"
@@ -964,6 +965,14 @@ void Map::Update(uint32 t_diff)
ProcessRelocationNotifies(t_diff);
sScriptMgr->OnMapUpdate(this, t_diff);
+
+ TC_METRIC_VALUE("map_creatures", uint64(GetObjectsStore().Size<Creature>()),
+ TC_METRIC_TAG("map_id", std::to_string(GetId())),
+ TC_METRIC_TAG("map_instanceid", std::to_string(GetInstanceId())));
+
+ TC_METRIC_VALUE("map_gameobjects", uint64(GetObjectsStore().Size<GameObject>()),
+ TC_METRIC_TAG("map_id", std::to_string(GetId())),
+ TC_METRIC_TAG("map_instanceid", std::to_string(GetInstanceId())));
}
struct ResetNotifier