fix metrics rpc for Timer type

This commit is contained in:
boqiu 2024-08-21 15:17:13 +08:00
parent eb521fc24b
commit 061fc3ef58

View File

@ -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)
}
}