Additional Metrics collected and exposed via prometheus (#5414)

This PR refactors the metrics measuring and Prometheus exposing entity in sc-service into its own submodule and extends the parameters it exposes by:

- system load average (over one, five and 15min)
- the TCP connection state of the process (lsof), refs #5304
- number of tokio threads
- number of known forks
- counter for items in each unbounded queue (with internal unbounded channels)
- number of file descriptors opened by this process (*nix only at this point)
- number of system threads (*nix only at this point)

refs #4679

Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Ashley <ashley.ruglys@gmail.com>
This commit is contained in:
Benjamin Kampmann
2020-04-04 15:13:35 +02:00
committed by GitHub
parent 6847f8452e
commit 247822bb33
60 changed files with 1344 additions and 526 deletions
+5 -5
View File
@@ -21,7 +21,6 @@ use std::{
result,
};
use log::{info, trace, warn};
use futures::channel::mpsc;
use parking_lot::{Mutex, RwLock};
use codec::{Encode, Decode};
use hash_db::Prefix;
@@ -78,6 +77,7 @@ pub use sc_client_api::{
notifications::{StorageNotifications, StorageEventStream},
CallExecutor, ExecutorProvider, ProofProvider, CloneableSpawn,
};
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedSender};
use sp_blockchain::Error;
use prometheus_endpoint::Registry;
@@ -93,8 +93,8 @@ pub struct Client<B, E, Block, RA> where Block: BlockT {
backend: Arc<B>,
executor: E,
storage_notifications: Mutex<StorageNotifications<Block>>,
import_notification_sinks: Mutex<Vec<mpsc::UnboundedSender<BlockImportNotification<Block>>>>,
finality_notification_sinks: Mutex<Vec<mpsc::UnboundedSender<FinalityNotification<Block>>>>,
import_notification_sinks: Mutex<Vec<TracingUnboundedSender<BlockImportNotification<Block>>>>,
finality_notification_sinks: Mutex<Vec<TracingUnboundedSender<FinalityNotification<Block>>>>,
// holds the block hash currently being imported. TODO: replace this with block queue
importing_block: RwLock<Option<Block::Hash>>,
block_rules: BlockRules<Block>,
@@ -1764,13 +1764,13 @@ where
{
/// Get block import event stream.
fn import_notification_stream(&self) -> ImportNotifications<Block> {
let (sink, stream) = mpsc::unbounded();
let (sink, stream) = tracing_unbounded("mpsc_import_notification_stream");
self.import_notification_sinks.lock().push(sink);
stream
}
fn finality_notification_stream(&self) -> FinalityNotifications<Block> {
let (sink, stream) = mpsc::unbounded();
let (sink, stream) = tracing_unbounded("mpsc_finality_notification_stream");
self.finality_notification_sinks.lock().push(sink);
stream
}
+1
View File
@@ -304,6 +304,7 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
genesis_hash: storage.genesis_hash,
finalized_hash: storage.finalized_hash,
finalized_number: storage.finalized_number,
number_leaves: storage.leaves.count()
}
}
+5
View File
@@ -195,6 +195,11 @@ impl<H, N> LeafSet<H, N> where
self.storage.iter().flat_map(|(_, hashes)| hashes.iter()).cloned().collect()
}
/// Number of known leaves
pub fn count(&self) -> usize {
self.storage.len()
}
/// Write the leaf list to the database transaction.
pub fn prepare_transaction(&mut self, tx: &mut DBTransaction, column: u32, prefix: &[u8]) {
let mut buf = prefix.to_vec();