Add more prometheus metrics to network::Protocol. (#5145)

This commit is contained in:
Gavin Wood
2020-03-05 17:01:24 +01:00
committed by GitHub
parent f7084e5487
commit 868d8b8252
4 changed files with 189 additions and 3 deletions
@@ -1202,6 +1202,27 @@ impl<B: BlockT> ChainSync<B> {
fn is_already_downloading(&self, hash: &B::Hash) -> bool {
self.peers.iter().any(|(_, p)| p.state == PeerSyncState::DownloadingStale(*hash))
}
/// Return some key metrics.
pub(crate) fn metrics(&self) -> Metrics {
use std::convert::TryInto;
Metrics {
queued_blocks: self.queue_blocks.len().try_into().unwrap_or(std::u32::MAX),
fork_targets: self.fork_targets.len().try_into().unwrap_or(std::u32::MAX),
finality_proofs: self.extra_finality_proofs.metrics(),
justifications: self.extra_justifications.metrics(),
_priv: ()
}
}
}
#[derive(Debug)]
pub(crate) struct Metrics {
pub(crate) queued_blocks: u32,
pub(crate) fork_targets: u32,
pub(crate) finality_proofs: extra_requests::Metrics,
pub(crate) justifications: extra_requests::Metrics,
_priv: ()
}
/// Request the ancestry for a block. Sends a request for header and justification for the given
@@ -53,6 +53,15 @@ pub(crate) struct ExtraRequests<B: BlockT> {
request_type_name: &'static str,
}
#[derive(Debug)]
pub(crate) struct Metrics {
pub(crate) pending_requests: u32,
pub(crate) active_requests: u32,
pub(crate) importing_requests: u32,
pub(crate) failed_requests: u32,
_priv: ()
}
impl<B: BlockT> ExtraRequests<B> {
pub(crate) fn new(request_type_name: &'static str) -> Self {
ExtraRequests {
@@ -240,6 +249,18 @@ impl<B: BlockT> ExtraRequests<B> {
pub(crate) fn pending_requests(&self) -> impl Iterator<Item = &ExtraRequest<B>> {
self.pending_requests.iter()
}
/// Get some key metrics.
pub(crate) fn metrics(&self) -> Metrics {
use std::convert::TryInto;
Metrics {
pending_requests: self.pending_requests.len().try_into().unwrap_or(std::u32::MAX),
active_requests: self.active_requests.len().try_into().unwrap_or(std::u32::MAX),
failed_requests: self.failed_requests.len().try_into().unwrap_or(std::u32::MAX),
importing_requests: self.importing_requests.len().try_into().unwrap_or(std::u32::MAX),
_priv: ()
}
}
}
/// Matches peers with pending extra requests.