Skip to content

Commit 4cd3d0f

Browse files
committed
Expose lean_attestation_committee_subnet as a Prometheus gauge
Register and set the metric at P2P startup with the computed subnet ID (validator_id % attestation_committee_count), per the leanMetrics spec. Non-validator nodes default to subnet 0.
1 parent 455611c commit 4cd3d0f

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

crates/net/p2p/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ pub fn build_swarm(
210210
let subnet_id = config
211211
.validator_id
212212
.map(|vid| vid % config.attestation_committee_count);
213+
metrics::set_attestation_committee_subnet(subnet_id.unwrap_or(0));
214+
213215
let attestation_topic_kind = match subnet_id {
214216
Some(id) => format!("{ATTESTATION_SUBNET_TOPIC_PREFIX}_{id}"),
215217
// Non-validators use subnet 0 for publishing

crates/net/p2p/src/metrics.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ static LEAN_PEER_DISCONNECTION_EVENTS_TOTAL: LazyLock<IntCounterVec> = LazyLock:
6868
.unwrap()
6969
});
7070

71+
/// Set the attestation committee subnet gauge.
72+
pub fn set_attestation_committee_subnet(subnet_id: u64) {
73+
static LEAN_ATTESTATION_COMMITTEE_SUBNET: LazyLock<IntGauge> = LazyLock::new(|| {
74+
register_int_gauge!(
75+
"lean_attestation_committee_subnet",
76+
"Node's attestation committee subnet"
77+
)
78+
.unwrap()
79+
});
80+
LEAN_ATTESTATION_COMMITTEE_SUBNET.set(subnet_id.try_into().unwrap());
81+
}
82+
7183
/// Notify that a peer connection event occurred.
7284
///
7385
/// If `result` is "success", the connected peer count is incremented.

docs/metrics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ The exposed metrics follow [the leanMetrics specification](https://github.com/le
7474
| Name | Type | Usage | Sample collection event | Labels | Supported |
7575
|--------|-------|-------|-------------------------|--------|-----------|
7676
|`lean_attestation_committee_count`| Gauge | Number of attestation committees | On node start | ||
77+
|`lean_attestation_committee_subnet`| Gauge | Node's attestation committee subnet | On node start | ||
7778
|`lean_connected_peers`| Gauge | Number of connected peers | On scrape | client=ethlambda,grandine,lantern,lighthouse,qlean,ream,zeam | ✅(*) |
7879
|`lean_peer_connection_events_total`| Counter | Total number of peer connection events | On peer connection | direction=inbound,outbound<br>result=success,timeout,error ||
7980
|`lean_peer_disconnection_events_total`| Counter | Total number of peer disconnection events | On peer disconnection | direction=inbound,outbound<br>reason=timeout,remote_close,local_close,error ||

0 commit comments

Comments
 (0)