aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Metric/Metric.cpp3
-rw-r--r--src/common/Metric/Metric.h54
2 files changed, 34 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