From 0cc3b96076b8643703f2108a4fea157d56e37cda Mon Sep 17 00:00:00 2001 From: Max Inden Date: Tue, 10 Mar 2020 11:12:32 +0100 Subject: [PATCH] client/service/src/builder.rs: Add build_info metric (#5192) * client/service/src/builder.rs: Add build_info metric Add static Prometheus metric exposing the chain name, the version and the commit. * client/service/src/builder.rs: Move node_role to static metrics The Prometheus metrics `node_role` is static and thus there is no need to keep a reference of it within `ServiceMetrics`. This follows the example of the `build_info` metric. * client/service/src/builder.rs: Adjust indentation --- substrate/client/service/src/builder.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/substrate/client/service/src/builder.rs b/substrate/client/service/src/builder.rs index e49f568733..e4328a3403 100644 --- a/substrate/client/service/src/builder.rs +++ b/substrate/client/service/src/builder.rs @@ -61,7 +61,6 @@ struct ServiceMetrics { memory_usage_bytes: Gauge, cpu_usage_percentage: Gauge, network_per_sec_bytes: GaugeVec, - node_roles: Gauge, database_cache: Gauge, state_cache: Gauge, state_db: GaugeVec, @@ -87,9 +86,6 @@ impl ServiceMetrics { Opts::new("network_per_sec_bytes", "Networking bytes per second"), &["direction"] )?, registry)?, - node_roles: register(Gauge::new( - "node_roles", "The roles the node is running as", - )?, registry)?, database_cache: register(Gauge::new( "database_cache_bytes", "RocksDB cache size in bytes", )?, registry)?, @@ -1011,18 +1007,34 @@ ServiceBuilder< ); } - // Prometheus metrics + // Prometheus metrics. let metrics = if let Some(PrometheusConfig { port, registry }) = config.prometheus_config.clone() { + // Set static metrics. + register(Gauge::::with_opts( + Opts::new( + "build_info", + "A metric with a constant '1' value labeled by name, version, and commit." + ) + .const_label("name", config.impl_name) + .const_label("version", config.impl_version) + .const_label("commit", config.impl_commit), + )?, ®istry)?.set(1); + register(Gauge::::new( + "node_roles", "The roles the node is running as", + )?, ®istry)?.set(u64::from(config.roles.bits())); + let metrics = ServiceMetrics::register(®istry)?; - metrics.node_roles.set(u64::from(config.roles.bits())); + spawn_handle.spawn( "prometheus-endpoint", prometheus_endpoint::init_prometheus(port, registry).map(drop) ); + Some(metrics) } else { None }; + // Periodically notify the telemetry. let transaction_pool_ = transaction_pool.clone(); let client_ = client.clone();