Skip to content

Commit 9483b4c

Browse files
committed
propagated PrometheusMetrics to additional modules.
- Client - Host - Network gathering details about those modules. reworked locking and DB metrics discovery
1 parent cae76c8 commit 9483b4c

File tree

11 files changed

+211
-19
lines changed

11 files changed

+211
-19
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/oe/db/rocksdb/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ impl BlockChainDB for AppDB {
5555
}
5656

5757
impl PrometheusMetrics for AppDB {
58-
fn prometheus_metrics(&self, _: &mut stats::PrometheusRegistry) {}
58+
fn prometheus_metrics(&self, r: &mut stats::PrometheusRegistry) {
59+
self.key_value.prometheus_metrics(r);
60+
}
5961
}
6062

6163
/// Open a secret store DB using the given secret store data path. The DB path is one level beneath the data path.

crates/ethcore/src/client/client.rs

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use std::{
18-
cmp,
18+
cmp::{self},
1919
collections::{BTreeMap, HashSet, VecDeque},
2020
convert::TryFrom,
2121
io::{BufRead, BufReader},
@@ -194,6 +194,28 @@ struct Importer {
194194
pub bad_blocks: bad_blocks::BadBlocks,
195195
}
196196

197+
#[derive(Default)]
198+
struct ClientStatistics {
199+
logging_enabled: bool,
200+
broadcasted_consensus_messages: AtomicU64,
201+
broadcasted_consensus_messages_bytes: AtomicU64,
202+
sent_consensus_messages: AtomicU64,
203+
sent_consensus_messages_bytes: AtomicU64,
204+
}
205+
206+
207+
impl PrometheusMetrics for ClientStatistics {
208+
209+
fn prometheus_metrics(&self, r: &mut PrometheusRegistry) {
210+
if self.logging_enabled {
211+
r.register_counter("consens_messages_sent", "", self.sent_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64);
212+
r.register_counter("consens_messages_sent_bytes", "", self.sent_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64);
213+
r.register_counter("consens_messages_broadcasted", "", self.broadcasted_consensus_messages.load(std::sync::atomic::Ordering::Relaxed) as i64);
214+
r.register_counter("consens_messages_broadcasted_bytes", "", self.broadcasted_consensus_messages_bytes.load(std::sync::atomic::Ordering::Relaxed) as i64);
215+
}
216+
}
217+
}
218+
197219
/// Blockchain database client backed by a persistent database. Owns and manages a blockchain and a block queue.
198220
/// Call `import_block()` to import a block asynchronously; `flush_queue()` flushes the queue.
199221
pub struct Client {
@@ -264,6 +286,8 @@ pub struct Client {
264286
importer: Importer,
265287

266288
shutdown: ShutdownManager,
289+
290+
statistics: ClientStatistics,
267291
}
268292

269293
impl Importer {
@@ -1030,6 +1054,9 @@ impl Client {
10301054
trace!(target: "client", "Found registrar at {}", addr);
10311055
}
10321056

1057+
let mut statistics = ClientStatistics::default();
1058+
statistics.logging_enabled = true;
1059+
10331060
let client = Arc::new(Client {
10341061
enabled: AtomicBool::new(true),
10351062
sleep_state: Mutex::new(SleepState::new(awake)),
@@ -1060,6 +1087,7 @@ impl Client {
10601087
importer,
10611088
config,
10621089
shutdown,
1090+
statistics,
10631091
});
10641092

10651093
let exec_client = client.clone();
@@ -3226,10 +3254,24 @@ impl super::traits::EngineClient for Client {
32263254
}
32273255

32283256
fn broadcast_consensus_message(&self, message: Bytes) {
3257+
self.statistics
3258+
.broadcasted_consensus_messages
3259+
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
3260+
self.statistics
3261+
.broadcasted_consensus_messages_bytes
3262+
.fetch_add(message.len() as u64, std::sync::atomic::Ordering::Relaxed);
3263+
32293264
self.notify(|notify| notify.broadcast(ChainMessageType::Consensus(message.clone())));
32303265
}
32313266

32323267
fn send_consensus_message(&self, message: Bytes, node_id: Option<H512>) {
3268+
self.statistics
3269+
.sent_consensus_messages
3270+
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
3271+
self.statistics
3272+
.sent_consensus_messages_bytes
3273+
.fetch_add(message.len() as u64, std::sync::atomic::Ordering::Relaxed);
3274+
32333275
self.notify(|notify| notify.send(ChainMessageType::Consensus(message.clone()), node_id));
32343276
}
32353277

@@ -3593,8 +3635,10 @@ impl PrometheusMetrics for Client {
35933635
report.transactions_applied as i64,
35943636
);
35953637

3638+
let lockd = Duration::from_millis(50);
3639+
35963640
self.state_db
3597-
.try_read_for(Duration::from_millis(200))
3641+
.try_read_for(lockd)
35983642
.map(|state_db| {
35993643
let state_db_size = state_db.cache_size();
36003644
r.register_gauge(
@@ -3712,12 +3756,14 @@ impl PrometheusMetrics for Client {
37123756
queue.verifying_queue_size as i64,
37133757
);
37143758

3715-
// database info
3716-
self.db.read().key_value().prometheus_metrics(r);
3759+
if let Some(db) = self.db.try_read_for(lockd) {
3760+
db.prometheus_metrics(r);
3761+
};
37173762

37183763
// engine specific metrics.
3719-
37203764
self.engine.prometheus_metrics(r);
3765+
3766+
self.statistics.prometheus_metrics(r);
37213767
}
37223768
}
37233769

crates/ethcore/src/engines/hbbft/block_reward_hbbft.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use engines::{SystemOrCodeCall, SystemOrCodeCallKind};
2121
use error::Error;
2222
use ethabi::FunctionOutputDecoder;
2323
use ethabi_contract::use_contract;
24-
use ethereum_types::{Address, U256};
24+
use ethereum_types::Address;
2525

2626
use_contract!(
2727
block_reward_contract,

crates/ethcore/src/engines/hbbft/keygen_transactions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use engines::{
1616
},
1717
signer::EngineSigner,
1818
};
19-
use ethereum_types::{Address, Public, U256};
19+
use ethereum_types::{Address, U256};
2020
use itertools::Itertools;
2121
use parking_lot::RwLock;
2222
use std::{collections::BTreeMap, sync::Arc};
@@ -281,7 +281,7 @@ impl KeygenTransactionSender {
281281
for ack in acks {
282282
let ack_to_push = match bincode::serialize(&ack) {
283283
Ok(serialized_ack) => serialized_ack,
284-
Err(e) => return Err(KeyGenError::Unexpected),
284+
Err(_) => return Err(KeyGenError::Unexpected),
285285
};
286286
total_bytes_for_acks += ack_to_push.len();
287287
serialized_acks.push(ack_to_push);

crates/ethcore/sync/src/api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ impl PrometheusMetrics for EthSync {
447447
"First block number of the present snapshot",
448448
manifest_block_num as i64,
449449
);
450+
451+
self.network.prometheus_metrics(r);
450452
}
451453
}
452454

crates/net/network-devp2p/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ parity-bytes = "0.1"
2323
parity-crypto = { version = "0.6.2", features = [ "publickey" ] }
2424
ethcore-network = { path = "../network" }
2525
ethereum-types = "0.9.2"
26-
ethkey = { path = "../../../crates/accounts/ethkey" }
26+
ethkey = { path = "../../accounts/ethkey" }
2727
rlp = { version = "0.4.6" }
2828
parity-path = "0.1"
2929
ipnetwork = "0.12.6"
@@ -34,6 +34,7 @@ serde_json = "1.0"
3434
serde_derive = "1.0"
3535
error-chain = { version = "0.12", default-features = false }
3636
lru-cache = "0.1"
37+
stats = { path = "../../util/stats" }
3738

3839
[dev-dependencies]
3940
env_logger = "0.5"

0 commit comments

Comments
 (0)