diff --git a/Cargo.lock b/Cargo.lock index 194716611f7f2..010acdb334062 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -500,7 +500,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1676,34 +1675,6 @@ dependencies = [ "scroll 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "grafana-data-source" -version = "2.0.0" -dependencies = [ - "async-std 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "grafana-data-source-test" -version = "2.0.0" -dependencies = [ - "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "grafana-data-source 2.0.0", - "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "h2" version = "0.1.26" @@ -4451,6 +4422,20 @@ dependencies = [ "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "prometheus-endpoint" +version = "2.0.0" +dependencies = [ + "async-std 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "prometheus 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "prost" version = "0.5.0" @@ -5063,11 +5048,11 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "names 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "prometheus-endpoint 2.0.0", "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "sc-client-api 2.0.0", "sc-network 0.8.0", - "sc-prometheus 2.0.0", "sc-service 2.0.0", "sc-telemetry 2.0.0", "sc-tracing 2.0.0", @@ -5595,22 +5580,6 @@ dependencies = [ "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sc-prometheus" -version = "2.0.0" -dependencies = [ - "async-std 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "derive_more 0.99.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "grafana-data-source 2.0.0", - "hyper 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "prometheus 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-runtime 2.0.0", - "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sc-rpc" version = "2.0.0" @@ -5702,12 +5671,12 @@ dependencies = [ "exit-future 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "grafana-data-source 2.0.0", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "prometheus-endpoint 2.0.0", "sc-chain-spec 2.0.0", "sc-client 2.0.0", "sc-client-api 2.0.0", @@ -5717,7 +5686,6 @@ dependencies = [ "sc-keystore 2.0.0", "sc-network 0.8.0", "sc-offchain 2.0.0", - "sc-prometheus 2.0.0", "sc-rpc 2.0.0", "sc-rpc-server 2.0.0", "sc-telemetry 2.0.0", @@ -5803,7 +5771,6 @@ name = "sc-tracing" version = "2.0.0" dependencies = [ "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "grafana-data-source 2.0.0", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "sc-telemetry 2.0.0", diff --git a/Cargo.toml b/Cargo.toml index e5940e5b7cdf1..219b1588f9618 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,8 +50,6 @@ members = [ "client/transaction-pool/graph", "utils/prometheus", "utils/wasm-builder-runner", - "utils/grafana-data-source", - "utils/grafana-data-source/test", "frame/assets", "frame/aura", "frame/authority-discovery", diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index 5c7ac86904164..05fc019d0a9d9 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -29,7 +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" } +prometheus-endpoint = { path = "../../utils/prometheus" } sp-keyring = { version = "2.0.0", path = "../../primitives/keyring" } names = "0.11.0" structopt = "=0.3.7" diff --git a/client/cli/src/informant/display.rs b/client/cli/src/informant/display.rs index f0b6e61176de7..3f0c1b8d60604 100644 --- a/client/cli/src/informant/display.rs +++ b/client/cli/src/informant/display.rs @@ -18,10 +18,20 @@ use ansi_term::Colour; use sc_client_api::ClientInfo; use log::info; use sc_network::SyncState; -use sp_runtime::traits::{Block as BlockT, CheckedDiv, NumberFor, Zero, Saturating}; +use sp_runtime::traits::{ + Block as BlockT, CheckedDiv, NumberFor, Zero, Saturating, UniqueSaturatedInto +}; use sc_service::NetworkStatus; use std::{convert::{TryFrom, TryInto}, fmt, time}; -use sc_prometheus::prometheus_gauge; +use prometheus_endpoint::{create_gauge, Gauge, U64}; + +prometheus_endpoint::lazy_static! { + pub static ref SYNC_TARGET: Gauge = create_gauge( + "sync_target_number", + "block sync target number" + ); +} + /// State of the informant display system. /// /// This is the system that handles the line that gets regularly printed and that looks something @@ -64,7 +74,7 @@ impl InformantDisplay { (SyncState::Idle, _) => ("Idle".into(), "".into()), (SyncState::Downloading, None) => (format!("Syncing{}", speed), "".into()), (SyncState::Downloading, Some(n)) => { - prometheus_gauge!(TARGET_NUM => n.saturated_into().try_into().unwrap()); + SYNC_TARGET.set(n.unique_saturated_into() as u64); (format!("Syncing{}", speed), format!(", target=#{}", n)) } }; diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 36bf19eedd0ec..c92b764b247ca 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -909,13 +909,12 @@ 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)?); - config.grafana_port = Some( - parse_address(&format!("{}:{}", grafana_interface, 9955), cli.grafana_port)? + config.prometheus_port = Some( + parse_address(&format!("{}:{}", prometheus_interface, 9955), cli.prometheus_port)? ); config.rpc_ws_max_connections = cli.ws_max_connections; @@ -942,12 +941,7 @@ 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; diff --git a/client/cli/src/params.rs b/client/cli/src/params.rs index 3fd521b1334b9..377e2c1dc0def 100644 --- a/client/cli/src/params.rs +++ b/client/cli/src/params.rs @@ -298,7 +298,7 @@ arg_enum! { pub enum TracingReceiver { Log, Telemetry, - Grafana, + Prometheus, } } @@ -307,7 +307,7 @@ impl Into for TracingReceiver { match self { TracingReceiver::Log => sc_tracing::TracingReceiver::Log, TracingReceiver::Telemetry => sc_tracing::TracingReceiver::Telemetry, - TracingReceiver::Grafana => sc_tracing::TracingReceiver::Grafana, + TracingReceiver::Prometheus => sc_tracing::TracingReceiver::Prometheus, } } } @@ -440,12 +440,6 @@ 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, - /// Prometheus exporter on/off external". - #[structopt(long = "prometheus-external")] - pub prometheus_external: bool, /// Listen to all Websocket interfaces. /// @@ -453,11 +447,11 @@ pub struct RunCmd { #[structopt(long = "unsafe-ws-external")] pub unsafe_ws_external: bool, - /// Listen to all Grafana data source interfaces. + /// Listen to all Prometheus endpoint interfaces. /// /// Default is local. - #[structopt(long = "grafana-external")] - pub grafana_external: bool, + #[structopt(long = "prometheus-external")] + pub prometheus_external: bool, /// Specify HTTP RPC server TCP port. #[structopt(long = "rpc-port", value_name = "PORT")] @@ -481,9 +475,9 @@ pub struct RunCmd { #[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = parse_cors))] pub rpc_cors: Option, - /// Specify Grafana data source server TCP Port. - #[structopt(long = "grafana-port", value_name = "PORT")] - pub grafana_port: Option, + /// Specify Prometheus endpoint TCP Port. + #[structopt(long = "prometheus-port", value_name = "PORT")] + pub prometheus_port: Option, /// The human-readable name for this node. /// diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index 887e8415f39b7..42f0a73dfbfa2 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -51,10 +51,9 @@ sc-rpc = { version = "2.0.0", path = "../rpc" } sc-telemetry = { version = "2.0.0", path = "../telemetry" } sc-offchain = { version = "2.0.0", path = "../offchain" } parity-multiaddr = { package = "parity-multiaddr", version = "0.5.0" } -grafana-data-source = { version = "2.0.0", path = "../../utils/grafana-data-source" } +prometheus-endpoint = { path = "../../utils/prometheus" } 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" } diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 424f47d57a614..9f17ad4a1ce28 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -53,11 +53,43 @@ 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}; - +use prometheus_endpoint::{create_gauge, Gauge, U64, F64}; + +prometheus_endpoint::lazy_static! { + pub static ref FINALITY_HEIGHT: Gauge = create_gauge( + "consensus_finality_block_height_number", + "block is finality HEIGHT" + ); + pub static ref BEST_HEIGHT: Gauge = create_gauge( + "consensus_best_block_height_number", + "block is best HEIGHT" + ); + pub static ref P2P_PEERS_NUM: Gauge = create_gauge( + "p2p_peers_number", + "network gosip peers number" + ); + pub static ref TX_COUNT: Gauge = create_gauge( + "consensus_num_txs", + "Number of transactions" + ); + pub static ref NODE_MEMORY: Gauge = create_gauge( + "consensus_node_memory", + "node memory" + ); + pub static ref NODE_CPU: Gauge = create_gauge( + "consensus_node_cpu", + "node cpu" + ); + pub static ref P2P_NODE_DOWNLOAD: Gauge = create_gauge( + "p2p_peers_receive_byte_per_sec", + "p2p_node_download_per_sec_byte" + ); + pub static ref P2P_NODE_UPLOAD: Gauge = create_gauge( + "p2p_peers_send_byte_per_sec", + "p2p_node_upload_per_sec_byte" + ); +} /// Aggregator for the components required to build a service. /// /// # Usage @@ -956,28 +988,14 @@ 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, - "txcount" => txpool_status.ready, - "cpu" => cpu_usage, - "memory" => memory, - "finalized_height" => finalized_number, - "bandwidth_download" => bandwidth_download, - "bandwidth_upload" => bandwidth_upload, - "used_state_cache_size" => used_state_cache_size, - ); + NODE_MEMORY.set(memory); + NODE_CPU.set(f64::from(cpu_usage)); + TX_COUNT.set(txpool_status.ready as u64); + FINALITY_HEIGHT.set(finalized_number); + BEST_HEIGHT.set(best_number); + P2P_PEERS_NUM.set(num_peers as u64); + P2P_NODE_DOWNLOAD.set(net_status.average_download_per_sec); + P2P_NODE_UPLOAD.set(net_status.average_upload_per_sec); Ok(()) }).select(exit.clone().map(Ok).compat()).then(|_| Ok(())); let _ = to_spawn_tx.unbounded_send(Box::new(tel_task)); @@ -1115,21 +1133,10 @@ ServiceBuilder< .then(|_| Ok(())))); telemetry }); - // prometheus init + // Prometheus endpoint if let Some(port) = config.prometheus_port { let future = select( - sc_prometheus::init_prometheus(port).boxed() - ,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( - grafana_data_source::run_server(port).boxed(), + prometheus_endpoint::init_prometheus(port).boxed(), exit.clone() ).map(|either| match either { Either::Left((result, _)) => result.map_err(|_| ()), @@ -1137,7 +1144,7 @@ ServiceBuilder< }).compat(); let _ = to_spawn_tx.unbounded_send(Box::new(future)); - } + } // Instrumentation if let Some(tracing_targets) = config.tracing_targets.as_ref() { diff --git a/client/service/src/config.rs b/client/service/src/config.rs index 2f0a2ba83a071..9f240a19affba 100644 --- a/client/service/src/config.rs +++ b/client/service/src/config.rs @@ -73,9 +73,7 @@ pub struct Configuration { pub rpc_ws_max_connections: Option, /// CORS settings for HTTP & WS servers. `None` if all origins are allowed. pub rpc_cors: Option>, - /// Grafana data source http port. `None` if disabled. - pub grafana_port: Option, - /// Prometheus Port.`None` if disabled and port 33333 by default. + /// Prometheus endpoint Port. `None` if disabled. pub prometheus_port: Option, /// Telemetry service URL. `None` if disabled. pub telemetry_endpoints: Option, @@ -156,7 +154,6 @@ impl Configuration where rpc_ws_max_connections: None, rpc_cors: Some(vec![]), prometheus_port: None, - grafana_port: None, telemetry_endpoints: None, telemetry_external_transport: None, default_heap_pages: None, diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index ea3e523d4ef0a..cf1baa06db6c8 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -193,7 +193,6 @@ fn node_config ( rpc_ws_max_connections: None, rpc_cors: None, prometheus_port: None, - grafana_port: None, telemetry_endpoints: None, telemetry_external_transport: None, default_heap_pages: None, diff --git a/client/tracing/Cargo.toml b/client/tracing/Cargo.toml index 2ceee93f6a62a..ed9b52fc26e20 100644 --- a/client/tracing/Cargo.toml +++ b/client/tracing/Cargo.toml @@ -15,7 +15,6 @@ slog = { version = "2.5.2", features = ["nested-values"] } tracing-core = "0.1.7" sc-telemetry = { version = "2.0.0", path = "../telemetry" } -grafana-data-source = { version = "2.0.0", path = "../../utils/grafana-data-source" } [dev-dependencies] tracing = "0.1.10" diff --git a/client/tracing/src/lib.rs b/client/tracing/src/lib.rs index 288d5e70192de..32dc27be158e0 100644 --- a/client/tracing/src/lib.rs +++ b/client/tracing/src/lib.rs @@ -34,7 +34,7 @@ //! let span = tracing::span!(tracing::Level::INFO, "my_span_name", my_number = 10, a_key = "a value"); //! let _guard = span.enter(); //! ``` -//! Currently we provide `Log` (default), `Telemetry` and `Grafana` variants for `Receiver` +//! Currently we provide `Log` (default), `Telemetry` and `Prometheus` variants for `Receiver` use std::collections::HashMap; use std::fmt; @@ -53,7 +53,6 @@ use tracing_core::{ subscriber::Subscriber }; -use grafana_data_source::{self, record_metrics}; use sc_telemetry::{telemetry, SUBSTRATE_INFO}; /// Used to configure how to receive the metrics @@ -63,8 +62,8 @@ pub enum TracingReceiver { Log, /// Output to telemetry Telemetry, - /// Output to Grafana - Grafana, + /// Output to Prometheus endpoint + Prometheus, } impl Default for TracingReceiver { @@ -255,7 +254,7 @@ impl ProfilingSubscriber { match self.receiver { TracingReceiver::Log => print_log(span_datum), TracingReceiver::Telemetry => send_telemetry(span_datum), - TracingReceiver::Grafana => send_grafana(span_datum), + TracingReceiver::Prometheus => send_prometheus(span_datum), } } } @@ -291,9 +290,6 @@ fn send_telemetry(span_datum: SpanDatum) { ); } -fn send_grafana(span_datum: SpanDatum) { - let name = format!("{}::{}", span_datum.target, span_datum.name); - if let Err(e) = record_metrics!(&name => span_datum.overall_time.as_nanos(),) { - log::warn!("Unable to send metrics to grafana: {:?}", e); - } +fn send_prometheus(span_datum: SpanDatum) { + unimplemented!() } diff --git a/primitives/consensus/babe/src/inherents.rs b/primitives/consensus/babe/src/inherents.rs index 5a4e042352dcb..4fe71dbb8a7c4 100644 --- a/primitives/consensus/babe/src/inherents.rs +++ b/primitives/consensus/babe/src/inherents.rs @@ -32,59 +32,59 @@ pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"babeslot"; pub type InherentType = u64; /// Auxiliary trait to extract BABE inherent data. pub trait BabeInherentData { - /// Get BABE inherent data. - fn babe_inherent_data(&self) -> Result; - /// Replace BABE inherent data. - fn babe_replace_inherent_data(&mut self, new: InherentType); + /// Get BABE inherent data. + fn babe_inherent_data(&self) -> Result; + /// Replace BABE inherent data. + fn babe_replace_inherent_data(&mut self, new: InherentType); } impl BabeInherentData for InherentData { - fn babe_inherent_data(&self) -> Result { - self.get_data(&INHERENT_IDENTIFIER) - .and_then(|r| r.ok_or_else(|| "BABE inherent data not found".into())) - } + fn babe_inherent_data(&self) -> Result { + self.get_data(&INHERENT_IDENTIFIER) + .and_then(|r| r.ok_or_else(|| "BABE inherent data not found".into())) + } - fn babe_replace_inherent_data(&mut self, new: InherentType) { - self.replace_data(INHERENT_IDENTIFIER, &new); - } + fn babe_replace_inherent_data(&mut self, new: InherentType) { + self.replace_data(INHERENT_IDENTIFIER, &new); + } } /// Provides the slot duration inherent data for BABE. #[cfg(feature = "std")] pub struct InherentDataProvider { - slot_duration: u64, + slot_duration: u64, } #[cfg(feature = "std")] impl InherentDataProvider { - /// Constructs `Self` - pub fn new(slot_duration: u64) -> Self { - Self { slot_duration } - } + /// Constructs `Self` + pub fn new(slot_duration: u64) -> Self { + Self { slot_duration } + } } #[cfg(feature = "std")] impl ProvideInherentData for InherentDataProvider { - fn on_register(&self, providers: &InherentDataProviders) -> Result<(), Error> { - if !providers.has_provider(&sp_timestamp::INHERENT_IDENTIFIER) { - // Add the timestamp inherent data provider, as we require it. - providers.register_provider(sp_timestamp::InherentDataProvider) - } else { - Ok(()) - } - } + fn on_register(&self, providers: &InherentDataProviders) -> Result<(), Error> { + if !providers.has_provider(&sp_timestamp::INHERENT_IDENTIFIER) { + // Add the timestamp inherent data provider, as we require it. + providers.register_provider(sp_timestamp::InherentDataProvider) + } else { + Ok(()) + } + } - fn inherent_identifier(&self) -> &'static InherentIdentifier { - &INHERENT_IDENTIFIER - } + fn inherent_identifier(&self) -> &'static InherentIdentifier { + &INHERENT_IDENTIFIER + } - fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> { - let timestamp = inherent_data.timestamp_inherent_data()?; - let slot_number = timestamp / self.slot_duration; - inherent_data.put_data(INHERENT_IDENTIFIER, &slot_number) - } + fn provide_inherent_data(&self, inherent_data: &mut InherentData) -> Result<(), Error> { + let timestamp = inherent_data.timestamp_inherent_data()?; + let slot_number = timestamp / self.slot_duration; + inherent_data.put_data(INHERENT_IDENTIFIER, &slot_number) + } - fn error_to_string(&self, error: &[u8]) -> Option { - Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() - } + fn error_to_string(&self, error: &[u8]) -> Option { + Error::decode(&mut &error[..]).map(|e| e.into_string()).ok() + } } diff --git a/utils/grafana-data-source/Cargo.toml b/utils/grafana-data-source/Cargo.toml deleted file mode 100644 index 76bf7d5988d9a..0000000000000 --- a/utils/grafana-data-source/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -description = "Grafana data source server" -name = "grafana-data-source" -version = "2.0.0" -license = "GPL-3.0" -authors = ["Parity Technologies "] -edition = "2018" - -[dependencies] -log = "0.4.8" -hyper = { version = "0.13.1", default-features = false, features = ["stream"] } -tokio = "0.2" -futures-util = { version = "0.3.1", default-features = false, features = ["io"] } -serde_json = "1" -serde = { version = "1", features = ["derive"] } -chrono = { version = "0.4", features = ["serde"] } -lazy_static = "1.4" -parking_lot = "0.9" -futures-timer = "2.0" -derive_more = "0.99" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] -async-std = { version = "1.0.1", features = ["unstable"] } diff --git a/utils/grafana-data-source/test/Cargo.toml b/utils/grafana-data-source/test/Cargo.toml deleted file mode 100644 index 079b49dc8608a..0000000000000 --- a/utils/grafana-data-source/test/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -description = "Grafana data source server test" -name = "grafana-data-source-test" -version = "2.0.0" -license = "GPL-3.0" -authors = ["Parity Technologies "] -edition = "2018" - -[dependencies] -grafana-data-source = { version = "2.0.0", path = ".." } -futures = "0.3" -futures-timer = "2.0" -rand = "0.7" diff --git a/utils/prometheus/Cargo.toml b/utils/prometheus/Cargo.toml index 46b5c42ca3ef4..a4bf0aa52273e 100644 --- a/utils/prometheus/Cargo.toml +++ b/utils/prometheus/Cargo.toml @@ -1,20 +1,19 @@ [package] -name = "sc-prometheus" +description = "Prometheus endpoint server" +name = "prometheus-endpoint" version = "2.0.0" +license = "GPL-3.0" authors = ["Parity Technologies "] -description = "prometheus utils" edition = "2018" [dependencies] -hyper = { version = "0.13.1", default-features = false, features = ["stream"] } -lazy_static = "1.4" log = "0.4.8" +hyper = { version = "0.13.1", default-features = false, features = ["stream"] } prometheus = { version = "0.7", features = ["nightly", "process"]} tokio = "0.2" futures-util = { version = "0.3.1", default-features = false, features = ["io"] } -sp-runtime = { package = "sp-runtime",path = "../../primitives/runtime" } +lazy_static = "1.4" 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"] } diff --git a/utils/prometheus/README.md b/utils/prometheus/README.md index e5952f1e192c4..f38cb1c8c7a15 100644 --- a/utils/prometheus/README.md +++ b/utils/prometheus/README.md @@ -22,430 +22,6 @@ Start Prometheus Start Grafana - Install Grafana -## Substrate Dev hack -### Prometheus primer - -Here is the entry point of prometheus core module in Parity Substrate. - -In existing sources, refer to the Grafana source due to the issue of the wasm. - -utils/prometheus/src/lib.rs -```rust -#[macro_use] -extern crate lazy_static; -use futures_util::{FutureExt,future::{Future}}; -use hyper::http::StatusCode; -use hyper::Server; -use hyper::{Body, Request, Response, service::{service_fn, make_service_fn}}; -pub use prometheus::{Encoder, HistogramOpts, Opts, TextEncoder}; -pub use prometheus::{Histogram, IntCounter, IntGauge}; -pub use sp_runtime::traits::SaturatedConversion; -use std::net::SocketAddr; - -pub mod metrics; - -#[derive(Debug, derive_more::Display, derive_more::From)] -pub enum Error { - /// Hyper internal error. - Hyper(hyper::Error), - /// Http request error. - Http(hyper::http::Error), - /// i/o error. - Io(std::io::Error) -} -impl std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Error::Hyper(error) => Some(error), - Error::Http(error) => Some(error), - Error::Io(error) => Some(error) - } - } -} - -async fn request_metrics(req: Request) -> Result, Error> { - if req.uri().path() == "/metrics" { - let metric_families = prometheus::gather(); - let mut buffer = vec![]; - let encoder = TextEncoder::new(); - encoder.encode(&metric_families, &mut buffer).unwrap(); - Response::builder() - .status(StatusCode::OK) - .header("Content-Type", encoder.format_type()) - .body(Body::from(buffer)) - .map_err(Error::Http) - } else { - Response::builder() - .status(StatusCode::NOT_FOUND) - .body(Body::from("Not found.")) - .map_err(Error::Http) - } - -} - -#[derive(Clone)] -pub struct Executor; - -#[cfg(not(target_os = "unknown"))] -impl hyper::rt::Executor for Executor - where - T: Future + Send + 'static, - T::Output: Send + 'static, -{ - fn execute(&self, future: T) { - async_std::task::spawn(future); - } -} -/// Initializes the metrics context, and starts an HTTP server -/// to serve metrics. -#[cfg(not(target_os = "unknown"))] -pub async fn init_prometheus(mut prometheus_addr: SocketAddr) -> Result<(), Error>{ - use async_std::{net, io}; - use grafana_data_source::networking::Incoming; - - let listener = loop { - let listener = net::TcpListener::bind(&prometheus_addr).await; - match listener { - Ok(listener) => { - log::info!("Prometheus server started at {}", prometheus_addr); - break listener - }, - Err(err) => match err.kind() { - io::ErrorKind::AddrInUse | io::ErrorKind::PermissionDenied if prometheus_addr.port() != 0 => { - log::warn!( - "Prometheus server to already {} port.", prometheus_addr.port() - ); - prometheus_addr.set_port(0); - continue; - }, - _ => return Err(err.into()) - } - } - }; - let service = make_service_fn(|_| { - async { - Ok::<_, Error>(service_fn(request_metrics)) - } - }); - - - let _server = Server::builder(Incoming(listener.incoming())) - .executor(Executor) - .serve(service) - .boxed(); - - - let result = _server.await.map_err(Into::into); - - result -} - -#[cfg(target_os = "unknown")] -pub async fn init_prometheus(_: SocketAddr) -> Result<(), Error> { - Ok(()) -} - - -#[macro_export] -macro_rules! prometheus_gauge( - ($($metric:expr => $value:expr),*) => { - use $crate::{metrics::*}; - $( - metrics::set_gauge(&$metric, $value); - )* - } -); - -#[macro_export] -macro_rules! prometheus_histogram( - ($($metric:expr => $value:expr),*) => { - use $crate::{metrics::*}; - $( - metrics::set_histogram(&$metric, $value); - )* - } -); - - -``` - - - -Here is the dependancies of the module. -utils/prometheus/Cargo.toml -```toml -[package] -name = "sc-prometheus" -version = "2.0.0" -authors = ["Parity Technologies "] -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"]} -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" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] -async-std = { version = "1.0.1", features = ["unstable"] } -``` - -**Abbreviation of the package in service manager of parity substrate** -client/service/Cargo.toml -```toml -[dependencies] -sc-prometheus = { package = "sc-prometheus", path="../../utils/prometheus"} -``` - -**Metrics builder as same as substrate-telemetry** -client/service/src/builder.rsL1271 , L1112 -```rust -use sc_prometheus::prometheus_gauge; -... - telemetry!( - SUBSTRATE_INFO; - "system.interval"; - "peers" => num_peers, - "height" => best_number, - "best" => ?best_hash, - "txcount" => txpool_status.ready, - "cpu" => cpu_usage, - "memory" => memory, - "finalized_height" => finalized_number, - "finalized_hash" => ?info.chain.finalized_hash, - "bandwidth_download" => bandwidth_download, - "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, - "txcount" => txpool_status.ready, - "cpu" => cpu_usage, - "memory" => memory, - "finalized_height" => finalized_number, - "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)); - -... - // prometheus init - if let Some(port) = config.prometheus_port { - let future = select( - sc_prometheus::init_prometheus(port).boxed() - ,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( - grafana_data_source::run_server(port).boxed(), - 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)); - } - - // Instrumentation - if let Some(tracing_targets) = config.tracing_targets.as_ref() { - let subscriber = sc_tracing::ProfilingSubscriber::new( - config.tracing_receiver, tracing_targets - ); - match tracing::subscriber::set_global_default(subscriber) { - Ok(_) => (), - Err(e) => error!(target: "tracing", "Unable to set global default subscriber {}", e), - } - } - - -``` -substrate/Cargo.toml -```toml -[workspace] -members = [ - "utils/prometheus", -``` -### CLI Config -client/cli/src/lib.rs -```rust -fn crate_run_node_config{ -... - let prometheus_interface: &str = if cli.prometheus_external { "0.0.0.0" } -... - // Override prometheus - if cli.prometheus_external { - config.prometheus_port = Some( - parse_address(&format!("{}:{}", prometheus_interface, 33333), cli.prometheus_port)? - )} -} -``` - -client/cli/src/params.rs -```rust -pub struct RunCmd{ -... - /// Prometheus exporter TCP port. - #[structopt(long = "prometheus-port", value_name = "PORT")] - pub prometheus_port: Option, - /// Prometheus exporter on/off external". - #[structopt(long = "prometheus-external")] - pub prometheus_external: bool, -... -} -``` -client/service/src/config.rs -```rust -#[derive(Clone)] -pub struct Configuration { - ... - /// Prometheus Port.`None` if disabled and port 33333 by default. - pub prometheus_port: Option, - ... -} -impl Configuration where - C: Default, - G: RuntimeGenesis, - E: Extension, -{ - /// Create default config for given chain spec. - pub fn default_with_spec(chain_spec: ChainSpec) -> Self { - let mut configuration = Configuration { - ... - prometheus_prot: None, - ... - }; - configuration.network.boot_nodes = configuration.chain_spec.boot_nodes().to_vec(); - - configuration.telemetry_endpoints = configuration.chain_spec.telemetry_endpoints().clone(); - - configuration - } -``` - - - -### Metrics Add -ex) consensus_FINALITY_HEIGHT - -utils/prometheus/src/metrics.rs - -```rust -pub use crate::*; - -/// Gauge type metrics generation function -pub fn try_create_int_gauge(name: &str, help: &str) -> Result { - let opts = Opts::new(name, help); - let gauge = IntGauge::with_opts(opts)?; - prometheus::register(Box::new(gauge.clone()))?; - Ok(gauge) -} - -///Gauge Metrics a value in injection. -pub fn set_gauge(gauge: &Result, value: u64) { - if let Ok(gauge) = gauge { - gauge.set(value as i64); - } -} - -///All of the metrics in the prometheus are managed by the lazy_static. -lazy_static! { - pub static ref FINALITY_HEIGHT: Result = try_create_int_gauge( - "consensus_finality_block_height_number", - "block is finality HEIGHT" - ); -} -``` -client/service/Cargo.toml -```rust -... -sc-prometheus = { package = "sc-prometheus", path="../../utils/prometheus"} -... -``` -client/service/src/builder.rs -```rust -..... -use sc-prometheus::{prometheus_gauge}; -..... - let tel_task = state_rx.for_each(move |(net_status, _)| { - let info = client_.info(); - let best_number = info.chain.best_number.saturated_into::(); - let best_hash = info.chain.best_hash; - let num_peers = net_status.num_connected_peers; - let txpool_status = transaction_pool_.status(); - let finalized_number: u64 = info.chain.finalized_number.saturated_into::(); - let bandwidth_download = net_status.average_download_per_sec; - let bandwidth_upload = net_status.average_upload_per_sec; - - let used_state_cache_size = match info.used_state_cache_size { - Some(size) => size, - None => 0, - }; - - // get cpu usage and memory usage of this process - let (cpu_usage, memory) = if let Some(self_pid) = self_pid { - if sys.refresh_process(self_pid) { - let proc = sys.get_process(self_pid) - .expect("Above refresh_process succeeds, this should be Some(), qed"); - (proc.cpu_usage(), proc.memory()) - } else { (0.0, 0) } - } else { (0.0, 0) }; - - telemetry!( - SUBSTRATE_INFO; - "system.interval"; - "peers" => num_peers, - "height" => best_number, - "best" => ?best_hash, - "txcount" => txpool_status.ready, - "cpu" => cpu_usage, - "memory" => memory, - "finalized_height" => finalized_number, - "finalized_hash" => ?info.chain.finalized_hash, - "bandwidth_download" => bandwidth_download, - "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 - ); -..... -``` ## Metrics substrate can report and serve the Prometheus metrics, which in their turn can be consumed by Prometheus collector(s). diff --git a/utils/prometheus/src/lib.rs b/utils/prometheus/src/lib.rs index a6d9397575db6..802a2b53b7fa5 100644 --- a/utils/prometheus/src/lib.rs +++ b/utils/prometheus/src/lib.rs @@ -14,21 +14,27 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . - -#[macro_use] extern crate lazy_static; -use futures_util::{FutureExt,future::{Future}}; + +use futures_util::{FutureExt, future::Future}; use hyper::http::StatusCode; -use hyper::Server; -use hyper::{Body, Request, Response, service::{service_fn, make_service_fn}}; -pub use prometheus::{Encoder, HistogramOpts, Opts, TextEncoder}; -pub use prometheus::{Histogram, IntCounter, IntGauge}; -pub use sp_runtime::traits::SaturatedConversion; +use hyper::{Server, Body, Request, Response, service::{service_fn, make_service_fn}}; +use prometheus::{Encoder, Opts, TextEncoder, core::Atomic}; use std::net::SocketAddr; -//#[cfg(not(target_os = "unknown"))] -//mod networking; - -pub mod metrics; +#[cfg(not(target_os = "unknown"))] +mod networking; + +pub use prometheus::core::{ + GenericGauge as Gauge, AtomicF64 as F64, AtomicI64 as I64, AtomicU64 as U64 +}; +pub use lazy_static::lazy_static; + +pub fn create_gauge(name: &str, description: &str) -> Gauge { + let opts = Opts::new(name, description); + let gauge = Gauge::with_opts(opts).expect("Creating Gauge Failed"); + prometheus::register(Box::new(gauge.clone())).expect("Registering gauge failed"); + gauge +} #[derive(Debug, derive_more::Display, derive_more::From)] pub enum Error { @@ -50,23 +56,16 @@ impl std::error::Error for Error { } async fn request_metrics(req: Request) -> Result, Error> { - if req.uri().path() == "/metrics" { - let metric_families = prometheus::gather(); - let mut buffer = vec![]; - let encoder = TextEncoder::new(); - encoder.encode(&metric_families, &mut buffer).unwrap(); - Response::builder() - .status(StatusCode::OK) - .header("Content-Type", encoder.format_type()) - .body(Body::from(buffer)) - .map_err(Error::Http) - } else { - Response::builder() - .status(StatusCode::NOT_FOUND) - .body(Body::from("Not found.")) - .map_err(Error::Http) - } - + let metric_families = prometheus::gather(); + let mut buffer = vec![]; + let encoder = TextEncoder::new(); + encoder.encode(&metric_families, &mut buffer).unwrap(); + + Response::builder() + .status(StatusCode::OK) + .header("Content-Type", encoder.format_type()) + .body(Body::from(buffer)) + .map_err(Error::Http) } #[derive(Clone)] @@ -86,8 +85,8 @@ impl hyper::rt::Executor for Executor /// to serve metrics. #[cfg(not(target_os = "unknown"))] pub async fn init_prometheus(mut prometheus_addr: SocketAddr) -> Result<(), Error>{ - use async_std::{net, io}; - use grafana_data_source::networking::Incoming; + use async_std::{net, io}; + use networking::Incoming; let listener = loop { let listener = net::TcpListener::bind(&prometheus_addr).await; match listener { @@ -103,23 +102,21 @@ pub async fn init_prometheus(mut prometheus_addr: SocketAddr) -> Result<(), Err prometheus_addr.set_port(0); continue; }, - _ => return Err(err.into()) - } + _ => return Err(err.into()) + } } }; - let service = make_service_fn(|_| { + let service = make_service_fn(|_| { async { Ok::<_, Error>(service_fn(request_metrics)) } }); - let _server = Server::builder(Incoming(listener.incoming())) .executor(Executor) .serve(service) - .boxed(); - - + .boxed(); + let result = _server.await.map_err(Into::into); result @@ -129,24 +126,3 @@ pub async fn init_prometheus(mut prometheus_addr: SocketAddr) -> Result<(), Err pub async fn init_prometheus(_: SocketAddr) -> Result<(), Error> { Ok(()) } - - -#[macro_export] -macro_rules! prometheus_gauge( - ($($metric:expr => $value:expr),*) => { - use $crate::{metrics::*}; - $( - metrics::set_gauge(&$metric, $value); - )* - } -); - -#[macro_export] -macro_rules! prometheus_histogram( - ($($metric:expr => $value:expr),*) => { - use $crate::{metrics::*}; - $( - metrics::set_histogram(&$metric, $value); - )* - } -); diff --git a/utils/prometheus/src/metrics.rs b/utils/prometheus/src/metrics.rs deleted file mode 100644 index 61a7fcc6eb3fc..0000000000000 --- a/utils/prometheus/src/metrics.rs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - - -pub use crate::*; -pub use prometheus::Result; -/// Gauge type metrics generation function -pub fn try_create_int_gauge(name: &str, help: &str) -> Result { - let opts = Opts::new(name, help); - let gauge = IntGauge::with_opts(opts)?; - prometheus::register(Box::new(gauge.clone()))?; - Ok(gauge) -} -/// histogram type metrics generation function -pub fn try_create_histogram(name: &str, help: &str) -> Result { - let opts = HistogramOpts::new(name, help); - let histogram = Histogram::with_opts(opts)?; - prometheus::register(Box::new(histogram.clone()))?; - Ok(histogram) -} - -/// Gauge Metrics a value in injection. -pub fn set_gauge(gauge: &Result, value: u64) { - if let Ok(gauge) = gauge { - gauge.set(value as i64); - } -} -/// histogram Metrics a value in injection. -pub fn set_histogram(histogram: &Result, value: f64) { - if let Ok(histogram) = histogram { - histogram.observe(value) - } -} -/// All of the metrics in the prometheus are managed by the lazy_static. - -lazy_static! { - pub static ref FINALITY_HEIGHT: Result = try_create_int_gauge( - "consensus_finality_block_height_number", - "block is finality HEIGHT" - - ); - - pub static ref BEST_HEIGHT: Result = try_create_int_gauge( - "consensus_best_block_height_number", - "block is best HEIGHT" - ); - - pub static ref P2P_PEERS_NUM: Result = try_create_int_gauge( - "p2p_peers_number", - "network gosip peers number" - ); - - pub static ref TARGET_NUM: Result = try_create_int_gauge( - "consensus_target_syn_number", - "block syn target number" - ); - - pub static ref TX_COUNT: Result = try_create_int_gauge( - "consensus_num_txs", - "Number of transactions" - ); - - pub static ref NODE_MEMORY: Result = try_create_int_gauge( - "consensus_node_memory", - "node memory" - ); - - pub static ref NODE_CPU: Result = try_create_int_gauge( - "consensus_node_cpu", - "node cpu" - ); - - pub static ref STATE_CACHE_SIZE: Result = try_create_int_gauge( - "consensus_state_cache_size", - "used state cache size" - ); - - pub static ref P2P_NODE_DOWNLOAD: Result = try_create_int_gauge( - "p2p_peers_receive_byte_per_sec", - "p2p_node_download_per_sec_byte" - ); - - pub static ref P2P_NODE_UPLOAD: Result = try_create_int_gauge( - "p2p_peers_send_byte_per_sec", - "p2p_node_upload_per_sec_byte" - ); -} diff --git a/utils/grafana-data-source/src/networking.rs b/utils/prometheus/src/networking.rs similarity index 100% rename from utils/grafana-data-source/src/networking.rs rename to utils/prometheus/src/networking.rs