diff --git a/crates/blockchain/src/lib.rs b/crates/blockchain/src/lib.rs index 9ee4ee8e..a851235d 100644 --- a/crates/blockchain/src/lib.rs +++ b/crates/blockchain/src/lib.rs @@ -170,6 +170,8 @@ impl BlockChainServer { } fn produce_attestations(&mut self, slot: u64) { + let _timing = metrics::time_attestations_production(); + // Produce attestation data once for all validators let attestation_data = store::produce_attestation_data(&self.store, slot); diff --git a/crates/blockchain/src/metrics.rs b/crates/blockchain/src/metrics.rs index e59c5b9a..7558b09f 100644 --- a/crates/blockchain/src/metrics.rs +++ b/crates/blockchain/src/metrics.rs @@ -226,6 +226,16 @@ static LEAN_PQ_SIG_ATTESTATION_SIGNING_TIME_SECONDS: std::sync::LazyLock = + std::sync::LazyLock::new(|| { + register_histogram!( + "lean_attestations_production_time_seconds", + "Time taken to produce attestation", + vec![0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 0.75, 1.0] + ) + .unwrap() + }); + static LEAN_PQ_SIG_ATTESTATION_VERIFICATION_TIME_SECONDS: std::sync::LazyLock = std::sync::LazyLock::new(|| { register_histogram!( @@ -381,6 +391,7 @@ pub fn init() { std::sync::LazyLock::force(&LEAN_FORK_CHOICE_BLOCK_PROCESSING_TIME_SECONDS); std::sync::LazyLock::force(&LEAN_ATTESTATION_VALIDATION_TIME_SECONDS); std::sync::LazyLock::force(&LEAN_PQ_SIG_ATTESTATION_SIGNING_TIME_SECONDS); + std::sync::LazyLock::force(&LEAN_ATTESTATIONS_PRODUCTION_TIME_SECONDS); std::sync::LazyLock::force(&LEAN_PQ_SIG_ATTESTATION_VERIFICATION_TIME_SECONDS); std::sync::LazyLock::force(&LEAN_PQ_SIG_AGGREGATED_SIGNATURES_BUILDING_TIME_SECONDS); std::sync::LazyLock::force(&LEAN_PQ_SIG_AGGREGATED_SIGNATURES_VERIFICATION_TIME_SECONDS); @@ -499,6 +510,11 @@ pub fn time_pq_sig_attestation_signing() -> TimingGuard { TimingGuard::new(&LEAN_PQ_SIG_ATTESTATION_SIGNING_TIME_SECONDS) } +/// Start timing attestation production. Records duration when the guard is dropped. +pub fn time_attestations_production() -> TimingGuard { + TimingGuard::new(&LEAN_ATTESTATIONS_PRODUCTION_TIME_SECONDS) +} + /// Start timing individual attestation signature verification. Records duration when the guard is dropped. pub fn time_pq_sig_attestation_verification() -> TimingGuard { TimingGuard::new(&LEAN_PQ_SIG_ATTESTATION_VERIFICATION_TIME_SECONDS) diff --git a/docs/metrics.md b/docs/metrics.md index 778a3334..3c956fd8 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -64,10 +64,11 @@ The exposed metrics follow [the leanMetrics specification](https://github.com/le ## Validator Metrics -| Name | Type | Usage | Sample collection event | Labels | Supported | -|--------|-------|-------|-------------------------|--------|-----------| -|`lean_validators_count`| Gauge | Number of validators managed by a node | On scrape | | ✅(*) | -|`lean_is_aggregator`| Gauge | Validator's `is_aggregator` status. True=1, False=0 | On node start | | ✅ | +| Name | Type | Usage | Sample collection event | Labels | Buckets | Supported | +|--------|-------|-------|-------------------------|--------|---------|-----------| +|`lean_validators_count`| Gauge | Number of validators managed by a node | On scrape | | | ✅(*) | +|`lean_is_aggregator`| Gauge | Validator's `is_aggregator` status. True=1, False=0 | On node start | | | ✅ | +|`lean_attestations_production_time_seconds`| Histogram | Time taken to produce attestation | On attestation production | | 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 0.75, 1 | ✅ | ## Network Metrics