Pass Prometheus Registry into Client (#5120)

* Add a few metrics to Client

* Improve PrometheusConfig

* Fix client docs
This commit is contained in:
Gavin Wood
2020-03-05 13:40:33 +01:00
committed by GitHub
parent 7177ad5cf0
commit 906e08ee2a
13 changed files with 59 additions and 55 deletions
+26 -3
View File
@@ -27,6 +27,7 @@ use sc_chain_spec::{ChainSpec, NoExtension};
use sp_core::crypto::Protected;
use target_info::Target;
use sc_telemetry::TelemetryEndpoints;
use prometheus_endpoint::Registry;
/// Executable version. Used to pass version information from the root crate.
#[derive(Clone)]
@@ -93,8 +94,8 @@ pub struct Configuration<G, E = NoExtension> {
pub rpc_ws_max_connections: Option<usize>,
/// CORS settings for HTTP & WS servers. `None` if all origins are allowed.
pub rpc_cors: Option<Vec<String>>,
/// Prometheus endpoint Port. `None` if disabled.
pub prometheus_port: Option<SocketAddr>,
/// Prometheus endpoint configuration. `None` if disabled.
pub prometheus_config: Option<PrometheusConfig>,
/// Telemetry service URL. `None` if disabled.
pub telemetry_endpoints: Option<TelemetryEndpoints>,
/// External WASM transport for the telemetry. If `Some`, when connection to a telemetry
@@ -165,6 +166,28 @@ pub enum DatabaseConfig {
Custom(Arc<dyn KeyValueDB>),
}
/// Configuration of the Prometheus endpoint.
#[derive(Clone)]
pub struct PrometheusConfig {
/// Port to use.
pub port: SocketAddr,
/// A metrics registry to use. Useful for setting the metric prefix.
pub registry: Registry,
}
impl PrometheusConfig {
/// Create a new config using the default registry.
///
/// The default registry prefixes metrics with `substrate`.
pub fn new_with_default_registry(port: SocketAddr) -> Self {
Self {
port,
registry: Registry::new_custom(Some("substrate".into()), None)
.expect("this can only fail if the prefix is empty")
}
}
}
impl<G, E> Default for Configuration<G, E> {
/// Create a default config
fn default() -> Self {
@@ -190,7 +213,7 @@ impl<G, E> Default for Configuration<G, E> {
rpc_ws: None,
rpc_ws_max_connections: None,
rpc_cors: Some(vec![]),
prometheus_port: None,
prometheus_config: None,
telemetry_endpoints: None,
telemetry_external_transport: None,
default_heap_pages: None,