diff --git a/Cargo.lock b/Cargo.lock index 727d76a61..6a1a8a647 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -522,7 +522,7 @@ dependencies = [ "futures-lite", "parking", "polling", - "rustix", + "rustix 1.1.4", "slab", "windows-sys 0.61.2", ] @@ -4714,6 +4714,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + [[package]] name = "linux-raw-sys" version = "0.12.1" @@ -5460,7 +5466,7 @@ dependencies = [ "concurrent-queue", "hermit-abi", "pin-project-lite", - "rustix", + "rustix 1.1.4", "windows-sys 0.61.2", ] @@ -5628,6 +5634,28 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "procfs" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc5b72d8145275d844d4b5f6d4e1eef00c8cd889edb6035c21675d1bb1f45c9f" +dependencies = [ + "bitflags 2.11.1", + "hex", + "procfs-core", + "rustix 0.38.44", +] + +[[package]] +name = "procfs-core" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "239df02d8349b06fc07398a3a1697b06418223b1c7725085e801e7c0fc6a12ec" +dependencies = [ + "bitflags 2.11.1", + "hex", +] + [[package]] name = "prometheus" version = "0.14.0" @@ -5637,8 +5665,10 @@ dependencies = [ "cfg-if", "fnv", "lazy_static", + "libc", "memchr", "parking_lot", + "procfs", "protobuf", "thiserror 2.0.18", ] @@ -6386,6 +6416,19 @@ dependencies = [ "nom", ] +[[package]] +name = "rustix" +version = "0.38.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +dependencies = [ + "bitflags 2.11.1", + "errno", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.52.0", +] + [[package]] name = "rustix" version = "1.1.4" @@ -6395,7 +6438,7 @@ dependencies = [ "bitflags 2.11.1", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.12.1", "windows-sys 0.60.2", ] @@ -7149,7 +7192,7 @@ dependencies = [ "fastrand", "getrandom 0.4.2", "once_cell", - "rustix", + "rustix 1.1.4", "windows-sys 0.60.2", ] diff --git a/Cargo.toml b/Cargo.toml index 71effe4b1..e13475448 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,7 +95,7 @@ spawned-rt = "0.5.0" tokio = "1.0" tokio-util = "0.7" -prometheus = "0.14" +prometheus = { version = "0.14", features = ["process"] } clap = { version = "4.3", features = ["derive", "env"] } diff --git a/crates/common/metrics/src/gather.rs b/crates/common/metrics/src/gather.rs index c4e727e0c..8912d18e6 100644 --- a/crates/common/metrics/src/gather.rs +++ b/crates/common/metrics/src/gather.rs @@ -27,3 +27,21 @@ pub fn gather_default_metrics() -> Result { Ok(res) } + +/// The process collector comes from the `prometheus` crate's `process` +/// feature, which registers it with the default registry on Linux only. +/// Dashboards read the node's memory from it, so dropping the feature would +/// leave them blank without any build failing. +#[cfg(all(test, target_os = "linux"))] +mod tests { + use super::*; + + #[test] + fn the_default_registry_serves_the_process_metrics() { + let metrics = gather_default_metrics().unwrap(); + assert!( + metrics.contains("process_resident_memory_bytes"), + "{metrics}" + ); + } +} diff --git a/docs/metrics.md b/docs/metrics.md index 1ea07953f..7107778d1 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -13,6 +13,13 @@ The Lean Chain's metrics follow [the leanMetrics specification](https://github.c | `lean_node_info` | Gauge | Node information (always 1) | On node start | name, version | ✅ | | `lean_node_start_time_seconds` | Gauge | Start timestamp | On node start | | ✅ | +On Linux the endpoint also serves the `prometheus` crate's process collector, +read from `/proc/self` at each scrape: `process_resident_memory_bytes`, +`process_virtual_memory_bytes`, `process_cpu_seconds_total`, +`process_open_fds`, `process_max_fds`, `process_threads` and +`process_start_time_seconds`. They are not part of the leanMetrics spec, and +other platforms do not export them. + ## PQ Signature Metrics