This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add more metrics to prometheus #5034
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a522a58
Add a few things
expenses 790ad91
Add finality_grandpa_round
expenses 2062bb0
fix fg tests
expenses 81fd6ae
Merge remote-tracking branch 'parity/master' into ashley-more-metrics
expenses 5acd634
Merge remote-tracking branch 'parity/master' into ashley-more-metrics
expenses 8c85687
Merge remote-tracking branch 'parity/master' into ashley-more-metrics
expenses 3b22f98
Nitpicks
expenses fc1ad16
Nitpicks
expenses 7aae893
Merge remote-tracking branch 'parity/master' into ashley-more-metrics
expenses 3845670
Merge remote-tracking branch 'parity/master' into ashley-more-metrics
expenses 66f245a
Fix name of prometheus crate
expenses ba296bd
Merge remote-tracking branch 'parity/master' into ashley-more-metrics
expenses File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ use libp2p::swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent}; | |
use parking_lot::Mutex; | ||
use sc_peerset::PeersetHandle; | ||
use sp_runtime::{traits::{Block as BlockT, NumberFor}, ConsensusEngineId}; | ||
use prometheus_endpoint::{Registry, Gauge, U64, register, PrometheusError}; | ||
|
||
use crate::{behaviour::{Behaviour, BehaviourOut}, config::{parse_str_addr, parse_addr}}; | ||
use crate::{transport, config::NonReservedPeerMode, ReputationChange}; | ||
|
@@ -294,6 +295,10 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> { | |
from_worker, | ||
light_client_rqs: params.on_demand.and_then(|od| od.extract_receiver()), | ||
event_streams: Vec::new(), | ||
metrics: match params.metrics_registry { | ||
Some(registry) => Some(Metrics::register(®istry)?), | ||
None => None | ||
} | ||
}) | ||
} | ||
|
||
|
@@ -727,6 +732,26 @@ pub struct NetworkWorker<B: BlockT + 'static, H: ExHashT> { | |
light_client_rqs: Option<mpsc::UnboundedReceiver<RequestData<B>>>, | ||
/// Senders for events that happen on the network. | ||
event_streams: Vec<mpsc::UnboundedSender<Event>>, | ||
/// Prometheus network metrics. | ||
metrics: Option<Metrics> | ||
} | ||
|
||
struct Metrics { | ||
is_major_syncing: Gauge<U64>, | ||
peers_count: Gauge<U64>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving this to |
||
} | ||
|
||
impl Metrics { | ||
fn register(registry: &Registry) -> Result<Self, PrometheusError> { | ||
Ok(Self { | ||
is_major_syncing: register(Gauge::new( | ||
"is_major_syncing", "Whether the node is performing a major sync or not.", | ||
)?, registry)?, | ||
peers_count: register(Gauge::new( | ||
"peers_count", "Number of network gossip peers", | ||
)?, registry)?, | ||
}) | ||
} | ||
} | ||
|
||
impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> { | ||
|
@@ -818,16 +843,26 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> { | |
}; | ||
} | ||
|
||
let num_connected_peers = this.network_service.user_protocol_mut().num_connected_peers(); | ||
|
||
// Update the variables shared with the `NetworkService`. | ||
this.num_connected.store(this.network_service.user_protocol_mut().num_connected_peers(), Ordering::Relaxed); | ||
this.num_connected.store(num_connected_peers, Ordering::Relaxed); | ||
{ | ||
let external_addresses = Swarm::<B, H>::external_addresses(&this.network_service).cloned().collect(); | ||
*this.external_addresses.lock() = external_addresses; | ||
} | ||
this.is_major_syncing.store(match this.network_service.user_protocol_mut().sync_state() { | ||
|
||
let is_major_syncing = match this.network_service.user_protocol_mut().sync_state() { | ||
SyncState::Idle => false, | ||
SyncState::Downloading => true, | ||
}, Ordering::Relaxed); | ||
}; | ||
|
||
this.is_major_syncing.store(is_major_syncing, Ordering::Relaxed); | ||
|
||
if let Some(metrics) = this.metrics.as_ref() { | ||
metrics.is_major_syncing.set(is_major_syncing as u64); | ||
metrics.peers_count.set(num_connected_peers as u64); | ||
} | ||
|
||
Poll::Pending | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
environment.rs
as a source of truth for the current round was a guess from my side. @andresilva could you approve that that is a good idea?