This is an automated email from the ASF dual-hosted git repository. wangdan pushed a commit to branch migrate-metrics-dev in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git
commit 5d44514cbb4f202fbacfa8dd299f16dbbd9c8a72 Author: Dan Wang <[email protected]> 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 2a15fb5aa..b32887c55 100644 --- a/src/utils/metrics.cpp +++ b/src/utils/metrics.cpp @@ -30,6 +30,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 9087b78e5..e69268006 100644 --- a/src/utils/metrics.h +++ b/src/utils/metrics.h @@ -164,6 +164,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) \ @@ -1445,3 +1446,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: [email protected] For additional commands, e-mail: [email protected]
