From 061fc3ef58d2bd0f3cc3164da6887463bf69b6b6 Mon Sep 17 00:00:00 2001 From: boqiu <82121246@qq.com> Date: Wed, 21 Aug 2024 15:17:13 +0800 Subject: [PATCH] fix metrics rpc for Timer type --- node/rpc/src/admin/impl.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/node/rpc/src/admin/impl.rs b/node/rpc/src/admin/impl.rs index ccad517..6bbd3cf 100644 --- a/node/rpc/src/admin/impl.rs +++ b/node/rpc/src/admin/impl.rs @@ -4,7 +4,7 @@ use crate::{error, Context}; use futures::prelude::*; use jsonrpsee::core::async_trait; use jsonrpsee::core::RpcResult; -use metrics::DEFAULT_REGISTRY; +use metrics::{DEFAULT_GROUPING_REGISTRY, DEFAULT_REGISTRY}; use network::{multiaddr::Protocol, Multiaddr}; use std::collections::{BTreeMap, HashMap}; use std::net::IpAddr; @@ -266,6 +266,21 @@ impl RpcServer for RpcServerImpl { } } + for (group_name, metrics) in DEFAULT_GROUPING_REGISTRY.read().get_all() { + for (metric_name, metric) in metrics.iter() { + let name = format!("{}.{}", group_name, metric_name); + match &maybe_prefix { + Some(prefix) if !name.starts_with(prefix) => {} + _ => { + result.insert( + name, + format!("{} {}", metric.get_type(), metric.get_value()), + ); + } + } + } + } + Ok(result) } }