Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

R4R: prometheus exporter in substrate #4511

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
40762b6
Refactor rebase master prometheus_v0.3
nodebreaker0-0 Nov 28, 2019
472aca1
Milestone1: Final Version of v0.3
nodebreaker0-0 Dec 10, 2019
1974f94
no-std or warm compatibility issues, grapana-data -source code refere…
nodebreaker0-0 Jan 2, 2020
62a873d
Cargo.lock paritytech/master rebase
nodebreaker0-0 Jan 2, 2020
97e37e4
prometheus networking.rs del, grafana-data-source networking.rs pub e…
nodebreaker0-0 Jan 3, 2020
f3e444e
chore: reflect various feedback
nodebreaker0-0 Jan 10, 2020
8145df7
Spaces to tabs.
gavofyork Jan 6, 2020
fca71be
Replace grafana and tidy
expenses Jan 10, 2020
855ceed
Add generics
expenses Jan 10, 2020
70c6bcc
Add photo back
expenses Jan 10, 2020
5941041
Re-fix spaces in primitives/consensus/babe/src/inherents.rs
expenses Jan 10, 2020
7d9d341
Refactor rebase master prometheus_v0.3
nodebreaker0-0 Nov 28, 2019
52316ae
Milestone1: Final Version of v0.3
nodebreaker0-0 Dec 10, 2019
82cd8cf
no-std or warm compatibility issues, grapana-data -source code refere…
nodebreaker0-0 Jan 2, 2020
b052829
prometheus networking.rs del, grafana-data-source networking.rs pub e…
nodebreaker0-0 Jan 3, 2020
4e831e9
chore: reflect various feedback
nodebreaker0-0 Jan 10, 2020
0b15bc4
Replace grafana and tidy
expenses Jan 10, 2020
8025361
Add generics
expenses Jan 10, 2020
fd081c9
Add photo back
expenses Jan 10, 2020
f00bb9b
Re-fix spaces in primitives/consensus/babe/src/inherents.rs
expenses Jan 10, 2020
398da97
chore: revert this file back to paritytech/master inherents.rs.
nodebreaker0-0 Jan 14, 2020
84c458f
Add newline at EOF
expenses Jan 14, 2020
f931588
Merge remote-tracking branch 'nodebreaker/prometheus_v0.3' into ashle…
expenses Jan 16, 2020
5796c85
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 16, 2020
2a45de8
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 16, 2020
8bae73b
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 17, 2020
1caa0f1
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 17, 2020
ffb4746
Tidy
expenses Jan 17, 2020
8a6e3c5
Use local registry
expenses Jan 17, 2020
53c95de
fix typo
hskang9 Jan 17, 2020
23cb72e
chore: Apply review feedback
nodebreaker0-0 Jan 20, 2020
3d1634b
Merge remote-tracking branch 'nodebreaker/prometheus_v0.3' into ashle…
expenses Jan 20, 2020
55ac4f8
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 20, 2020
3cfe43c
endpoint -> exporter
expenses Jan 20, 2020
0af2369
fix readme
expenses Jan 20, 2020
44f8c0e
Merge pull request #3 from paritytech/ashley-prometheus
nodebreaker0-0 Jan 21, 2020
d2bba61
Remove lazy_static, use ServiceMetrics struct instead
expenses Jan 21, 2020
5d3d9a7
Merge pull request #4 from paritytech/ashley-prometheus
nodebreaker0-0 Jan 22, 2020
32c04b4
Merge branch 'paritytech/master' into prometheus_v0.3
mxinden Jan 23, 2020
9bde830
Switch to using GaugeVecs
expenses Jan 23, 2020
97faad6
Merge pull request #5 from mxinden/prometheus_v0.3
nodebreaker0-0 Jan 24, 2020
f64a482
chore: without nightly , edit README
nodebreaker0-0 Jan 24, 2020
5d56d93
Merge branch 'prometheus_v0.3' into ashley-prometheus
nodebreaker0-0 Jan 24, 2020
50f2928
block_height -> block_height_number
expenses Jan 27, 2020
8edb710
Merge branch 'ashley-prometheus' of github.com:paritytech/substrate i…
expenses Jan 27, 2020
6a25ea8
Switch to a ready_transactions_number gauge
expenses Jan 29, 2020
18cf2be
Merge pull request #7 from paritytech/ashley-prometheus
nodebreaker0-0 Jan 29, 2020
bb388f5
Update utils/prometheus/src/lib.rs
hskang9 Jan 31, 2020
77ba252
no-prometheus flag add
nodebreaker0-0 Jan 31, 2020
5e327c2
/metrics url Input check
nodebreaker0-0 Jan 31, 2020
ccb3179
remove prometheus in Tracing
nodebreaker0-0 Feb 5, 2020
152176f
remove prometheus in Tracing
nodebreaker0-0 Feb 14, 2020
8de57c2
Merge branch 'master' into prometheus_v0.3
nodebreaker0-0 Feb 14, 2020
e76f200
chore: master code rebase edit
nodebreaker0-0 Feb 14, 2020
55428b7
gitlab-check-web-wasm edit code
nodebreaker0-0 Feb 14, 2020
d1003e6
From:from and cargo.lock update
nodebreaker0-0 Feb 17, 2020
5c2e085
Merge commit 'db1ab7d18fbe7876cdea43bbf30f147ddd263f94' into promethe…
nodebreaker0-0 Feb 17, 2020
b4b4432
with_prometheus_registry add background_tasks
nodebreaker0-0 Feb 17, 2020
ee421a6
Merge commit '419e5fd0026cfd528cd3b327789bb0a3a8215703' into promethe…
nodebreaker0-0 Feb 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 68 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ members = [
"client/telemetry",
"client/transaction-pool",
"client/transaction-pool/graph",
"utils/prometheus",
"utils/wasm-builder-runner",
"utils/grafana-data-source",
"utils/grafana-data-source/test",
Expand Down
1 change: 1 addition & 0 deletions client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sp-core = { version = "2.0.0", path = "../../primitives/core" }
sc-service = { version = "2.0.0", default-features = false, path = "../service" }
sp-state-machine = { version = "2.0.0", path = "../../primitives/state-machine" }
sc-telemetry = { version = "2.0.0", path = "../telemetry" }
sc-prometheus = { path = "../../utils/prometheus" }
sp-keyring = { version = "2.0.0", path = "../../primitives/keyring" }
names = "0.11.0"
structopt = "=0.3.7"
Expand Down
7 changes: 5 additions & 2 deletions client/cli/src/informant/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sc_network::SyncState;
use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Zero, Saturating};
use sc_service::NetworkStatus;
use std::{convert::{TryFrom, TryInto}, fmt, time};

use sc_prometheus::prometheus_gauge;
/// State of the informant display system.
///
/// This is the system that handles the line that gets regularly printed and that looks something
Expand Down Expand Up @@ -63,7 +63,10 @@ impl<B: BlockT> InformantDisplay<B> {
let (status, target) = match (net_status.sync_state, net_status.best_seen_block) {
(SyncState::Idle, _) => ("Idle".into(), "".into()),
(SyncState::Downloading, None) => (format!("Syncing{}", speed), "".into()),
(SyncState::Downloading, Some(n)) => (format!("Syncing{}", speed), format!(", target=#{}", n)),
(SyncState::Downloading, Some(n)) => {
prometheus_gauge!(TARGET_NUM => n.saturated_into().try_into().unwrap());
(format!("Syncing{}", speed), format!(", target=#{}", n))
}
};

info!(
Expand Down
8 changes: 7 additions & 1 deletion client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ where
let rpc_interface: &str = interface_str(cli.rpc_external, cli.unsafe_rpc_external, cli.validator)?;
let ws_interface: &str = interface_str(cli.ws_external, cli.unsafe_ws_external, cli.validator)?;
let grafana_interface: &str = if cli.grafana_external { "0.0.0.0" } else { "127.0.0.1" };
let prometheus_interface: &str = if cli.prometheus_external { "0.0.0.0" } else { "127.0.0.1" };

config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9933), cli.rpc_port)?);
config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9944), cli.ws_port)?);
Expand Down Expand Up @@ -941,7 +942,12 @@ where

config.tracing_targets = cli.tracing_targets.into();
config.tracing_receiver = cli.tracing_receiver.into();


// Override prometheus
if cli.prometheus_external {
config.prometheus_port = Some(
parse_address(&format!("{}:{}", prometheus_interface, 33333), cli.prometheus_port)?
)}
// Imply forced authoring on --dev
config.force_authoring = cli.shared_params.dev || cli.force_authoring;

Expand Down
6 changes: 6 additions & 0 deletions client/cli/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ pub struct RunCmd {
/// Use `--unsafe-ws-external` to suppress the warning if you understand the risks.
#[structopt(long = "ws-external")]
pub ws_external: bool,
/// Prometheus exporter TCP port.
#[structopt(long = "prometheus-port", value_name = "PORT")]
pub prometheus_port: Option<u16>,
/// Prometheus exporter on/off external".
#[structopt(long = "prometheus-external")]
pub prometheus_external: bool,

/// Listen to all Websocket interfaces.
///
Expand Down
1 change: 1 addition & 0 deletions client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ parity-multiaddr = { package = "parity-multiaddr", version = "0.5.0" }
grafana-data-source = { version = "2.0.0", path = "../../utils/grafana-data-source" }
sc-tracing = { version = "2.0.0", path = "../tracing" }
tracing = "0.1.10"
sc-prometheus = { package = "sc-prometheus", path="../../utils/prometheus"}

[dev-dependencies]
substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" }
Expand Down
28 changes: 25 additions & 3 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ use std::{
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
use sc_telemetry::{telemetry, SUBSTRATE_INFO};
use sp_transaction_pool::{TransactionPool, TransactionPoolMaintainer};
use sc_prometheus::prometheus_gauge;

use sp_blockchain;
use grafana_data_source::{self, record_metrics};

Expand Down Expand Up @@ -954,6 +956,17 @@ ServiceBuilder<
"bandwidth_upload" => bandwidth_upload,
"used_state_cache_size" => used_state_cache_size,
);
prometheus_gauge!(
STATE_CACHE_SIZE => used_state_cache_size as u64,
NODE_MEMORY => memory as u64,
NODE_CPU => cpu_usage as u64,
TX_COUNT => txpool_status.ready as u64,
FINALITY_HEIGHT => finalized_number as u64,
BEST_HEIGHT => best_number as u64,
P2P_PEERS_NUM => num_peers as u64,
P2P_NODE_DOWNLOAD => net_status.average_download_per_sec as u64,
P2P_NODE_UPLOAD => net_status.average_upload_per_sec as u64
);
let _ = record_metrics!(
"peers" => num_peers,
"height" => best_number,
Expand All @@ -964,8 +977,7 @@ ServiceBuilder<
"bandwidth_download" => bandwidth_download,
"bandwidth_upload" => bandwidth_upload,
"used_state_cache_size" => used_state_cache_size,
);

);
Ok(())
}).select(exit.clone().map(Ok).compat()).then(|_| Ok(()));
let _ = to_spawn_tx.unbounded_send(Box::new(tel_task));
Expand Down Expand Up @@ -1103,7 +1115,17 @@ ServiceBuilder<
.then(|_| Ok(()))));
telemetry
});

// prometheus init
if let Some(port) = config.prometheus_port {
let future = select(
sc_prometheus::init_prometheus(port).boxed()
expenses marked this conversation as resolved.
Show resolved Hide resolved
,exit.clone()
).map(|either| match either {
Either::Left((result, _)) => result.map_err(|_| ()),
Either::Right(_) => Ok(())
}).compat();
let _ = to_spawn_tx.unbounded_send(Box::new(future));
}
// Grafana data source
if let Some(port) = config.grafana_port {
let future = select(
Expand Down
3 changes: 3 additions & 0 deletions client/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub struct Configuration<C, G, E = NoExtension> {
pub rpc_cors: Option<Vec<String>>,
/// Grafana data source http port. `None` if disabled.
pub grafana_port: Option<SocketAddr>,
/// Promteheus Port. `None` if disabled. and defult port 33333
nodebreaker0-0 marked this conversation as resolved.
Show resolved Hide resolved
pub prometheus_port: Option<SocketAddr>,
/// Telemetry service URL. `None` if disabled.
pub telemetry_endpoints: Option<TelemetryEndpoints>,
/// External WASM transport for the telemetry. If `Some`, when connection to a telemetry
Expand Down Expand Up @@ -153,6 +155,7 @@ impl<C, G, E> Configuration<C, G, E> where
rpc_ws: None,
rpc_ws_max_connections: None,
rpc_cors: Some(vec![]),
prometheus_port: None,
grafana_port: None,
telemetry_endpoints: None,
telemetry_external_transport: None,
Expand Down
1 change: 1 addition & 0 deletions client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ fn node_config<G, E: Clone> (
rpc_ws: None,
rpc_ws_max_connections: None,
rpc_cors: None,
prometheus_port: None,
grafana_port: None,
telemetry_endpoints: None,
telemetry_external_transport: None,
Expand Down
2 changes: 1 addition & 1 deletion utils/grafana-data-source/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use parking_lot::RwLock;
mod types;
expenses marked this conversation as resolved.
Show resolved Hide resolved
mod server;
#[cfg(not(target_os = "unknown"))]
mod networking;
pub mod networking;
mod database;

use database::Database;
Expand Down
20 changes: 20 additions & 0 deletions utils/prometheus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "sc-prometheus"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "prometheus utils"
edition = "2018"

[dependencies]
hyper = { version = "0.13.1", default-features = false, features = ["stream"] }
lazy_static = "1.4"
log = "0.4.8"
prometheus = { version = "0.7", features = ["nightly", "process"]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand correctly that nightly enables features which are only available with Rust nightly? If I am not mistaken we don't build Substrate with Rust nightly as of today.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It compiles for me on stable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check if these features are needed though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiles and exposes metrics just fine without nightly, @nodebreaker0-0 can you please remove the flag, unless we are missing something.

tokio = "0.2"
futures-util = { version = "0.3.1", default-features = false, features = ["io"] }
sp-runtime = { package = "sp-runtime",path = "../../primitives/runtime" }
derive_more = "0.99"
grafana-data-source = { version = "2.0.0", path = "../grafana-data-source" }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
async-std = { version = "1.0.1", features = ["unstable"] }
nodebreaker0-0 marked this conversation as resolved.
Show resolved Hide resolved
Loading