Skip to content

Commit bbfe084

Browse files
committed
feature: GaugeHelper supports labels
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
1 parent abd48c6 commit bbfe084

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/app/impl/application_impl.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ namespace jam::app {
3434
system_clock_(std::move(system_clock)),
3535
metrics_registry_(metrics::createRegistry()) {
3636
// Metric for exposing name and version of node
37-
constexpr auto buildInfoMetricName = "jam_build_info";
38-
metrics_registry_->registerGaugeFamily(
39-
buildInfoMetricName,
40-
"A metric with a constant '1' value labeled by name, version");
41-
auto metric_build_info = metrics_registry_->registerGaugeMetric(
42-
buildInfoMetricName,
43-
{{"name", app_config_->nodeName()},
44-
{"version", app_config_->nodeVersion()}});
45-
metric_build_info->set(1);
37+
metrics::GaugeHelper(
38+
"jam_build_info",
39+
"A metric with a constant '1' value labeled by name, version",
40+
std::map<std::string, std::string>{
41+
{"name", app_config_->nodeName()},
42+
{"version", app_config_->nodeVersion()}})
43+
->set(1);
4644
}
4745

4846
void ApplicationImpl::run() {

src/metrics/histogram_timer.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ namespace jam::metrics {
2727
registry_->registerGaugeFamily(name, help);
2828
metric_ = registry_->registerGaugeMetric(name);
2929
}
30+
GaugeHelper(const std::string &name,
31+
const std::string &help,
32+
const std::map<std::string, std::string> &labels) {
33+
registry_->registerGaugeFamily(name, help);
34+
metric_ = registry_->registerGaugeMetric(name, labels);
35+
}
3036

3137
auto *operator->() const {
3238
return metric_;

0 commit comments

Comments
 (0)