You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pegasus.apache.org by wa...@apache.org on 2023/12/11 06:05:08 UTC
(incubator-pegasus) 09/45: feat(new_metrics): add server-level metric entity (#1415)
This is an automated email from the ASF dual-hosted git repository.
wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
commit b1730fba500139a6bbebb44e0a16154710940fbb
Author: Dan Wang <wa...@apache.org>
AuthorDate: Sat Mar 25 11:24:57 2023 +0800
feat(new_metrics): add server-level metric entity (#1415)
https://github.com/apache/incubator-pegasus/issues/1414
Add server-level metric entity, including:
- Define server-level entity prototype in metrics.cpp;
- Implement getter to acquire the (only) instance of server entity;
- Provide convenient macros to simplify operations for server entity.
---
src/utils/metrics.cpp | 8 ++++++++
src/utils/metrics.h | 7 +++++++
2 files changed, 15 insertions(+)
diff --git a/src/utils/metrics.cpp b/src/utils/metrics.cpp
index a0cc1ead4..03b89215a 100644
--- a/src/utils/metrics.cpp
+++ b/src/utils/metrics.cpp
@@ -32,6 +32,14 @@
#include "utils/string_conv.h"
#include "utils/strings.h"
+METRIC_DEFINE_entity(server);
+
+dsn::metric_entity_ptr server_metric_entity()
+{
+ static auto entity = METRIC_ENTITY_server.instantiate("server");
+ return entity;
+}
+
namespace dsn {
DSN_DEFINE_uint64(metrics,
diff --git a/src/utils/metrics.h b/src/utils/metrics.h
index b8102de5c..128ee9d4b 100644
--- a/src/utils/metrics.h
+++ b/src/utils/metrics.h
@@ -165,6 +165,7 @@ class error_code;
#define METRIC_VAR_INIT(name, entity, ...) \
_##name(METRIC_##name.instantiate(entity##_metric_entity(), ##__VA_ARGS__))
#define METRIC_VAR_INIT_replica(name, ...) METRIC_VAR_INIT(name, replica, ##__VA_ARGS__)
+#define METRIC_VAR_INIT_server(name, ...) METRIC_VAR_INIT(name, server, ##__VA_ARGS__)
// Perform increment-related operations on metrics including gauge and counter.
#define METRIC_VAR_INCREMENT_BY(name, x) \
@@ -1444,3 +1445,9 @@ private:
};
} // namespace dsn
+
+// Since server_metric_entity() will be called in macros such as METRIC_VAR_INIT_server(), its
+// declaration should be put outside any namespace (for example dsn). server_metric_entity()
+// will not be qualified with any namespace. Once it was qualified with some namespace, its name
+// would not be resolved in any other namespace.
+dsn::metric_entity_ptr server_metric_entity();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pegasus.apache.org
For additional commands, e-mail: commits-help@pegasus.apache.org